Skip to content

Commit 3c74c8b

Browse files
authored
Merge pull request github#13019 from jcogs33/jcogs33/url-open-stream-updates
Java: switch `url-open-stream` sink models to `experimentalSinkModel`
2 parents 27c4408 + 2e683b3 commit 3c74c8b

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

docs/codeql/codeql-language-guides/customizing-library-models-for-java.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The remaining values are used to define the **access path**, the **kind**, and t
8484
- The seventh value **Argument[0]** is the **access path** to the first argument passed to the method, which means that this is the location of the sink.
8585
- The eighth value **sql** is the kind of the sink. The sink kind is used to define the queries where the sink is in scope. In this case - the SQL injection queries.
8686
- The ninth value **manual** is the provenance of the sink, which is used to identify the origin of the sink.
87-
87+
8888
Example: Taint source from the **java.net** package
8989
----------------------------------------------------
9090
In this example we show how to model the return value from the **getInputStream** method as a **remote** source.
@@ -241,7 +241,7 @@ A neutral model is used to define that there is no flow through a method.
241241
Note that the neutral model for the **now** method is already added to the CodeQL Java analysis.
242242

243243
.. code-block:: java
244-
244+
245245
public static void taintflow() {
246246
Instant t = Instant.now(); // There is no flow from now to t.
247247
...
@@ -334,7 +334,7 @@ Below is an enumeration of the remaining sinks, but they are out of scope for th
334334

335335
- **open-url**, **jndi-injection**, **ldap**, **jdbc-url**
336336
- **mvel**, **xpath**, **groovy**, **ognl-injection**
337-
- **intent-start**, **pending-intent-sent**, **url-open-stream**, **url-redirect**
337+
- **intent-start**, **pending-intent-sent**, **url-redirect**
338338
- **create-file**, **read-file**, **write-file**, **set-hostname-verifier**
339339
- **header-splitting**, **information-leak**, **xslt**, **jexl**
340340
- **bean-validation**, **ssti**, **fragment-injection**, **regex-use[**\ `arg`\ **]**
@@ -414,4 +414,4 @@ Furthermore, it impacts the data flow analysis in the following way:
414414
That is, generated models are less trusted than manual models and only used if neither source code nor a manual model is available.
415415

416416

417-
.. include:: ../reusables/data-extensions.rst
417+
.. include:: ../reusables/data-extensions.rst
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
CWE,Sink identifier,Label
22
CWE‑089,sql,SQL injection
33
CWE‑022,create-file,Path injection
4-
CWE‑036,url-open-stream,Path traversal
54
CWE‑094,bean-validation,Code injection
65
CWE‑319,open-url,Cleartext transmission
76
CWE‑079,xss,Cross-site scripting
8-
CWE‑090,ldap,LDAP injection
7+
CWE‑090,ldap,LDAP injection
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Moved the `url-open-stream` sink models to experimental and removed `url-open-stream` as a sink option from the [Customizing Library Models for Java](https://github.com/github/codeql/blob/733a00039efdb39c3dd76ddffad5e6d6c85e6774/docs/codeql/codeql-language-guides/customizing-library-models-for-java.rst#customizing-library-models-for-java) documentation.

java/ql/lib/ext/com.google.common.io.model.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ extensions:
1111
- ["com.google.common.io", "Files", False, "toString", "(File,Charset)", "", "Argument[0]", "read-file", "ai-manual"]
1212
- ["com.google.common.io", "Files", False, "write", "(byte[],File)", "", "Argument[0]", "write-file", "ai-manual"]
1313
- ["com.google.common.io", "Files", False, "write", "(byte[],File)", "", "Argument[1]", "create-file", "manual"]
14-
- ["com.google.common.io", "Resources", False, "asByteSource", "(URL)", "", "Argument[0]", "url-open-stream", "manual"]
15-
- ["com.google.common.io", "Resources", False, "asCharSource", "(URL,Charset)", "", "Argument[0]", "url-open-stream", "manual"]
16-
- ["com.google.common.io", "Resources", False, "copy", "(URL,OutputStream)", "", "Argument[0]", "url-open-stream", "manual"]
17-
- ["com.google.common.io", "Resources", False, "readLines", "", "", "Argument[0]", "url-open-stream", "manual"]
18-
- ["com.google.common.io", "Resources", False, "toByteArray", "(URL)", "", "Argument[0]", "url-open-stream", "manual"]
19-
- ["com.google.common.io", "Resources", False, "toString", "(URL,Charset)", "", "Argument[0]", "url-open-stream", "manual"]
2014
- addsTo:
2115
pack: codeql/java-all
2216
extensible: summaryModel
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/java-all
4+
extensible: experimentalSinkModel
5+
data:
6+
- ["com.google.common.io", "Resources", False, "asByteSource", "(URL)", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]
7+
- ["com.google.common.io", "Resources", False, "asCharSource", "(URL,Charset)", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]
8+
- ["com.google.common.io", "Resources", False, "copy", "(URL,OutputStream)", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]
9+
- ["com.google.common.io", "Resources", False, "readLines", "", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]
10+
- ["com.google.common.io", "Resources", False, "toByteArray", "(URL)", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]
11+
- ["com.google.common.io", "Resources", False, "toString", "(URL,Charset)", "", "Argument[0]", "url-open-stream", "manual", "openstream-called-on-tainted-url"]

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ module ModelValidation {
273273
not kind =
274274
[
275275
"open-url", "jndi-injection", "ldap", "sql", "jdbc-url", "logging", "mvel", "xpath",
276-
"groovy", "xss", "ognl-injection", "intent-start", "pending-intent-sent",
277-
"url-open-stream", "url-redirect", "create-file", "read-file", "write-file",
278-
"set-hostname-verifier", "header-splitting", "information-leak", "xslt", "jexl",
279-
"bean-validation", "ssti", "fragment-injection", "command-injection"
276+
"groovy", "xss", "ognl-injection", "intent-start", "pending-intent-sent", "url-redirect",
277+
"create-file", "read-file", "write-file", "set-hostname-verifier", "header-splitting",
278+
"information-leak", "xslt", "jexl", "bean-validation", "ssti", "fragment-injection",
279+
"command-injection"
280280
] and
281281
not kind.matches("regex-use%") and
282282
not kind.matches("qltest%") and

java/ql/src/experimental/Security/CWE/CWE-036/OpenStream.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import semmle.code.java.dataflow.FlowSources
1717
import semmle.code.java.dataflow.ExternalFlow
1818
import RemoteUrlToOpenStreamFlow::PathGraph
1919

20+
private class ActivateModels extends ActiveExperimentalModels {
21+
ActivateModels() { this = "openstream-called-on-tainted-url" }
22+
}
23+
2024
class UrlConstructor extends ClassInstanceExpr {
2125
UrlConstructor() { this.getConstructor().getDeclaringType() instanceof TypeUrl }
2226

0 commit comments

Comments
 (0)