Skip to content

Commit 1a2db10

Browse files
committed
recognize barrier guard where the result is stored in a variable
1 parent 562a38c commit 1a2db10

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

javascript/ql/src/semmle/javascript/dataflow/Configuration.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private predicate barrierGuardBlocksNode(BarrierGuardNode guard, DataFlow::Node
438438
barrierGuardIsRelevant(guard) and
439439
exists(AccessPath p, BasicBlock bb, ConditionGuardNode cond, boolean outcome |
440440
nd = DataFlow::valueNode(p.getAnInstanceIn(bb)) and
441-
guard.getEnclosingExpr() = cond.getTest() and
441+
(guard.getEnclosingExpr() = cond.getTest() or guard = cond.getTest().flow().getALocalSource()) and
442442
outcome = cond.getOutcome() and
443443
barrierGuardBlocksAccessPath(guard, outcome, p, label) and
444444
cond.dominates(bb)

javascript/ql/test/query-tests/Security/CWE-079/ReflectedXssGood.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,20 @@ app.get('/user/:id', function(req, res) {
6868

6969
res.send(escapeHtml1(url)); // OK
7070
});
71+
72+
const matchHtmlRegExp = /["'&<>]/;
73+
function escapeHtml2 (string) {
74+
const str = '' + string;
75+
const match = matchHtmlRegExp.exec(str);
76+
77+
if (!match) {
78+
return str;
79+
}
80+
}
81+
82+
app.get('/user/:id', function(req, res) {
83+
const url = req.params.id;
84+
85+
res.send(escapeHtml2(url)); // OK
86+
});
87+

0 commit comments

Comments
 (0)