Skip to content

Commit adc8bf3

Browse files
author
Naman Jain
committed
fixed mistake in examples
1 parent aea7054 commit adc8bf3

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

javascript/ql/test/query-tests/Security/CWE-754/UnvalidatedDynamicMethodCall2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ var app = express();
33

44
var actions = new Map();
55
actions.put("play", function play(data) {
6-
// ...
6+
// ...
77
});
88
actions.put("pause", function pause(data) {
9-
// ...
9+
// ...
1010
});
1111

1212
app.get('/perform/:action/:payload', function(req, res) {
13-
let action = actions.get(req.params.action);
14-
res.end(action.get(req.params.payload)); // NOT OK
15-
});
13+
let action = actions.get(req.params.action);
14+
res.end(action(req.params.payload)); // NOT OK
15+
});

javascript/ql/test/query-tests/Security/CWE-754/UnvalidatedDynamicMethodCall3.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ var app = express();
33

44
var actions = new Map();
55
actions.put("play", function play(data) {
6-
// ...
6+
// ...
77
});
88
actions.put("pause", function pause(data) {
9-
// ...
9+
// ...
1010
});
1111

1212
app.get('/perform/:action/:payload', function(req, res) {
13-
if (actions.has(req.params.action)){
14-
let action = actions.get(req.params.action);
15-
res.end(action.get(req.params.payload)); // NOT OK, but not flagged [INCONSISTENCY]
16-
}
17-
});
13+
if (actions.has(req.params.action)) {
14+
let action = actions.get(req.params.action);
15+
res.end(action(req.params.payload)); // NOT OK, but not flagged [INCONSISTENCY]
16+
}
17+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var express = require('express');
2+
var app = express();
3+
4+
var actions = new Map();
5+
actions.put("play", function play(data) {
6+
// ...
7+
});
8+
actions.put("pause", function pause(data) {
9+
// ...
10+
});
11+
12+
app.get('/perform/:action/:payload', function(req, res) {
13+
if (typeof actions.get(req.params.action) === 'function') {
14+
let action = actions.get(req.params.action); // OK but flagged [INCONSISTENCY]
15+
// GOOD: `action` is either the `play` or the `pause` function from above
16+
res.end(action(req.params.payload));
17+
} else {
18+
res.end("Unsupported action.");
19+
}
20+
});

javascript/ql/test/query-tests/Security/CWE-754/UnvalidatedDynamicMethodCallGood3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ actions.put("pause", function pause(data) {
99
// ...
1010
});
1111

12-
app.get('/perform/:action/:payload', function (req, res) {
13-
if (typeof actions.get(req.params.action) === 'function') {
14-
let action = actions.get(req.params.action);
15-
// GOOD: `action` is either the `play` or the `pause` function from above
12+
app.get('/perform/:action/:payload', function(req, res) {
13+
let action = actions.get(req.params.action);
14+
// GOOD: `action` is either the `play` or the `pause` function from above
15+
if (typeof action === 'function') {
1616
res.end(action(req.params.payload));
1717
} else {
1818
res.end("Unsupported action.");
1919
}
20-
});
20+
});

0 commit comments

Comments
 (0)