File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
javascript/ql/src/semmle/javascript Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
107
107
}
108
108
109
109
/** Gets the regular expression passed as the first argument to `replace`, if any. */
110
- DataFlow:: RegExpLiteralNode getRegExp ( ) { result .flowsTo ( getArgument ( 0 ) ) }
110
+ DataFlow:: RegExpCreationNode getRegExp ( ) { result .flowsTo ( getArgument ( 0 ) ) }
111
111
112
112
/** Gets a string that is being replaced by this call. */
113
113
string getAReplacedString ( ) {
Original file line number Diff line number Diff line change @@ -1624,6 +1624,9 @@ class RegExpCreationNode extends DataFlow::SourceNode {
1624
1624
result = this .( RegExpLiteralNode ) .getFlags ( )
1625
1625
}
1626
1626
1627
+ /** Holds if the constructed predicate has the `g` flag. */
1628
+ predicate isGlobal ( ) { RegExp:: isGlobal ( getFlags ( ) ) }
1629
+
1627
1630
/** Gets a data flow node referring to this regular expression. */
1628
1631
private DataFlow:: SourceNode getAReference ( DataFlow:: TypeTracker t ) {
1629
1632
t .start ( ) and
Original file line number Diff line number Diff line change @@ -697,10 +697,28 @@ module TaintTracking {
697
697
name = "encodeURIComponent" or
698
698
name = "decodeURIComponent"
699
699
)
700
+ or
701
+ // In and out of .replace callbacks
702
+ exists ( StringReplaceCall call |
703
+ // Into the callback if the regexp does not sanitize matches
704
+ hasWildcardReplaceRegExp ( call ) and
705
+ pred = call .getReceiver ( ) and
706
+ succ = call .getReplacementCallback ( ) .getParameter ( 0 )
707
+ or
708
+ // Out of the callback
709
+ pred = call .getReplacementCallback ( ) .getReturnNode ( ) and
710
+ succ = call
711
+ )
700
712
)
701
713
}
702
714
}
703
715
716
+ /** Holds if the given call takes a regexp containing a wildcard. */
717
+ pragma [ noinline]
718
+ private predicate hasWildcardReplaceRegExp ( StringReplaceCall call ) {
719
+ RegExp:: isWildcardLike ( call .getRegExp ( ) .getRoot ( ) .getAChild * ( ) )
720
+ }
721
+
704
722
/**
705
723
* A taint propagating data flow edge arising from string formatting.
706
724
*/
You can’t perform that action at this time.
0 commit comments