Skip to content

Commit 1951461

Browse files
author
Max Schaefer
committed
JavaScript: Simplify DoubleEscaping.
Undo previous work on generalising the concept of a replacement, which did not work out.
1 parent ff002a7 commit 1951461

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

javascript/ql/src/Security/CWE-116/DoubleEscaping.ql

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,26 @@ predicate escapingScheme(string metachar, string regex) {
4141
}
4242

4343
/**
44-
* A method call that performs string replacement.
44+
* A call to `String.prototype.replace` that replaces all instances of a pattern.
4545
*/
46-
abstract class Replacement extends DataFlow::Node {
47-
/**
48-
* Holds if this replacement replaces the string `input` with `output`.
49-
*/
50-
abstract predicate replaces(string input, string output);
46+
class Replacement extends StringReplaceCall {
47+
Replacement() {
48+
isGlobal()
49+
}
5150

5251
/**
5352
* Gets the input of this replacement.
5453
*/
55-
abstract DataFlow::Node getInput();
54+
DataFlow::Node getInput() {
55+
result = this.getReceiver()
56+
}
5657

5758
/**
5859
* Gets the output of this replacement.
5960
*/
60-
abstract DataFlow::SourceNode getOutput();
61+
DataFlow::SourceNode getOutput() {
62+
result = this
63+
}
6164

6265
/**
6366
* Holds if this replacement escapes `char` using `metachar`.
@@ -123,27 +126,6 @@ abstract class Replacement extends DataFlow::Node {
123126
}
124127
}
125128

126-
/**
127-
* A call to `String.prototype.replace` that replaces all instances of a pattern.
128-
*/
129-
class GlobalStringReplacement extends Replacement, StringReplaceCall {
130-
GlobalStringReplacement() {
131-
isGlobal()
132-
}
133-
134-
override predicate replaces(string input, string output) {
135-
StringReplaceCall.super.replaces(input, output)
136-
}
137-
138-
override DataFlow::Node getInput() {
139-
result = this.getReceiver()
140-
}
141-
142-
override DataFlow::SourceNode getOutput() {
143-
result = this
144-
}
145-
}
146-
147129
from Replacement primary, Replacement supplementary, string message, string metachar
148130
where
149131
primary.escapes(metachar, _) and

0 commit comments

Comments
 (0)