JS: Add test for taint propagating into RegExp.$1

This commit is contained in:
Asger Feldthaus
2020-06-24 15:49:23 +01:00
parent 3aefb7fad9
commit 17af8f7650

View File

@@ -0,0 +1,45 @@
function test(x) {
let taint = source();
if (/Hello (.*)/.exec(taint)) {
sink(RegExp.$1); // NOT OK
}
if (/Foo (.*)/.exec(x)) {
sink(RegExp.$1); // OK
} else {
sink(RegExp.$1); // NOT OK - previous capture group remains
}
if (/Hello ([a-zA-Z]+)/.exec(taint)) {
sink(RegExp.$1); // OK - capture group is sanitized
} else {
sink(RegExp.$1); // NOT OK - original capture group possibly remains
}
if (/Hello (.*)/.exec(taint) && something()) {
sink(RegExp.$1); // NOT OK
}
if (something() && /Hello (.*)/.exec(taint)) {
sink(RegExp.$1); // NOT OK
}
if (/First (.*)/.exec(taint) || /Second (.*)/.exec(taint)) {
sink(RegExp.$1); // NOT OK
}
}
function test2(x) {
var taint = source();
if (something()) {
if (/Hello (.*)/.exec(taint)) {
something();
}
}
sink(RegExp.$1); // NOT OK
}
function replaceCallback() {
return source().replace(/(\w+)/, () => {
sink(RegExp.$1); // NOT OK
});
}