11/**
22 * @name Unsafe url forward from remote source
3- * @description URL forward based on unvalidated user-input
3+ * @description URL forward based on unvalidated user-input
44 * may cause file information disclosure.
55 * @kind path-problem
66 * @problem.severity error
@@ -18,7 +18,16 @@ import DataFlow::PathGraph
1818class UnsafeUrlForwardFlowConfig extends TaintTracking:: Configuration {
1919 UnsafeUrlForwardFlowConfig ( ) { this = "UnsafeUrlForwardFlowConfig" }
2020
21- override predicate isSource ( DataFlow:: Node source ) { source instanceof RemoteFlowSource }
21+ override predicate isSource ( DataFlow:: Node source ) {
22+ source instanceof RemoteFlowSource and
23+ not exists ( MethodAccess ma |
24+ ma .getMethod ( ) .getName ( ) in [ "getRequestURI" , "getRequestURL" , "getPathInfo" ] and
25+ ma .getMethod ( )
26+ .getDeclaringType ( )
27+ .getASupertype * ( )
28+ .hasQualifiedName ( "javax.servlet.http" , "HttpServletRequest" )
29+ )
30+ }
2231
2332 override predicate isSink ( DataFlow:: Node sink ) { sink instanceof UnsafeUrlForwardSink }
2433
@@ -30,11 +39,24 @@ class UnsafeUrlForwardFlowConfig extends TaintTracking::Configuration {
3039 exists ( AddExpr ae |
3140 ae .getRightOperand ( ) = node .asExpr ( ) and
3241 (
33- not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) .matches ( "/WEB-INF/%" )
34- and
42+ not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) .matches ( "/WEB-INF/%" ) and
3543 not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) = "forward:"
3644 )
3745 )
46+ or
47+ exists ( MethodAccess ma , int i |
48+ ma .getMethod ( ) .hasName ( "format" ) and
49+ ma .getMethod ( ) .getDeclaringType ( ) instanceof TypeString and
50+ ma .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = "redirect:" and
51+ ma .getArgument ( i ) = node .asExpr ( ) and
52+ i != 0
53+ )
54+ or
55+ exists ( StringBuilderAppendCall ma1 , StringBuilderAppendCall ma2 |
56+ DataFlow2:: localExprFlow ( ma1 .getQualifier ( ) , ma2 .getQualifier ( ) ) and
57+ ma1 .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = "redirect:" and
58+ ma2 .getArgument ( 0 ) = node .asExpr ( )
59+ )
3860 }
3961}
4062
0 commit comments