|
| 1 | +/** |
| 2 | + * Provides classes and predicates related to `ratpack.*`. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | +private import semmle.code.java.dataflow.DataFlow |
| 7 | +private import semmle.code.java.dataflow.FlowSteps |
| 8 | +private import semmle.code.java.dataflow.ExternalFlow |
| 9 | + |
| 10 | +/** |
| 11 | + * Ratpack methods that access user-supplied request data. |
| 12 | + */ |
| 13 | +private class RatpackHttpSource extends SourceModelCsv { |
| 14 | + override predicate row(string row) { |
| 15 | + row = |
| 16 | + ["ratpack.http;", "ratpack.core.http;"] + |
| 17 | + [ |
| 18 | + "Request;true;getContentLength;;;ReturnValue;remote", |
| 19 | + "Request;true;getCookies;;;ReturnValue;remote", |
| 20 | + "Request;true;oneCookie;;;ReturnValue;remote", |
| 21 | + "Request;true;getHeaders;;;ReturnValue;remote", |
| 22 | + "Request;true;getPath;;;ReturnValue;remote", "Request;true;getQuery;;;ReturnValue;remote", |
| 23 | + "Request;true;getQueryParams;;;ReturnValue;remote", |
| 24 | + "Request;true;getRawUri;;;ReturnValue;remote", "Request;true;getUri;;;ReturnValue;remote", |
| 25 | + "Request;true;getBody;;;ReturnValue;remote" |
| 26 | + ] |
| 27 | + or |
| 28 | + // All Context#parse methods that return a Promise are remote flow sources. |
| 29 | + row = |
| 30 | + ["ratpack.handling;", "ratpack.core.handling;"] + "Context;true;parse;" + |
| 31 | + [ |
| 32 | + "(java.lang.Class);", "(com.google.common.reflect.TypeToken);", |
| 33 | + "(java.lang.Class,java.lang.Object);", |
| 34 | + "(com.google.common.reflect.TypeToken,java.lang.Object);", "(ratpack.core.parse.Parse);", |
| 35 | + "(ratpack.parse.Parse);" |
| 36 | + ] + ";ReturnValue;remote" |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * Ratpack methods that propagate user-supplied request data as tainted. |
| 42 | + */ |
| 43 | +private class RatpackModel extends SummaryModelCsv { |
| 44 | + override predicate row(string row) { |
| 45 | + row = |
| 46 | + ["ratpack.http;", "ratpack.core.http;"] + |
| 47 | + [ |
| 48 | + "TypedData;true;getBuffer;;;Argument[-1];ReturnValue;taint", |
| 49 | + "TypedData;true;getBytes;;;Argument[-1];ReturnValue;taint", |
| 50 | + "TypedData;true;getContentType;;;Argument[-1];ReturnValue;taint", |
| 51 | + "TypedData;true;getInputStream;;;Argument[-1];ReturnValue;taint", |
| 52 | + "TypedData;true;getText;;;Argument[-1];ReturnValue;taint", |
| 53 | + "TypedData;true;writeTo;;;Argument[-1];Argument[0];taint", |
| 54 | + "Headers;true;get;;;Argument[-1];ReturnValue;taint", |
| 55 | + "Headers;true;getAll;;;Argument[-1];ReturnValue;taint", |
| 56 | + "Headers;true;getNames;;;Argument[-1];ReturnValue;taint", |
| 57 | + "Headers;true;asMultiValueMap;;;Argument[-1];ReturnValue;taint" |
| 58 | + ] |
| 59 | + or |
| 60 | + row = |
| 61 | + ["ratpack.form;", "ratpack.core.form;"] + |
| 62 | + [ |
| 63 | + "UploadedFile;true;getFileName;;;Argument[-1];ReturnValue;taint", |
| 64 | + "Form;true;file;;;Argument[-1];ReturnValue;taint", |
| 65 | + "Form;true;files;;;Argument[-1];ReturnValue;taint" |
| 66 | + ] |
| 67 | + or |
| 68 | + row = |
| 69 | + ["ratpack.handling;", "ratpack.core.handling;"] + |
| 70 | + [ |
| 71 | + "Context;true;parse;(ratpack.http.TypedData,ratpack.parse.Parse);;Argument[0];ReturnValue;taint", |
| 72 | + "Context;true;parse;(ratpack.core.http.TypedData,ratpack.core.parse.Parse);;Argument[0];ReturnValue;taint", |
| 73 | + "Context;true;parse;(ratpack.core.http.TypedData,ratpack.core.parse.Parse);;Argument[0];MapKey of ReturnValue;taint", |
| 74 | + "Context;true;parse;(ratpack.core.http.TypedData,ratpack.core.parse.Parse);;Argument[0];MapValue of ReturnValue;taint" |
| 75 | + ] |
| 76 | + or |
| 77 | + row = |
| 78 | + ["ratpack.util;", "ratpack.func;"] + |
| 79 | + [ |
| 80 | + "MultiValueMap;true;getAll;;;MapKey of Argument[-1];MapKey of ReturnValue;value", |
| 81 | + "MultiValueMap;true;getAll;();;MapValue of Argument[-1];Element of MapValue of ReturnValue;value", |
| 82 | + "MultiValueMap;true;getAll;(Object);;MapValue of Argument[-1];Element of ReturnValue;value", |
| 83 | + "MultiValueMap;true;asMultimap;;;MapKey of Argument[-1];MapKey of ReturnValue;value", |
| 84 | + "MultiValueMap;true;asMultimap;;;MapValue of Argument[-1];MapValue of ReturnValue;value" |
| 85 | + ] |
| 86 | + } |
| 87 | +} |
0 commit comments