Skip to content

Commit 915e106

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: remove path-injection related models and tests for now
1 parent 35a083a commit 915e106

File tree

6 files changed

+12
-626
lines changed

6 files changed

+12
-626
lines changed

java/ql/lib/ext/unsafeUrlForwardExperimentalMove.model.yml

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,18 @@ extensions:
66
- ["jakarta.servlet.http", "HttpServletRequest", True, "getServletPath", "", "", "ReturnValue", "remote", "manual"]
77
- ["javax.servlet.http", "HttpServletRequest", True, "getServletPath", "", "", "ReturnValue", "remote", "manual"]
88

9-
# # ! below added by me when debugging CVEs:
10-
# - ["org.springframework.cloud.config.server.resource", "ResourceController", True, "retrieve", "(String,String,String,ServletWebRequest,boolean)", "", "Parameter[3]", "remote", "manual"]
11-
# - ["org.springframework.web.context.request", "ServletWebRequest", True, "getContextPath", "()", "", "ReturnValue", "remote", "manual"]
12-
139
- addsTo:
1410
pack: codeql/java-all
1511
extensible: sinkModel
1612
data:
1713
- ["java.util.concurrent", "TimeUnit", True, "sleep", "", "", "Argument[0]", "thread-pause", "manual"] # ! this seems like a typo; doesn't look like it's used in the query at all
1814

