@@ -27,19 +27,24 @@ class RegexSink extends DataFlow::ExprNode {
2727 m .getDeclaringType ( ) instanceof TypeString and
2828 (
2929 ma .getArgument ( 0 ) = this .asExpr ( ) and
30+ // TODO: confirm if more/less than the below need to be handled
3031 m .hasName ( [ "matches" , "split" , "replaceFirst" , "replaceAll" ] )
3132 )
3233 or
34+ // TODO: review Java Pattern API
3335 m .getDeclaringType ( ) .hasQualifiedName ( "java.util.regex" , "Pattern" ) and
3436 (
3537 ma .getArgument ( 0 ) = this .asExpr ( ) and
38+ // TODO: confirm if more/less than the below need to be handled
3639 m .hasName ( [ "compile" , "matches" ] )
3740 )
3841 or
42+ // TODO: read docs about regex APIs in Java
3943 m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "RegExUtils" ) and
4044 (
4145 ma .getArgument ( 1 ) = this .asExpr ( ) and
4246 m .getParameterType ( 1 ) instanceof TypeString and
47+ // TODO: confirm if more/less than the below need to be handled
4348 m .hasName ( [
4449 "removeAll" , "removeFirst" , "removePattern" , "replaceAll" , "replaceFirst" ,
4550 "replacePattern"
@@ -50,6 +55,7 @@ class RegexSink extends DataFlow::ExprNode {
5055 }
5156}
5257
58+ // TODO: is this abstract class needed? Are there pre-existing sanitizer classes that can be used instead?
5359abstract class Sanitizer extends DataFlow:: ExprNode { }
5460
5561/**
@@ -60,12 +66,12 @@ class RegExpSanitizationCall extends Sanitizer {
6066 RegExpSanitizationCall ( ) {
6167 exists ( string calleeName , string sanitize , string regexp |
6268 calleeName = this .asExpr ( ) .( Call ) .getCallee ( ) .getName ( ) and
63- sanitize = "(?:escape|saniti[sz]e)" and
64- regexp = "regexp?"
69+ sanitize = "(?:escape|saniti[sz]e)" and // TODO: confirm this is sufficient
70+ regexp = "regexp?" // TODO: confirm this is sufficient
6571 |
6672 calleeName
6773 .regexpMatch ( "(?i)(" + sanitize + ".*" + regexp + ".*)" + "|(" + regexp + ".*" + sanitize +
68- ".*)" )
74+ ".*)" ) // TODO: confirm this is sufficient
6975 )
7076 }
7177}
@@ -87,3 +93,13 @@ from DataFlow::PathNode source, DataFlow::PathNode sink, RegexInjectionConfigura
8793where c .hasFlowPath ( source , sink )
8894select sink .getNode ( ) , source , sink , "This regular expression is constructed from a $@." ,
8995 source .getNode ( ) , "user-provided value"
96+ // from MethodAccess ma
97+ // where
98+ // // ma.getMethod().hasName("startsWith") and // graphhopper
99+ // // ma.getFile().getBaseName() = "NavigateResource.java" // graphhopper
100+ // // ma.getMethod().hasName("substring") and // jfinal
101+ // // ma.getFile().getBaseName() = "FileManager.java" // jfinal
102+ // ma.getMethod().hasName("startsWith") and // roller
103+ // ma.getFile().getBaseName() = "PageServlet.java" // roller (or RegexUtil.java)
104+ // ProteinArraySignificanceTestJSON.java or MockRKeys.java for cbioportal
105+ // select ma, "method access"
0 commit comments