Skip to content

Commit 60320a9

Browse files
committed
update TaintedPath to use new consistency checking
1 parent 68ca8e2 commit 60320a9

File tree

5 files changed

+9
-40
lines changed

5 files changed

+9
-40
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
| normalizedPaths.js:208:38:208:63 | // OK - ... anyway | Spurious alert |
2-
| tainted-string-steps.js:25:43:25:74 | // NOT ... flagged | Missing alert |
3-
| tainted-string-steps.js:26:49:26:74 | // OK - ... flagged | Spurious alert |
4-
| tainted-string-steps.js:28:39:28:70 | // NOT ... flagged | Missing alert |
1+
| query-tests/Security/CWE-022/TaintedPath/tainted-array-steps.js:10 | expected an alert, but found none | BAD: taint is preserved |
2+
| query-tests/Security/CWE-022/TaintedPath/tainted-array-steps.js:14 | expected an alert, but found none | BAD: taint is preserved |
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
11
import javascript
22
import semmle.javascript.security.dataflow.TaintedPath::TaintedPath
3-
4-
class Assertion extends LineComment {
5-
boolean shouldHaveAlert;
6-
7-
Assertion() {
8-
if getText().matches("%NOT OK%")
9-
then shouldHaveAlert = true
10-
else (
11-
getText().matches("%OK%") and shouldHaveAlert = false
12-
)
13-
}
14-
15-
predicate shouldHaveAlert() { shouldHaveAlert = true }
16-
17-
predicate hasAlert() {
18-
exists(Configuration cfg, DataFlow::Node src, DataFlow::Node sink, Location loc |
19-
cfg.hasFlow(src, sink) and
20-
loc = sink.getAstNode().getLocation() and
21-
loc.getFile() = getFile() and
22-
loc.getEndLine() = getLocation().getEndLine()
23-
)
24-
}
25-
}
26-
27-
from Assertion assertion, string message
28-
where
29-
assertion.shouldHaveAlert() and not assertion.hasAlert() and message = "Missing alert"
30-
or
31-
not assertion.shouldHaveAlert() and assertion.hasAlert() and message = "Spurious alert"
32-
select assertion, message
3+
import testUtilities.ConsistencyChecking

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/normalizedPaths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ app.get('/join-regression', (req, res) => {
205205
fs.readFileSync(normalizedPath); // NOT OK
206206

207207
if (normalizedPath.startsWith('/home/user/www') || normalizedPath.startsWith('/home/user/public'))
208-
fs.readFileSync(normalizedPath); // OK - but flagged anyway
208+
fs.readFileSync(normalizedPath); // OK - but flagged anyway [INCONSISTENCY]
209209
else
210210
fs.readFileSync(normalizedPath); // NOT OK
211211
});

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/tainted-array-steps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var fs = require('fs'),
77

88
var server = http.createServer(function(req, res) {
99
let path = url.parse(req.url, true).query.path;
10-
res.write(fs.readFileSync(['public', path].join('/'))); // BAD: taint is preserved [INCONSISTENCY]
10+
res.write(fs.readFileSync(['public', path].join('/'))); // BAD: taint is preserved
1111

1212
let parts = ['public', path];
1313
parts = parts.map(x => x.toLowerCase());
14-
res.write(fs.readFileSync(parts.join('/'))); // BAD: taint is preserved [INCONSISTENCY]
14+
res.write(fs.readFileSync(parts.join('/'))); // BAD: taint is preserved
1515
});
1616

1717
server.listen();

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/tainted-string-steps.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var server = http.createServer(function(req, res) {
2222
fs.readFileSync(path.split('/')[i]); // NOT OK
2323
fs.readFileSync(path.split(/\//)[i]); // NOT OK
2424
fs.readFileSync(path.split("?")[0]); // NOT OK
25-
fs.readFileSync(path.split(unknown)[i]); // NOT OK -- but not yet flagged
26-
fs.readFileSync(path.split(unknown).whatever); // OK -- but still flagged
25+
fs.readFileSync(path.split(unknown)[i]); // NOT OK -- but not yet flagged [INCONSISTENCY]
26+
fs.readFileSync(path.split(unknown).whatever); // OK -- but still flagged [INCONSISTENCY]
2727
fs.readFileSync(path.split(unknown)); // NOT OK
28-
fs.readFileSync(path.split("?")[i]); // NOT OK -- but not yet flagged
28+
fs.readFileSync(path.split("?")[i]); // NOT OK -- but not yet flagged [INCONSISTENCY]
2929
});
3030

3131
server.listen();

0 commit comments

Comments
 (0)