|
5 | 5 | import java
|
6 | 6 | private import semmle.code.java.dataflow.DataFlow
|
7 | 7 | private import semmle.code.java.dataflow.FlowSteps
|
| 8 | +private import semmle.code.java.dataflow.ExternalFlow |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * Ratpack methods that access user-supplied request data.
|
11 | 12 | */
|
12 | 13 | abstract class RatpackGetRequestDataMethod extends Method { }
|
13 | 14 |
|
14 |
| -/** |
15 |
| - * The interface `ratpack.http.Request`. |
16 |
| - * https://ratpack.io/manual/current/api/ratpack/http/Request.html |
17 |
| - */ |
18 |
| -class RatpackRequest extends RefType { |
19 |
| - RatpackRequest() { |
20 |
| - hasQualifiedName("ratpack.http", "Request") or |
21 |
| - hasQualifiedName("ratpack.core.http", "Request") |
22 |
| - } |
23 |
| -} |
24 |
| - |
25 |
| -/** |
26 |
| - * Methods on `ratpack.http.Request` that return user tainted data. |
27 |
| - */ |
28 |
| -class RatpackHttpRequestGetMethod extends RatpackGetRequestDataMethod { |
29 |
| - RatpackHttpRequestGetMethod() { |
30 |
| - getDeclaringType() instanceof RatpackRequest and |
31 |
| - hasName([ |
32 |
| - "getContentLength", "getCookies", "oneCookie", "getHeaders", "getPath", "getQuery", |
33 |
| - "getQueryParams", "getRawUri", "getUri" |
34 |
| - ]) |
| 15 | +private class RatpackHttpSource extends SourceModelCsv { |
| 16 | + override predicate row(string row) { |
| 17 | + row = |
| 18 | + ["ratpack.http;", "ratpack.core.http;"] + |
| 19 | + [ |
| 20 | + "Request;true;getContentLength;;;ReturnValue;remote", |
| 21 | + "Request;true;getCookies;;;ReturnValue;remote", |
| 22 | + "Request;true;oneCookie;;;ReturnValue;remote", |
| 23 | + "Request;true;getHeaders;;;ReturnValue;remote", |
| 24 | + "Request;true;getPath;;;ReturnValue;remote", "Request;true;getQuery;;;ReturnValue;remote", |
| 25 | + "Request;true;getQueryParams;;;ReturnValue;remote", |
| 26 | + "Request;true;getRawUri;;;ReturnValue;remote", "Request;true;getUri;;;ReturnValue;remote", |
| 27 | + "Request;true;getBody;;;ReturnValue;remote" |
| 28 | + ] |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Ratpack methods that propagate user-supplied request data as tainted. |
| 34 | + */ |
| 35 | +private class RatpackHttpModel extends SummaryModelCsv { |
| 36 | + override predicate row(string row) { |
| 37 | + row = |
| 38 | + ["ratpack.http;", "ratpack.core.http;"] + |
| 39 | + [ |
| 40 | + "TypedData;true;getBuffer;;;Argument[-1];ReturnValue;taint", |
| 41 | + "TypedData;true;getBytes;;;Argument[-1];ReturnValue;taint", |
| 42 | + "TypedData;true;getContentType;;;Argument[-1];ReturnValue;taint", |
| 43 | + "TypedData;true;getInputStream;;;Argument[-1];ReturnValue;taint", |
| 44 | + "TypedData;true;getText;;;Argument[-1];ReturnValue;taint", |
| 45 | + "TypedData;true;writeTo;;;Argument[-1];Argument[0];taint", |
| 46 | + "Headers;true;get;;;Argument[-1];ReturnValue;taint", |
| 47 | + "Headers;true;getAll;;;Argument[-1];ReturnValue;taint", |
| 48 | + "Headers;true;getNames;;;Argument[-1];ReturnValue;taint", |
| 49 | + "Headers;true;asMultiValueMap;;;Argument[-1];ReturnValue;taint" |
| 50 | + ] |
| 51 | + or |
| 52 | + row = |
| 53 | + ["ratpack.form;", "ratpack.core.form;"] + |
| 54 | + ["UploadedFile;true;getFileName;;;Argument[-1];ReturnValue;taint"] |
35 | 55 | }
|
36 | 56 | }
|
37 |
| - |
38 |
| -/** |
39 |
| - * The interface `ratpack.http.TypedData`. |
40 |
| - * https://ratpack.io/manual/current/api/ratpack/http/TypedData.html |
41 |
| - */ |
42 |
| -class RatpackTypedData extends RefType { |
43 |
| - RatpackTypedData() { |
44 |
| - hasQualifiedName("ratpack.http", "TypedData") or |
45 |
| - hasQualifiedName("ratpack.core.http", "TypedData") |
46 |
| - } |
47 |
| -} |
48 |
| - |
49 |
| -/** |
50 |
| - * Methods on `ratpack.http.TypedData` that return user tainted data. |
51 |
| - */ |
52 |
| -class RatpackHttpTypedDataGetMethod extends RatpackGetRequestDataMethod { |
53 |
| - RatpackHttpTypedDataGetMethod() { |
54 |
| - getDeclaringType() instanceof RatpackTypedData and |
55 |
| - hasName(["getBuffer", "getBytes", "getContentType", "getInputStream", "getText"]) |
56 |
| - } |
57 |
| -} |
58 |
| - |
59 |
| -/** |
60 |
| - * Methods on `ratpack.http.TypedData` that taint the parameter passed in. |
61 |
| - */ |
62 |
| -class RatpackHttpTypedDataWriteMethod extends Method { |
63 |
| - RatpackHttpTypedDataWriteMethod() { |
64 |
| - getDeclaringType() instanceof RatpackTypedData and |
65 |
| - hasName("writeTo") |
66 |
| - } |
67 |
| -} |
68 |
| - |
69 |
| -/** |
70 |
| - * The interface `ratpack.form.UploadedFile`. |
71 |
| - * https://ratpack.io/manual/current/api/ratpack/form/UploadedFile.html |
72 |
| - */ |
73 |
| -class RatpackUploadFile extends RefType { |
74 |
| - RatpackUploadFile() { |
75 |
| - hasQualifiedName("ratpack.form", "UploadedFile") or |
76 |
| - hasQualifiedName("ratpack.core.form", "UploadedFile") |
77 |
| - } |
78 |
| -} |
79 |
| - |
80 |
| -class RatpackUploadFileGetMethod extends RatpackGetRequestDataMethod { |
81 |
| - RatpackUploadFileGetMethod() { |
82 |
| - getDeclaringType() instanceof RatpackUploadFile and |
83 |
| - hasName("getFileName") |
84 |
| - } |
85 |
| -} |
86 |
| - |
87 |
| -class RatpackHeader extends RefType { |
88 |
| - RatpackHeader() { |
89 |
| - hasQualifiedName("ratpack.http", "Headers") or |
90 |
| - hasQualifiedName("ratpack.core.http", "Headers") |
91 |
| - } |
92 |
| -} |
93 |
| - |
94 |
| -private class RatpackHeaderTaintPropagatingMethod extends Method, TaintPreservingCallable { |
95 |
| - RatpackHeaderTaintPropigatingMethod() { |
96 |
| - getDeclaringType() instanceof RatpackHeader and |
97 |
| - hasName(["get", "getAll", "getNames", "asMultiValueMap"]) |
98 |
| - } |
99 |
| - |
100 |
| - override predicate returnsTaintFrom(int arg) { arg = -1 } |
101 |
| -} |
0 commit comments