mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
JavaScript: Recognise wrapped chains of replacements.
This commit is contained in:
@@ -115,6 +115,13 @@ abstract class Replacement extends DataFlow::Node {
|
||||
result.getOutput() = getASimplePredecessor*(getInput())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next replacement in this chain of replacements.
|
||||
*/
|
||||
Replacement getNextReplacement() {
|
||||
this = result.getPreviousReplacement()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an earlier replacement in this chain of replacements that
|
||||
* performs an escaping.
|
||||
@@ -231,8 +238,8 @@ class WrappedReplacement extends Replacement, DataFlow::CallNode {
|
||||
|
||||
WrappedReplacement() {
|
||||
exists(DataFlow::FunctionNode wrapped | wrapped.getFunction() = getACallee() |
|
||||
wrapped.getParameter(i).flowsTo(inner.getInput()) and
|
||||
inner.getOutput().flowsTo(wrapped.getAReturn())
|
||||
wrapped.getParameter(i).flowsTo(inner.getPreviousReplacement*().getInput()) and
|
||||
inner.getNextReplacement*().getOutput().flowsTo(wrapped.getAReturn())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@
|
||||
| tst.js:86:10:86:22 | JSON.parse(s) | This replacement may produce '\\' characters that are double-unescaped $@. | tst.js:86:10:86:47 | JSON.pa ... g, "<") | here |
|
||||
| tst.js:99:10:99:66 | s.repla ... &") | This replacement may double-escape '&' characters from $@. | tst.js:99:10:99:43 | s.repla ... epl[c]) | here |
|
||||
| tst.js:107:10:107:53 | encodeD ... &") | This replacement may double-escape '&' characters from $@. | tst.js:107:10:107:30 | encodeD ... otes(s) | here |
|
||||
| tst.js:115:10:115:47 | encodeQ ... &") | This replacement may double-escape '&' characters from $@. | tst.js:115:10:115:24 | encodeQuotes(s) | here |
|
||||
|
||||
@@ -106,3 +106,11 @@ function encodeDoubleQuotes(s) {
|
||||
function badWrappedEncode(s) {
|
||||
return encodeDoubleQuotes(s).replace(/&/g, "&");
|
||||
}
|
||||
|
||||
function encodeQuotes(s) {
|
||||
return s.replace(/"/g, """).replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function badWrappedEncode2(s) {
|
||||
return encodeQuotes(s).replace(/&/g, "&");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user