Skip to content

Commit 955ad8c

Browse files
committed
add JSON.stringify as a code-injection sanitizer
1 parent 68a5c1f commit 955ad8c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/CodeInjectionCustomizations.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,9 @@ module CodeInjection {
375375
this = LodashUnderscore::member("template").getACall().getArgument(0)
376376
}
377377
}
378+
379+
/**
380+
* A call to JSON.stringify() seen as a sanitizer.
381+
*/
382+
class JSONStringifySanitizer extends Sanitizer, JsonStringifyCall { }
378383
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ const cp = require('child_process');
2525
app.get('/other/path', function(req, res) {
2626
const taint = req.param("wobble");
2727
cp.execFileSync('node', ['-e', taint]); // NOT OK
28+
29+
cp.execFileSync('node', ['-e', `console.log(${JSON.stringify(taint)})`]); // OK
2830
});

0 commit comments

Comments
 (0)