Skip to content

Commit 95819c8

Browse files
committed
use RegExpTerm to generalize predicate
1 parent 622a2fc commit 95819c8

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/TaintedPathCustomizations.qll

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,14 @@ module TaintedPath {
217217
this.getCalleeName() = "replace" and
218218
input = getReceiver() and
219219
output = this and
220-
not exists(RegExpLiteral literal |
220+
not exists(RegExpLiteral literal, RegExpTerm term |
221221
getArgument(0).getALocalSource().asExpr() = literal and
222-
literal.isGlobal()
222+
literal.isGlobal() and
223+
literal.getRoot() = term
223224
|
224-
exists(RegExpSequence seq | literal.getRoot() = seq |
225-
seq.getChild(0).(RegExpConstant).getValue() = "." and
226-
seq.getChild(1).(RegExpConstant).getValue() = "." and
227-
seq.getNumChild() = 2
228-
)
229-
or
230-
exists(RegExpTerm term | literal.getRoot() = term |
231-
term.getAMatchedString() = "/" or
232-
term.getAMatchedString() = "."
233-
)
225+
term.getAMatchedString() = "/" or
226+
term.getAMatchedString() = "." or
227+
term.getAMatchedString() = ".."
234228
)
235229
}
236230

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ var server = http.createServer(function(req, res) {
172172
var server = http.createServer(function(req, res) {
173173
let path = url.parse(req.url, true).query.path;
174174

175-
// Removal of forward-slash.
175+
// Removal of forward-slash or dots.
176176
res.write(fs.readFileSync(path.replace(/[\]\[*,;'"`<>\\?\/]/g, ''))); // OK.
177177
res.write(fs.readFileSync(path.replace(/[abcd]/g, ''))); // NOT OK
178178
res.write(fs.readFileSync(path.replace(/[.]/g, ''))); // OK (can still be absolute)
@@ -181,4 +181,6 @@ var server = http.createServer(function(req, res) {
181181
res.write(fs.readFileSync(path.replace(/[foobar/foobar]/g, ''))); // OK
182182
res.write(fs.readFileSync(path.replace(/\//g, ''))); // OK
183183
res.write(fs.readFileSync(path.replace(/\./g, ''))); // OK
184+
res.write(fs.readFileSync(path.replace(/\.|\//g, ''))); // OK
185+
res.write(fs.readFileSync(path.replace(/\.\.|BLA/g, ''))); // OK
184186
});

0 commit comments

Comments
 (0)