@@ -73,6 +73,26 @@ module Shared {
7373 e = this .getBaseString ( ) .getEnclosingExpr ( ) and outcome = this .getPolarity ( ) .booleanNot ( )
7474 }
7575 }
76+
77+ /**
78+ * A sanitizer guard that checks for the existence of HTML chars in a string.
79+ * E.g. `/["'&<>]/.exec(str)`.
80+ */
81+ class ContainsHTMLGuard extends SanitizerGuard , DataFlow:: MethodCallNode {
82+ DataFlow:: RegExpCreationNode regExp ;
83+
84+ ContainsHTMLGuard ( ) {
85+ this .getMethodName ( ) = [ "test" , "exec" ] and
86+ this .getReceiver ( ) .getALocalSource ( ) = regExp and
87+ regExp .getRoot ( ) instanceof RegExpCharacterClass and
88+ forall ( string s | s = [ "\"" , "&" , "<" , ">" ] | regExp .getRoot ( ) .getAMatchedString ( ) = s )
89+ }
90+
91+ override predicate sanitizes ( boolean outcome , Expr e ) {
92+ outcome = false and e = this .getArgument ( 0 ) .asExpr ( )
93+ }
94+ }
95+
7696}
7797
7898/** Provides classes and predicates for the DOM-based XSS query. */
@@ -359,6 +379,8 @@ module DomBasedXss {
359379 )
360380 )
361381 }
382+
383+ private class ContainsHTMLGuard extends SanitizerGuard , Shared:: ContainsHTMLGuard { }
362384}
363385
364386/** Provides classes and predicates for the reflected XSS query. */
@@ -463,6 +485,8 @@ module ReflectedXss {
463485 private class UriEncodingSanitizer extends Sanitizer , Shared:: UriEncodingSanitizer { }
464486
465487 private class QuoteGuard extends SanitizerGuard , Shared:: QuoteGuard { }
488+
489+ private class ContainsHTMLGuard extends SanitizerGuard , Shared:: ContainsHTMLGuard { }
466490}
467491
468492/** Provides classes and predicates for the stored XSS query. */
@@ -496,6 +520,8 @@ module StoredXss {
496520 private class UriEncodingSanitizer extends Sanitizer , Shared:: UriEncodingSanitizer { }
497521
498522 private class QuoteGuard extends SanitizerGuard , Shared:: QuoteGuard { }
523+
524+ private class ContainsHTMLGuard extends SanitizerGuard , Shared:: ContainsHTMLGuard { }
499525}
500526
501527/** Provides classes and predicates for the XSS through DOM query. */
0 commit comments