Skip to content

Commit 283376e

Browse files
haby0smowton
authored andcommitted
Modify the model
1 parent 679652e commit 283376e

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

java/ql/lib/semmle/code/java/frameworks/Servlets.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ library class HttpServletRequestGetQueryStringMethod extends Method {
7474
/**
7575
* The method `getPathInfo()` declared in `javax.servlet.http.HttpServletRequest`.
7676
*/
77-
library class HttpServletRequestGetPathMethod extends Method {
77+
class HttpServletRequestGetPathMethod extends Method {
7878
HttpServletRequestGetPathMethod() {
7979
getDeclaringType() instanceof HttpServletRequest and
8080
hasName("getPathInfo") and
@@ -120,7 +120,7 @@ library class HttpServletRequestGetHeaderNamesMethod extends Method {
120120
/**
121121
* The method `getRequestURL()` declared in `javax.servlet.http.HttpServletRequest`.
122122
*/
123-
library class HttpServletRequestGetRequestURLMethod extends Method {
123+
class HttpServletRequestGetRequestURLMethod extends Method {
124124
HttpServletRequestGetRequestURLMethod() {
125125
getDeclaringType() instanceof HttpServletRequest and
126126
hasName("getRequestURL") and
@@ -131,7 +131,7 @@ library class HttpServletRequestGetRequestURLMethod extends Method {
131131
/**
132132
* The method `getRequestURI()` declared in `javax.servlet.http.HttpServletRequest`.
133133
*/
134-
library class HttpServletRequestGetRequestURIMethod extends Method {
134+
class HttpServletRequestGetRequestURIMethod extends Method {
135135
HttpServletRequestGetRequestURIMethod() {
136136
getDeclaringType() instanceof HttpServletRequest and
137137
hasName("getRequestURI") and
@@ -197,9 +197,7 @@ class HttpServletResponseSendErrorMethod extends Method {
197197
class ServletRequestGetRequestDispatcherMethod extends Method {
198198
ServletRequestGetRequestDispatcherMethod() {
199199
getDeclaringType() instanceof ServletRequest and
200-
hasName("getRequestDispatcher") and
201-
getNumberOfParameters() = 1 and
202-
getParameter(0).getType() instanceof TypeString
200+
hasName("getRequestDispatcher")
203201
}
204202
}
205203

java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java
1414
import UnsafeUrlForward
1515
import semmle.code.java.dataflow.FlowSources
16+
import semmle.code.java.frameworks.Servlets
1617
import DataFlow::PathGraph
1718

1819
private class StartsWithSanitizer extends DataFlow::BarrierGuard {
@@ -32,12 +33,12 @@ class UnsafeUrlForwardFlowConfig extends TaintTracking::Configuration {
3233

3334
override predicate isSource(DataFlow::Node source) {
3435
source instanceof RemoteFlowSource and
35-
not exists(MethodAccess ma |
36-
ma.getMethod().getName() in ["getRequestURI", "getRequestURL", "getPathInfo"] and
37-
ma.getMethod()
38-
.getDeclaringType()
39-
.getASupertype*()
40-
.hasQualifiedName("javax.servlet.http", "HttpServletRequest") and
36+
not exists(MethodAccess ma, Method m | ma.getMethod() = m |
37+
(
38+
m instanceof HttpServletRequestGetRequestURIMethod or
39+
m instanceof HttpServletRequestGetRequestURLMethod or
40+
m instanceof HttpServletRequestGetPathMethod
41+
) and
4142
ma = source.asExpr()
4243
)
4344
}

java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import java
22
import DataFlow
33
import semmle.code.java.dataflow.FlowSources
44
import semmle.code.java.frameworks.Servlets
5+
import semmle.code.java.frameworks.spring.SpringWeb
56

67
/** A sanitizer for unsafe url forward vulnerabilities. */
78
abstract class UnsafeUrlForwardSanitizer extends DataFlow::Node { }
@@ -144,7 +145,7 @@ private class UnsafeUrlForwardSanitizedExpr extends Expr {
144145
/**
145146
* A concatenate expression using the string `forward:` on the left.
146147
*
147-
* E.g: `"forward:" + url`
148+
* For example, `"forward:" + url`.
148149
*/
149150
private class ForwardBuilderExpr extends AddExpr {
150151
ForwardBuilderExpr() {
@@ -155,7 +156,7 @@ private class ForwardBuilderExpr extends AddExpr {
155156
/**
156157
* A call to `StringBuilder.append` or `StringBuffer.append` method, and the parameter value is `"forward:"`.
157158
*
158-
* E.g: `StringBuilder.append("forward:")`
159+
* For example, `StringBuilder.append("forward:")`.
159160
*/
160161
private class ForwardAppendCall extends StringBuilderAppend {
161162
ForwardAppendCall() {
@@ -191,7 +192,7 @@ private class SpringUrlForwardSink extends UnsafeUrlForwardSink {
191192
)
192193
or
193194
exists(ClassInstanceExpr cie |
194-
cie.getConstructedType().hasQualifiedName("org.springframework.web.servlet", "ModelAndView") and
195+
cie.getConstructedType() instanceof ModelAndView and
195196
(
196197
exists(ForwardBuilderExpr rbe |
197198
rbe = cie.getArgument(0) and rbe.getRightOperand() = this.asExpr()
@@ -201,12 +202,6 @@ private class SpringUrlForwardSink extends UnsafeUrlForwardSink {
201202
)
202203
)
203204
or
204-
exists(MethodAccess ma |
205-
ma.getMethod().hasName("setViewName") and
206-
ma.getMethod()
207-
.getDeclaringType()
208-
.hasQualifiedName("org.springframework.web.servlet", "ModelAndView") and
209-
ma.getArgument(0) = this.asExpr()
210-
)
205+
exists(SpringModelAndViewSetViewNameCall smavsvnc | smavsvnc.getArgument(0) = this.asExpr())
211206
}
212207
}

0 commit comments

Comments
 (0)