Skip to content

Commit 17af8f7

Browse files
committed
JS: Add test for taint propagating into RegExp.$1
1 parent 3aefb7f commit 17af8f7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function test(x) {
2+
let taint = source();
3+
4+
if (/Hello (.*)/.exec(taint)) {
5+
sink(RegExp.$1); // NOT OK
6+
}
7+
8+
if (/Foo (.*)/.exec(x)) {
9+
sink(RegExp.$1); // OK
10+
} else {
11+
sink(RegExp.$1); // NOT OK - previous capture group remains
12+
}
13+
14+
if (/Hello ([a-zA-Z]+)/.exec(taint)) {
15+
sink(RegExp.$1); // OK - capture group is sanitized
16+
} else {
17+
sink(RegExp.$1); // NOT OK - original capture group possibly remains
18+
}
19+
20+
if (/Hello (.*)/.exec(taint) && something()) {
21+
sink(RegExp.$1); // NOT OK
22+
}
23+
if (something() && /Hello (.*)/.exec(taint)) {
24+
sink(RegExp.$1); // NOT OK
25+
}
26+
if (/First (.*)/.exec(taint) || /Second (.*)/.exec(taint)) {
27+
sink(RegExp.$1); // NOT OK
28+
}
29+
}
30+
31+
function test2(x) {
32+
var taint = source();
33+
if (something()) {
34+
if (/Hello (.*)/.exec(taint)) {
35+
something();
36+
}
37+
}
38+
sink(RegExp.$1); // NOT OK
39+
}
40+
41+
function replaceCallback() {
42+
return source().replace(/(\w+)/, () => {
43+
sink(RegExp.$1); // NOT OK
44+
});
45+
}

0 commit comments

Comments
 (0)