File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed
test/library-tests/frameworks/jdk/java.net Expand file tree Collapse file tree 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 {
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
Original file line number Diff line number Diff line change 33 */
44
55import 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`. */
810class 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`. */
2835class TypeUrlDecoder extends RefType {
2936 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 {
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 ;
You can’t perform that action at this time.
0 commit comments