Skip to content

Commit 2cf139d

Browse files
committed
JS: Fix barrier guards for ServerSideUrlRedirect
The barrier guards for ServerSideUrlRedirect were lost when it was ported to ConfigSig, and the aforementioned spurious alert was a result of that. The query had two guards: a proper barrier guard and a heuristic one for functions named 'isLocalURL'. We should move away from the heuristic name-based sanitiser guards, so I'm only reinstating the proper barrier guard. Therefore updating the test to test the real barrier guard.
1 parent 3db3e62 commit 2cf139d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ module ServerSideUrlRedirectConfig implements DataFlow::ConfigSig {
2020

2121
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2222

23-
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
23+
predicate isBarrier(DataFlow::Node node) {
24+
node instanceof Sanitizer
25+
or
26+
node = HostnameSanitizerGuard::getABarrierNode()
27+
}
2428

2529
predicate isBarrierOut(DataFlow::Node node) { hostnameSanitizingPrefixEdge(node, _) }
2630

@@ -69,10 +73,12 @@ deprecated class Configuration extends TaintTracking::Configuration {
6973
}
7074

7175
/**
76+
* DEPRECATED. This is no longer used as a sanitizer guard.
77+
*
7278
* A call to a function called `isLocalUrl` or similar, which is
7379
* considered to sanitize a variable for purposes of URL redirection.
7480
*/
75-
class LocalUrlSanitizingGuard extends DataFlow::CallNode {
81+
deprecated class LocalUrlSanitizingGuard extends DataFlow::CallNode {
7682
LocalUrlSanitizingGuard() { this.getCalleeName().regexpMatch("(?i)(is_?)?local_?url") }
7783

7884
/** DEPRECATED. Use `blocksExpr` instead. */

javascript/ql/test/query-tests/Security/CWE-601/ServerSideUrlRedirect/express.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ app.get('/some/other/path2', function(req, res) {
2323

2424
app.get('/some/path', function(req, res) {
2525
var target = req.param("target");
26-
if (isLocalURL(target))
26+
if (target.startsWith("http://example.com/"))
2727
// OK - request parameter is sanitized before incorporating it into the redirect
28-
res.redirect(target); // $ SPURIOUS: Alert
28+
res.redirect(target);
2929
else
3030
res.redirect(target); // $ Alert - sanitization doesn't apply here
3131
res.redirect(target); // $ Alert - sanitization doesn't apply here

0 commit comments

Comments
 (0)