Skip to content

Commit a0ea0c9

Browse files
authored
Merge pull request #20492 from Napalys/js/graph-ql-obj-type
JS: mark `GraphQLObjectType` resolvers args as remote sources
2 parents 97d6295 + 3a6a537 commit a0ea0c9

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added modeling of `GraphQLObjectType` resolver function parameters as remote sources.

javascript/ql/lib/ext/graph-ql.model.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ extensions:
44
extensible: summaryModel
55
data:
66
- ["graphql", "Member[graphql]", "Argument[0].Member[source,variableValues]", "Argument[0].Member[rootValue].AnyMember.Parameter[0]", "taint"]
7+
- addsTo:
8+
pack: codeql/javascript-all
9+
extensible: sourceModel
10+
data:
11+
- ["graphql", "Member[GraphQLObjectType].Argument[0].Member[fields].AnyMember.Member[resolve].Parameter[1]", "remote"]

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
| fastify.js:108:28:108:50 | reply.l ... tedCode | fastify.js:94:29:94:51 | request ... plyCode | fastify.js:108:28:108:50 | reply.l ... tedCode | This code execution depends on a $@. | fastify.js:94:29:94:51 | request ... plyCode | user-provided value |
6464
| graph-ql.js:20:19:20:22 | expr | graph-ql.js:28:32:28:39 | req.body | graph-ql.js:20:19:20:22 | expr | This code execution depends on a $@. | graph-ql.js:28:32:28:39 | req.body | user-provided value |
6565
| graph-ql.js:39:19:39:30 | name + title | graph-ql.js:28:32:28:39 | req.body | graph-ql.js:39:19:39:30 | name + title | This code execution depends on a $@. | graph-ql.js:28:32:28:39 | req.body | user-provided value |
66+
| graph-ql.js:66:23:66:27 | value | graph-ql.js:65:22:65:30 | { value } | graph-ql.js:66:23:66:27 | value | This code execution depends on a $@. | graph-ql.js:65:22:65:30 | { value } | user-provided value |
6667
| module.js:9:16:9:29 | req.query.code | module.js:9:16:9:29 | req.query.code | module.js:9:16:9:29 | req.query.code | This code execution depends on a $@. | module.js:9:16:9:29 | req.query.code | user-provided value |
6768
| module.js:11:17:11:30 | req.query.code | module.js:11:17:11:30 | req.query.code | module.js:11:17:11:30 | req.query.code | This code execution depends on a $@. | module.js:11:17:11:30 | req.query.code | user-provided value |
6869
| react-native.js:8:32:8:38 | tainted | react-native.js:7:17:7:33 | req.param("code") | react-native.js:8:32:8:38 | tainted | This code execution depends on a $@. | react-native.js:7:17:7:33 | req.param("code") | user-provided value |
@@ -173,6 +174,8 @@ edges
173174
| graph-ql.js:39:19:39:22 | name | graph-ql.js:39:19:39:30 | name + title | provenance | |
174175
| graph-ql.js:39:26:39:30 | title | graph-ql.js:39:19:39:30 | name + title | provenance | |
175176
| graph-ql.js:54:21:54:29 | variables | graph-ql.js:38:13:38:27 | { name, title } | provenance | |
177+
| graph-ql.js:65:22:65:30 | { value } | graph-ql.js:65:24:65:28 | value | provenance | |
178+
| graph-ql.js:65:24:65:28 | value | graph-ql.js:66:23:66:27 | value | provenance | |
176179
| react-native.js:7:7:7:13 | tainted | react-native.js:8:32:8:38 | tainted | provenance | |
177180
| react-native.js:7:7:7:13 | tainted | react-native.js:10:23:10:29 | tainted | provenance | |
178181
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:13 | tainted | provenance | |
@@ -323,6 +326,9 @@ nodes
323326
| graph-ql.js:39:19:39:30 | name + title | semmle.label | name + title |
324327
| graph-ql.js:39:26:39:30 | title | semmle.label | title |
325328
| graph-ql.js:54:21:54:29 | variables | semmle.label | variables |
329+
| graph-ql.js:65:22:65:30 | { value } | semmle.label | { value } |
330+
| graph-ql.js:65:24:65:28 | value | semmle.label | value |
331+
| graph-ql.js:66:23:66:27 | value | semmle.label | value |
326332
| module.js:9:16:9:29 | req.query.code | semmle.label | req.query.code |
327333
| module.js:11:17:11:30 | req.query.code | semmle.label | req.query.code |
328334
| react-native.js:7:7:7:13 | tainted | semmle.label | tainted |

javascript/ql/test/query-tests/Security/CWE-094/CodeInjection/HeuristicSourceCodeInjection.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ edges
7272
| graph-ql.js:39:19:39:22 | name | graph-ql.js:39:19:39:30 | name + title | provenance | |
7373
| graph-ql.js:39:26:39:30 | title | graph-ql.js:39:19:39:30 | name + title | provenance | |
7474
| graph-ql.js:54:21:54:29 | variables | graph-ql.js:38:13:38:27 | { name, title } | provenance | |
75+
| graph-ql.js:65:22:65:30 | { value } | graph-ql.js:65:24:65:28 | value | provenance | |
76+
| graph-ql.js:65:24:65:28 | value | graph-ql.js:66:23:66:27 | value | provenance | |
7577
| react-native.js:7:7:7:13 | tainted | react-native.js:8:32:8:38 | tainted | provenance | |
7678
| react-native.js:7:7:7:13 | tainted | react-native.js:10:23:10:29 | tainted | provenance | |
7779
| react-native.js:7:17:7:33 | req.param("code") | react-native.js:7:7:7:13 | tainted | provenance | |
@@ -224,6 +226,9 @@ nodes
224226
| graph-ql.js:39:19:39:30 | name + title | semmle.label | name + title |
225227
| graph-ql.js:39:26:39:30 | title | semmle.label | title |
226228
| graph-ql.js:54:21:54:29 | variables | semmle.label | variables |
229+
| graph-ql.js:65:22:65:30 | { value } | semmle.label | { value } |
230+
| graph-ql.js:65:24:65:28 | value | semmle.label | value |
231+
| graph-ql.js:66:23:66:27 | value | semmle.label | value |
227232
| module.js:9:16:9:29 | req.query.code | semmle.label | req.query.code |
228233
| module.js:11:17:11:30 | req.query.code | semmle.label | req.query.code |
229234
| react-native.js:7:7:7:13 | tainted | semmle.label | tainted |

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) => { // $ Source[js/code-injection]
66+
return eval(value); // $ 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)