File tree 4 files changed +28
-0
lines changed
test/library-tests/frameworks/jdk/java.net 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ private module Frameworks {
22
22
private import semmle.code.java.frameworks.IoJsonWebToken
23
23
private import semmle.code.java.frameworks.jackson.JacksonSerializability
24
24
private import semmle.code.java.frameworks.InputStream
25
+ private import semmle.code.java.frameworks.Networking
25
26
private import semmle.code.java.frameworks.Properties
26
27
private import semmle.code.java.frameworks.Protobuf
27
28
private import semmle.code.java.frameworks.ThreadLocal
Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
import semmle.code.java.Type
6
+ private import semmle.code.java.dataflow.DataFlow
7
+ private import semmle.code.java.dataflow.FlowSteps
6
8
7
9
/** The type `java.net.URLConnection`. */
8
10
class TypeUrlConnection extends RefType {
@@ -24,6 +26,11 @@ class TypeUrl extends RefType {
24
26
TypeUrl ( ) { this .hasQualifiedName ( "java.net" , "URL" ) }
25
27
}
26
28
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
+
27
34
/** The type `java.net.URLDecoder`. */
28
35
class TypeUrlDecoder extends RefType {
29
36
TypeUrlDecoder ( ) { this .hasQualifiedName ( "java.net" , "URLDecoder" ) }
Original file line number Diff line number Diff line change @@ -90,13 +90,29 @@ public void test() throws Exception {
90
90
out = in .toURL ();
91
91
sink (out ); // $ hasTaintFlow
92
92
}
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
+ }
93
101
{
94
102
// "java.net;URL;false;URL;(String);;Argument[0];Argument[this];taint;manual"
95
103
URL out = null ;
96
104
String in = (String ) source ();
97
105
out = new URL (in );
98
106
sink (out ); // $ hasTaintFlow
99
107
}
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
+ }
100
116
{
101
117
// "java.net;URL;false;URL;(URL,String);;Argument[0];Argument[this];taint;ai-generated"
102
118
URL out = null ;
You can’t perform that action at this time.
0 commit comments