11/**
2- * @name Unsafe url forward from remote source
3- * @description URL forward based on unvalidated user-input
2+ * @name Unsafe URL forward or dispatch from remote source
3+ * @description URL forward or dispatch based on unvalidated user-input
44 * may cause file information disclosure.
55 * @kind path-problem
66 * @problem.severity error
77 * @precision high
8- * @id java/unsafe-url-forward
8+ * @id java/unsafe-url-forward-dispatch
99 * @tags security
1010 * external/cwe-552
1111 */
1212
1313import java
1414import UnsafeUrlForward
1515import semmle.code.java.dataflow.FlowSources
16- import semmle.code.java.frameworks.Servlets
1716import DataFlow:: PathGraph
1817
19- private class StartsWithSanitizer extends DataFlow:: BarrierGuard {
20- StartsWithSanitizer ( ) {
21- this .( MethodAccess ) .getMethod ( ) .hasName ( "startsWith" ) and
22- this .( MethodAccess ) .getMethod ( ) .getDeclaringType ( ) instanceof TypeString and
23- this .( MethodAccess ) .getMethod ( ) .getNumberOfParameters ( ) = 1
24- }
25-
26- override predicate checks ( Expr e , boolean branch ) {
27- e = this .( MethodAccess ) .getQualifier ( ) and branch = true
28- }
29- }
30-
3118class UnsafeUrlForwardFlowConfig extends TaintTracking:: Configuration {
3219 UnsafeUrlForwardFlowConfig ( ) { this = "UnsafeUrlForwardFlowConfig" }
3320
@@ -45,11 +32,15 @@ class UnsafeUrlForwardFlowConfig extends TaintTracking::Configuration {
4532
4633 override predicate isSink ( DataFlow:: Node sink ) { sink instanceof UnsafeUrlForwardSink }
4734
35+ override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof UnsafeUrlForwardSanitizer }
36+
4837 override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
49- guard instanceof StartsWithSanitizer
38+ guard instanceof UnsafeUrlForwardBarrierGuard
5039 }
5140
52- override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof UnsafeUrlForwardSanitizer }
41+ override DataFlow:: FlowFeature getAFeature ( ) {
42+ result instanceof DataFlow:: FeatureHasSourceCallContext
43+ }
5344}
5445
5546from DataFlow:: PathNode source , DataFlow:: PathNode sink , UnsafeUrlForwardFlowConfig conf
0 commit comments