| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,14 @@ import DataFlow | |||
| 3 | 3 | import semmle.code.java.dataflow.FlowSources | |
| 4 | 4 | import semmle.code.java.frameworks.Servlets | |
| 5 | 5 | ||
| 6 | + /** A call to `StringBuilder.append` method. */ | ||
| 7 | + class StringBuilderAppendCall extends MethodAccess { | ||
| 8 | + StringBuilderAppendCall() { | ||
| 9 | + this.getMethod().hasName("append") and | ||
| 10 | + this.getMethod().getDeclaringType() instanceof StringBuildingType | ||
| 11 | + } | ||
| 12 | + } | ||
| 13 | + | ||
| 6 | 14 | /** | |
| 7 | 15 | * A concatenate expression using the string `forward:` on the left. | |
| 8 | 16 | * | |
@@ -19,10 +27,8 @@ class ForwardBuilderExpr extends AddExpr { | |||
| 19 | 27 | * | |
| 20 | 28 | * E.g: `StringBuilder.append("forward:")` | |
| 21 | 29 | */ | |
| 22 | - class ForwardAppendCall extends MethodAccess { | ||
| 30 | + class ForwardAppendCall extends StringBuilderAppendCall { | ||
| 23 | 31 | ForwardAppendCall() { | |
| 24 | - this.getMethod().hasName("append") and | ||
| 25 | - this.getMethod().getDeclaringType() instanceof StringBuildingType and | ||
| 26 | 32 | this.getArgument(0).(CompileTimeConstantExpr).getStringValue() = "forward:" | |
| 27 | 33 | } | |
| 28 | 34 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments