Skip to content

Commit d88bc8e

Browse files
committed
JS: Add test case for GraphQLObjectType
1 parent 2cd1d2f commit d88bc8e

File tree

1 file changed

+27
-1
lines changed
  • javascript/ql/test/query-tests/Security/CWE-094/CodeInjection

1 file changed

+27
-1
lines changed

javascript/ql/test/query-tests/Security/CWE-094/CodeInjection/graph-ql.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const express = require('express');
2-
const { graphql, buildSchema } = require('graphql');
2+
const { graphql, buildSchema, GraphQLObjectType, GraphQLString } = require('graphql');
33

44
const app = express();
55
app.use(express.json());
@@ -53,4 +53,30 @@ app.post('/graphql', async (req, res) => {
5353
rootValue: root1,
5454
variableValues: variables
5555
});
56+
57+
const MutationType = new GraphQLObjectType({
58+
name: 'Mutation',
59+
fields: {
60+
runEval: {
61+
type: GraphQLString,
62+
args: {
63+
value: { type: GraphQLString }
64+
},
65+
resolve: (_, { value }, context) => { // $ MISSING: Source[js/code-injection]
66+
return eval(value); // $ MISSING: Alert[js/code-injection]
67+
}
68+
}
69+
}
70+
});
71+
72+
const schema = new GraphQLSchema({
73+
query: QueryType,
74+
mutation: MutationType
75+
});
76+
77+
await graphql({
78+
schema,
79+
source: query,
80+
variableValues: variables
81+
});
5682
});

0 commit comments

Comments
 (0)