Skip to content

Commit a6d728a

Browse files
committed
JS: Add test case with missing alert using graphql
1 parent a7173e0 commit a6d728a

File tree

1 file changed

+36
-0
lines changed
  • javascript/ql/test/query-tests/Security/CWE-094/CodeInjection

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const express = require('express');
2+
const { graphql, buildSchema } = require('graphql');
3+
4+
const app = express();
5+
app.use(express.json());
6+
7+
const schema = buildSchema(`
8+
type Query {
9+
greet(name: String!): String
10+
calc(expr: String!): String
11+
}
12+
`);
13+
14+
const root = {
15+
greet: ({ name }) => {
16+
return `Hello, ${name}!`;
17+
},
18+
calc: ({ expr }) => {
19+
try {
20+
return eval(expr).toString(); // $ MISSING: Alert[js/code-injection]
21+
} catch (e) {
22+
return `Error: ${e.message}`;
23+
}
24+
}
25+
};
26+
27+
app.post('/graphql', async (req, res) => {
28+
const { query, variables } = req.body; // $ MISSING: Source[js/code-injection]
29+
const result = await graphql({
30+
schema,
31+
source: query,
32+
rootValue: root,
33+
variableValues: variables
34+
});
35+
res.json(result);
36+
});

0 commit comments

Comments
 (0)