Skip to content

Commit 91f5f08

Browse files
authored
Merge pull request #17025 from jcogs33/jcogs33/java/adjust-url-syntheticfield
Java: add TaintInheritingContent for URL synthetic fields
2 parents 30abc95 + 5854e88 commit 91f5f08

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added flow through some methods of the class `java.net.URL` by ensuring that the fields of a URL are tainted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private module Frameworks {
2222
private import semmle.code.java.frameworks.IoJsonWebToken
2323
private import semmle.code.java.frameworks.jackson.JacksonSerializability
2424
private import semmle.code.java.frameworks.InputStream
25+
private import semmle.code.java.frameworks.Networking
2526
private import semmle.code.java.frameworks.Properties
2627
private import semmle.code.java.frameworks.Protobuf
2728
private import semmle.code.java.frameworks.ThreadLocal

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44

55
import semmle.code.java.Type
6+
private import semmle.code.java.dataflow.DataFlow
7+
private import semmle.code.java.dataflow.FlowSteps
68

79
/** The type `java.net.URLConnection`. */
810
class TypeUrlConnection extends RefType {
@@ -24,6 +26,11 @@ class TypeUrl extends RefType {
2426
TypeUrl() { this.hasQualifiedName("java.net", "URL") }
2527
}
2628

29+
/** Specifies that if a `URL` is tainted, then so are its synthetic fields. */
30+
private class UrlFieldsInheritTaint extends DataFlow::SyntheticFieldContent, TaintInheritingContent {
31+
UrlFieldsInheritTaint() { this.getField().matches("java.net.URL.%") }
32+
}
33+
2734
/** The type `java.net.URLDecoder`. */
2835
class TypeUrlDecoder extends RefType {
2936
TypeUrlDecoder() { this.hasQualifiedName("java.net", "URLDecoder") }

java/ql/test/library-tests/frameworks/jdk/java.net/Test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,29 @@ public void test() throws Exception {
9090
out = in.toURL();
9191
sink(out); // $ hasTaintFlow
9292
}
93+
{
94+
// manual test for `URI.toURL().getPath()`; checks that if a `URL` is tainted, then so are its synthetic fields
95+
// java.net;URL;False;getPath;();;Argument[this].SyntheticField[java.net.URL.path];ReturnValue;taint;ai-manual
96+
URL out = null;
97+
URI in = (URI) source();
98+
out = in.toURL();
99+
sink(out.getPath()); // $ hasTaintFlow
100+
}
93101
{
94102
// "java.net;URL;false;URL;(String);;Argument[0];Argument[this];taint;manual"
95103
URL out = null;
96104
String in = (String) source();
97105
out = new URL(in);
98106
sink(out); // $ hasTaintFlow
99107
}
108+
{
109+
// manual test for `URL(String).getPath()`; checks that if a `URL` is tainted, then so are its synthetic fields
110+
// java.net;URL;False;getPath;();;Argument[this].SyntheticField[java.net.URL.path];ReturnValue;taint;ai-manual
111+
URL out = null;
112+
String in = (String) source();
113+
out = new URL(in);
114+
sink(out.getPath()); // $ hasTaintFlow
115+
}
100116
{
101117
// "java.net;URL;false;URL;(URL,String);;Argument[0];Argument[this];taint;ai-generated"
102118
URL out = null;

0 commit comments

Comments
 (0)