1
1
/**
2
2
* @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
4
4
* may cause file information disclosure.
5
5
* @kind path-problem
6
6
* @problem.severity error
@@ -18,7 +18,16 @@ import DataFlow::PathGraph
18
18
class UnsafeUrlForwardFlowConfig extends TaintTracking:: Configuration {
19
19
UnsafeUrlForwardFlowConfig ( ) { this = "UnsafeUrlForwardFlowConfig" }
20
20
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
+ }
22
31
23
32
override predicate isSink ( DataFlow:: Node sink ) { sink instanceof UnsafeUrlForwardSink }
24
33
@@ -30,11 +39,24 @@ class UnsafeUrlForwardFlowConfig extends TaintTracking::Configuration {
30
39
exists ( AddExpr ae |
31
40
ae .getRightOperand ( ) = node .asExpr ( ) and
32
41
(
33
- not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) .matches ( "/WEB-INF/%" )
34
- and
42
+ not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) .matches ( "/WEB-INF/%" ) and
35
43
not ae .getLeftOperand ( ) .( CompileTimeConstantExpr ) .getStringValue ( ) = "forward:"
36
44
)
37
45
)
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
+ )
38
60
}
39
61
}
40
62
0 commit comments