Skip to content

Commit 9c5ad44

Browse files
authored
Merge pull request github#5782 from erik-krogh/domFP
Approved by esbena
2 parents 73521e2 + d5450f1 commit 9c5ad44

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

javascript/ql/src/semmle/javascript/Regexp.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ class RegExpQuantifier extends RegExpTerm, @regexp_quantifier {
191191
predicate isGreedy() { is_greedy(this) }
192192
}
193193

194+
/**
195+
* A regular expression term that permits unlimited repetitions.
196+
*/
197+
class InfiniteRepetitionQuantifier extends RegExpQuantifier {
198+
InfiniteRepetitionQuantifier() {
199+
this instanceof RegExpPlus
200+
or
201+
this instanceof RegExpStar
202+
or
203+
this instanceof RegExpRange and not exists(this.(RegExpRange).getUpperBound())
204+
}
205+
}
206+
194207
/**
195208
* An escaped regular expression term, that is, a regular expression
196209
* term starting with a backslash.
@@ -1065,6 +1078,12 @@ module RegExp {
10651078
not cls.isInverted() and
10661079
cls.getAChild().(RegExpCharacterClassEscape).getValue().isUppercase()
10671080
)
1081+
or
1082+
// an unlimited number of wildcards, is also a wildcard.
1083+
exists(InfiniteRepetitionQuantifier q |
1084+
term = q and
1085+
isWildcardLike(q.getAChild())
1086+
)
10681087
}
10691088

10701089
/**

javascript/ql/src/semmle/javascript/security/dataflow/Xss.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ module Shared {
3434
class MetacharEscapeSanitizer extends Sanitizer, StringReplaceCall {
3535
MetacharEscapeSanitizer() {
3636
isGlobal() and
37-
RegExp::alwaysMatchesMetaCharacter(getRegExp().getRoot(), ["<", "'", "\""])
37+
(
38+
RegExp::alwaysMatchesMetaCharacter(getRegExp().getRoot(), ["<", "'", "\""])
39+
or
40+
// or it's like a wild-card.
41+
RegExp::isWildcardLike(getRegExp().getRoot())
42+
)
3843
}
3944
}
4045

javascript/ql/src/semmle/javascript/security/performance/ReDoSUtil.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,6 @@ private predicate isReDoSCandidate(State state, string pump) {
5353
)
5454
}
5555

56-
/**
57-
* A regular expression term that permits unlimited repetitions.
58-
*/
59-
class InfiniteRepetitionQuantifier extends RegExpQuantifier {
60-
InfiniteRepetitionQuantifier() {
61-
this instanceof RegExpPlus
62-
or
63-
this instanceof RegExpStar
64-
or
65-
this instanceof RegExpRange and not exists(this.(RegExpRange).getUpperBound())
66-
}
67-
}
68-
6956
/**
7057
* Gets the char after `c` (from a simplified ASCII table).
7158
*/

javascript/ql/test/query-tests/Security/CWE-079/XssThroughDom/xss-through-dom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@
8585

8686
$("#id").html(anser.ansiToHtml(text)); // NOT OK
8787
$("#id").html(new anser().process(text)); // NOT OK
88+
89+
$("section h1").each(function(){
90+
$("nav ul").append("<a href='#" + $(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,'') + "'>Section</a>"); // OK
91+
});
8892
})();

0 commit comments

Comments
 (0)