19-
- ["org.springframework.core.io", "ClassPathResource", True, "getFilename", "", "", "Argument[this]", "get-resource", "manual"] # ! Note: `ClassPathResource` implements `Resource`, so it might make more sense to model some of these as `Resource` with subtype True.
20-
- ["org.springframework.core.io", "ClassPathResource", True, "getPath", "", "", "Argument[this]", "get-resource", "manual"]
21-
- ["org.springframework.core.io", "ClassPathResource", True, "getURL", "", "", "Argument[this]", "get-resource", "manual"]
22-
- ["org.springframework.core.io", "ClassPathResource", True, "resolveURL", "", "", "Argument[this]", "get-resource", "manual"]
23-
# # ! below added by me when debugging CVEs:
24-
# - ["org.springframework.cloud.config.server.resource", "ResourceController", True, "retrieve", "", "", "Argument[0]", "get-resource", "manual"] # don't need
25-
# # - ["org.springframework.cloud.config.server.resource", "ResourceController", True, "getFilePath", "", "", "Argument[0..3]", "get-resource", "manual"] # don't need
26-
# # - ["org.springframework.cloud.config.server.resource", "ResourceRepository", True, "findOne", "", "", "Argument[0..3]", "get-resource", "manual"] # convert to summary
27-
# # - ["org.springframework.core.io", "InputStreamSource", True, "getInputStream", "", "", "Argument[this]", "get-resource", "manual"] # convert to summary
28-
# - ["org.springframework.util", "StreamUtils", True, "copyToString", "", "", "Argument[0]", "get-resource", "manual"] # * public class with good docs
29-
# # - ["org.springframework.cloud.config.server.environment", "SearchPathLocator", True, "getLocations", "(String,String,String)", "", "Argument[0..2]", "get-resource", "manual"] # convert to summary
30-
# # - ["org.springframework.cloud.config.server.environment", "SearchPathLocator$Locations", True, "getLocations", "()", "", "Argument[this]", "get-resource", "manual"] # convert to summary
31-
# - ["org.springframework.core.io", "ResourceLoader", True, "getResource", "", "", "Argument[0]", "get-resource", "manual"] # * public interface with good docs, might be problematic for FPs based on fact that the ext contributor changed this to a taint step to avoid "exists" FPS (maybe there's another way to exclude those FPs though).
32-
# - ["javax.servlet", "ServletContext", True, "getResource", "", "", "Argument[0]", "get-resource", "manual"]
33-
# - ["javax.servlet", "ServletContext", True, "getResourceAsStream", "", "", "Argument[0]", "get-resource", "manual"]
34-
# - ["javax.servlet", "ServletContext", True, "getResourcePaths", "", "", "Argument[0]", "get-resource", "manual"]
35-
# - ["javax.servlet", "ServletContext", True, "getResource", "", "", "Argument[this]", "get-resource", "manual"]
36-
# - ["javax.servlet", "ServletContext", True, "getResourceAsStream", "", "", "Argument[this]", "get-resource", "manual"]
37-
# - ["javax.servlet", "ServletContext", True, "getResourcePaths", "", "", "Argument[this]", "get-resource", "manual"]
38-
# # - ["org.apache.tomcat.util.http", "RequestUtil", True, "normalize", "", "", "Argument[0]", "get-resource", "manual"]
39-
4015
- addsTo:
4116
pack: codeql/java-all
4217
extensible: summaryModel
4318
data:
44-
- ["io.undertow.server.handlers.resource", "Resource", True, "getFile", "", "", "Argument[this]", "ReturnValue", "taint", "manual"]
45-
- ["io.undertow.server.handlers.resource", "Resource", True, "getFilePath", "", "", "Argument[this]", "ReturnValue", "taint", "manual"]
46-
- ["io.undertow.server.handlers.resource", "Resource", True, "getPath", "", "", "Argument[this]", "ReturnValue", "taint", "manual"] # ! this as a taint step seems to contradict the fact that they did `ClassPathResource.getPath` as a sink for Spring...
47-
- ["java.nio.file", "Path", True, "normalize", "", "", "Argument[this]", "ReturnValue", "taint", "manual"] # ! shouldn't this be a sanitizer instead??? Or no because WEB-INF ones don't care about normalization?
19+
- ["java.nio.file", "Path", True, "normalize", "", "", "Argument[this]", "ReturnValue", "taint", "manual"]
4820
- ["java.nio.file", "Path", True, "resolve", "", "", "Argument[this]", "ReturnValue", "taint", "manual"] # ! check if this and the below are already in the default models
4921
- ["java.nio.file", "Path", True, "resolve", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
5022
- ["java.nio.file", "Path", True, "toString", "", "", "Argument[this]", "ReturnValue", "taint", "manual"]
5123
- ["java.nio.file", "Paths", True, "get", "", "", "Argument[0..1]", "ReturnValue", "taint", "manual"]
52-
53-
- ["org.springframework.core.io", "ClassPathResource", False, "ClassPathResource", "", "", "Argument[0]", "Argument[this]", "taint", "manual"]
54-
- ["org.springframework.core.io", "Resource", True, "createRelative", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
55-
# # ! below added/modified by me when debugging CVEs:
56-
- ["org.springframework.core.io", "ResourceLoader", True, "getResource", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
57-
# - ["org.springframework.cloud.config.server.resource", "ResourceRepository", True, "findOne", "", "", "Argument[0..3]", "ReturnValue", "taint", "manual"] # * public interface, but might be too specific, no easily findable docs...
58-
# - ["org.springframework.core.io", "InputStreamSource", True, "getInputStream", "", "", "Argument[this]", "ReturnValue", "taint", "manual"] # * public interface with good docs, Note: other `getInputStream`s are remote source and/or taint step, so this as taint step versus sink probably is more consistent
59-
# - ["org.springframework.cloud.config.server.environment", "SearchPathLocator", True, "getLocations", "(String,String,String)", "", "Argument[0..2]", "ReturnValue", "taint", "manual"] # * public interface with docs: https://www.javadoc.io/static/org.springframework.cloud/spring-cloud-config-server/2.1.0.RELEASE/org/springframework/cloud/config/server/environment/SearchPathLocator.html
60-
# - ["org.springframework.cloud.config.server.environment", "SearchPathLocator$Locations", True, "getLocations", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] # ! is the `Locations` class package-private? Or does it inherit public from it's enclosing interface?
61-
# - ["org.springframework.cloud.config.server.resource", "ResourceController", True, "getFilePath", "", "", "Argument[0..3]", "ReturnValue", "taint", "manual"] # don't need

java/ql/lib/semmle/code/java/security/UnsafeUrlForward.qll

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -22,96 +22,7 @@ private class RequestDispatcherSink extends UnsafeUrlForwardSink {
2222
}
2323
}
2424

25-
/** The `getResource` method of `Class`. */
26-
class GetClassResourceMethod extends Method {
27-
GetClassResourceMethod() {
28-
this.getDeclaringType() instanceof TypeClass and
29-
this.hasName("getResource")
30-
}
31-
}
32-
33-
/** The `getResourceAsStream` method of `Class`. */
34-
class GetClassResourceAsStreamMethod extends Method {
35-
GetClassResourceAsStreamMethod() {
36-
this.getDeclaringType() instanceof TypeClass and
37-
this.hasName("getResourceAsStream")
38-
}
39-
}
40-
41-
/** The `getResource` method of `ClassLoader`. */
42-
class GetClassLoaderResourceMethod extends Method {
43-
GetClassLoaderResourceMethod() {
44-
this.getDeclaringType() instanceof ClassLoaderClass and
45-
this.hasName("getResource")
46-
}
47-
}
48-
49-
/** The `getResourceAsStream` method of `ClassLoader`. */
50-
class GetClassLoaderResourceAsStreamMethod extends Method {
51-
GetClassLoaderResourceAsStreamMethod() {
52-
this.getDeclaringType() instanceof ClassLoaderClass and
53-
this.hasName("getResourceAsStream")
54-
}
55-
}
56-
57-
/** The JBoss class `FileResourceManager`. */
58-
class FileResourceManager extends RefType {
59-
FileResourceManager() {
60-
this.hasQualifiedName("io.undertow.server.handlers.resource", "FileResourceManager")
61-
}
62-
}
63-
64-
/** The JBoss method `getResource` of `FileResourceManager`. */
65-
class GetWildflyResourceMethod extends Method {
66-
GetWildflyResourceMethod() {
67-
this.getDeclaringType().getASupertype*() instanceof FileResourceManager and
68-
this.hasName("getResource")
69-
}
70-
}
71-
72-
/** The JBoss class `VirtualFile`. */
73-
class VirtualFile extends RefType {
74-
VirtualFile() { this.hasQualifiedName("org.jboss.vfs", "VirtualFile") }
75-
}
76-
77-
/** The JBoss method `getChild` of `FileResourceManager`. */
78-
class GetVirtualFileChildMethod extends Method {
79-
GetVirtualFileChildMethod() {
80-
this.getDeclaringType().getASupertype*() instanceof VirtualFile and
81-
this.hasName("getChild")
82-
}
83-
}
84-
85-
/** An argument to `getResource()` or `getResourceAsStream()`. */
86-
private class GetResourceSink extends UnsafeUrlForwardSink {
87-
GetResourceSink() {
88-
sinkNode(this, "request-forgery")
89-
or
90-
sinkNode(this, "get-resource")
91-
or
92-
exists(MethodCall ma |
93-
(
94-
ma.getMethod() instanceof GetServletResourceAsStreamMethod or
95-
ma.getMethod() instanceof GetFacesResourceAsStreamMethod or
96-
ma.getMethod() instanceof GetClassResourceAsStreamMethod or
97-
ma.getMethod() instanceof GetClassLoaderResourceAsStreamMethod or
98-
ma.getMethod() instanceof GetVirtualFileChildMethod
99-
) and
100-
ma.getArgument(0) = this.asExpr()
101-
)
102-
}
103-
}
104-
105-
/** A sink for methods that load Spring resources. */
106-
private class SpringResourceSink extends UnsafeUrlForwardSink {
107-
SpringResourceSink() {
108-
exists(MethodCall ma |
109-
ma.getMethod() instanceof GetResourceUtilsMethod and
110-
ma.getArgument(0) = this.asExpr()
111-
)
112-
}
113-
}
114-
25+
// TODO: look into `StaplerResponse.forward`, etc., and think about re-adding the MaD "request-forgery" sinks as a result
11526
/** An argument to `new ModelAndView` or `ModelAndView.setViewName`. */
11627
private class SpringModelAndViewSink extends UnsafeUrlForwardSink {
11728
SpringModelAndViewSink() {
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
/** Provides configurations to be used in queries related to unsafe URL forwarding. */
2+
13
import java
24
import semmle.code.java.security.UnsafeUrlForward
35
import semmle.code.java.dataflow.FlowSources
46
import semmle.code.java.dataflow.TaintTracking
57
import semmle.code.java.Jsf
68
import semmle.code.java.security.PathSanitizer
79

10+
/**
11+
* A taint-tracking configuration for untrusted user input in a URL forward or include.
12+
*/
813
module UnsafeUrlForwardFlowConfig implements DataFlow::ConfigSig {
914
predicate isSource(DataFlow::Node source) {
1015
source instanceof ThreatModelFlowSource and
16+
// TODO: move below logic to class in UnsafeUrlForward.qll?
1117
not exists(MethodCall ma, Method m | ma.getMethod() = m |
1218
(
1319
m instanceof HttpServletRequestGetRequestUriMethod or
@@ -25,21 +31,11 @@ module UnsafeUrlForwardFlowConfig implements DataFlow::ConfigSig {
2531
node instanceof PathInjectionSanitizer
2632
}
2733

34+
// TODO: check if the below is still needed after removing path-injection related sinks.
2835
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
29-
30-
predicate isAdditionalFlowStep(DataFlow::Node prev, DataFlow::Node succ) {
31-
exists(MethodCall ma |
32-
(
33-
ma.getMethod() instanceof GetServletResourceMethod or
34-
ma.getMethod() instanceof GetFacesResourceMethod or
35-
ma.getMethod() instanceof GetClassResourceMethod or
36-
ma.getMethod() instanceof GetClassLoaderResourceMethod or
37-
ma.getMethod() instanceof GetWildflyResourceMethod
38-
) and
39-
ma.getArgument(0) = prev.asExpr() and
40-
ma = succ.asExpr()
41-
)
42-
}
4336
}
4437

38+
/**
39+
* Taint-tracking flow for untrusted user input in a URL forward or include.
40+
*/
4541
module UnsafeUrlForwardFlow = TaintTracking::Global<UnsafeUrlForwardFlowConfig>;

java/ql/test/query-tests/security/CWE-552/UnsafeLoadSpringResource.java

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)