11import java
2+ private import experimental.semmle.code.java.frameworks.Jsf
23private import semmle.code.java.dataflow.ExternalFlow
34private import semmle.code.java.dataflow.FlowSources
45private import semmle.code.java.dataflow.StringPrefixes
6+ private import semmle.code.java.frameworks.javaee.ejb.EJBRestrictions
57
68/** A sink for unsafe URL forward vulnerabilities. */
79abstract class UnsafeUrlForwardSink extends DataFlow:: Node { }
@@ -19,6 +21,84 @@ private class RequestDispatcherSink extends UnsafeUrlForwardSink {
1921 }
2022}
2123
24+ /** The `getResource` method of `Class`. */
25+ class GetClassResourceMethod extends Method {
26+ GetClassResourceMethod ( ) {
27+ this .getDeclaringType ( ) instanceof TypeClass and
28+ this .hasName ( "getResource" )
29+ }
30+ }
31+
32+ /** The `getResourceAsStream` method of `Class`. */
33+ class GetClassResourceAsStreamMethod extends Method {
34+ GetClassResourceAsStreamMethod ( ) {
35+ this .getDeclaringType ( ) instanceof TypeClass and
36+ this .hasName ( "getResourceAsStream" )
37+ }
38+ }
39+
40+ /** The `getResource` method of `ClassLoader`. */
41+ class GetClassLoaderResourceMethod extends Method {
42+ GetClassLoaderResourceMethod ( ) {
43+ this .getDeclaringType ( ) instanceof ClassLoaderClass and
44+ this .hasName ( "getResource" )
45+ }
46+ }
47+
48+ /** The `getResourceAsStream` method of `ClassLoader`. */
49+ class GetClassLoaderResourceAsStreamMethod extends Method {
50+ GetClassLoaderResourceAsStreamMethod ( ) {
51+ this .getDeclaringType ( ) instanceof ClassLoaderClass and
52+ this .hasName ( "getResourceAsStream" )
53+ }
54+ }
55+
56+ /** The JBoss class `FileResourceManager`. */
57+ class FileResourceManager extends RefType {
58+ FileResourceManager ( ) {
59+ this .hasQualifiedName ( "io.undertow.server.handlers.resource" , "FileResourceManager" )
60+ }
61+ }
62+
63+ /** The JBoss method `getResource` of `FileResourceManager`. */
64+ class GetWildflyResourceMethod extends Method {
65+ GetWildflyResourceMethod ( ) {
66+ this .getDeclaringType ( ) .getASupertype * ( ) instanceof FileResourceManager and
67+ this .hasName ( "getResource" )
68+ }
69+ }
70+
71+ /** The JBoss class `VirtualFile`. */
72+ class VirtualFile extends RefType {
73+ VirtualFile ( ) { this .hasQualifiedName ( "org.jboss.vfs" , "VirtualFile" ) }
74+ }
75+
76+ /** The JBoss method `getChild` of `FileResourceManager`. */
77+ class GetVirtualFileChildMethod extends Method {
78+ GetVirtualFileChildMethod ( ) {
79+ this .getDeclaringType ( ) .getASupertype * ( ) instanceof VirtualFile and
80+ this .hasName ( "getChild" )
81+ }
82+ }
83+
84+ /** An argument to `getResource()` or `getResourceAsStream()`. */
85+ private class GetResourceSink extends UnsafeUrlForwardSink {
86+ GetResourceSink ( ) {
87+ sinkNode ( this , "open-url" )
88+ or
89+ exists ( MethodAccess ma |
90+ (
91+ ma .getMethod ( ) instanceof GetServletResourceAsStreamMethod or
92+ ma .getMethod ( ) instanceof GetFacesResourceAsStreamMethod or
93+ ma .getMethod ( ) instanceof GetClassResourceAsStreamMethod or
94+ ma .getMethod ( ) instanceof GetClassLoaderResourceAsStreamMethod or
95+ ma .getMethod ( ) instanceof GetVirtualFileChildMethod
96+ ) and
97+ ma .getArgument ( 0 ) = this .asExpr ( )
98+ )
99+ }
100+ }
101+
22102/** An argument to `new ModelAndView` or `ModelAndView.setViewName`. */
23103private class SpringModelAndViewSink extends UnsafeUrlForwardSink {
24104 SpringModelAndViewSink ( ) {
@@ -80,15 +160,18 @@ private class ServletGetPathSource extends SourceModelCsv {
80160 }
81161}
82162
83- /** Taint model related to `java.nio.file.Path`. */
163+ /** Taint model related to `java.nio.file.Path` and `io.undertow.server.handlers.resource.Resource` . */
84164private class FilePathFlowStep extends SummaryModelCsv {
85165 override predicate row ( string row ) {
86166 row =
87167 [
88168 "java.nio.file;Paths;true;get;;;Argument[0..1];ReturnValue;taint" ,
89169 "java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint" ,
90170 "java.nio.file;Path;true;normalize;;;Argument[-1];ReturnValue;taint" ,
91- "java.nio.file;Path;true;toString;;;Argument[-1];ReturnValue;taint"
171+ "java.nio.file;Path;true;toString;;;Argument[-1];ReturnValue;taint" ,
172+ "io.undertow.server.handlers.resource;Resource;true;getFile;;;Argument[-1];ReturnValue;taint" ,
173+ "io.undertow.server.handlers.resource;Resource;true;getFilePath;;;Argument[-1];ReturnValue;taint" ,
174+ "io.undertow.server.handlers.resource;Resource;true;getPath;;;Argument[-1];ReturnValue;taint"
92175 ]
93176 }
94177}
0 commit comments