Skip to content

Commit f2818eb

Browse files
Merge pull request #7489 from edoardopirovano/fix-example
Fix example in JavaScript query
2 parents 8f73772 + 081765c commit f2818eb

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

javascript/ql/src/Security/CWE-843/examples/TypeConfusionThroughParameterTampering.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ app.get("/user-files", function(req, res) {
55
var file = req.param("file");
66
if (file.indexOf("..") !== -1) {
77
// BAD
8-
// forbid paths outside the /public directory
8+
// we forbid relative paths that contain ..
9+
// as these could leave the public directory
910
res.status(400).send("Bad request");
1011
} else {
1112
var absolute = path.resolve("/public/" + file);

javascript/ql/src/Security/CWE-843/examples/TypeConfusionThroughParameterTampering_fixed.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ var app = require("express")(),
33

44
app.get("/user-files", function(req, res) {
55
var file = req.param("file");
6-
if (typeof path !== 'string' || file.indexOf("..") !== -1) {
7-
// BAD
8-
// forbid paths outside the /public directory
6+
if (typeof file !== 'string' || file.indexOf("..") !== -1) {
7+
// GOOD
8+
// we forbid relative paths that contain ..
9+
// as these could leave the public directory
910
res.status(400).send("Bad request");
1011
} else {
1112
var absolute = path.resolve("/public/" + file);

0 commit comments

Comments
 (0)