JS: Add test case with missing alert using graphql

This commit is contained in:
Napalys Klicius
2025-09-17 11:19:33 +02:00
parent a7173e0c05
commit a6d728a66d

View File

@@ -0,0 +1,36 @@
const express = require('express');
const { graphql, buildSchema } = require('graphql');
const app = express();
app.use(express.json());
const schema = buildSchema(`
type Query {
greet(name: String!): String
calc(expr: String!): String
}
`);
const root = {
greet: ({ name }) => {
return `Hello, ${name}!`;
},
calc: ({ expr }) => {
try {
return eval(expr).toString(); // $ MISSING: Alert[js/code-injection]
} catch (e) {
return `Error: ${e.message}`;
}
}
};
app.post('/graphql', async (req, res) => {
const { query, variables } = req.body; // $ MISSING: Source[js/code-injection]
const result = await graphql({
schema,
source: query,
rootValue: root,
variableValues: variables
});
res.json(result);
});