File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
javascript/ql/test/query-tests/Security/CWE-094/CodeInjection Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments