mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
JS: Add test for taint propagating into RegExp.$1
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user