|
1 | 1 | import java |
2 | | -import semmle.code.java.dataflow.FlowSources |
3 | | -import semmle.code.java.frameworks.play.PlayController |
4 | | -import semmle.code.java.frameworks.play.PlayAddCSRFToken |
5 | | -import semmle.code.java.frameworks.play.PlayAsyncResult |
6 | | -import semmle.code.java.frameworks.play.PlayBodyParser |
7 | | -import semmle.code.java.frameworks.play.PlayHTTPRequestHeader |
8 | | -import semmle.code.java.frameworks.play.PlayMVCResult |
9 | | -import semmle.code.java.frameworks.play.PlayMVCResults |
| 2 | + |
| 3 | +/** |
| 4 | + * Play MVC Framework Result Class |
| 5 | + */ |
| 6 | +class PlayMVCResultClass extends Class { |
| 7 | + PlayMVCResultClass() { this.hasQualifiedName("play.mvc", "Result") } |
| 8 | +} |
| 9 | + |
| 10 | +/** |
| 11 | + * Play MVC Framework Results Class |
| 12 | + * |
| 13 | + * Documentation: https://www.playframework.com/documentation/2.8.x/JavaActions |
| 14 | + */ |
| 15 | +class PlayMVCResultsClass extends Class { |
| 16 | + PlayMVCResultsClass() { this.hasQualifiedName("play.mvc", "Results") } |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Play MVC Framework HTTP Request Header Class |
| 21 | + */ |
| 22 | +class PlayMVCHTTPRequestHeader extends RefType { |
| 23 | + PlayMVCHTTPRequestHeader() { this.hasQualifiedName("play.mvc", "Http$RequestHeader") } |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * Play Framework Explicit Body Parser Annotation |
| 28 | + * |
| 29 | + * Documentation: https://www.playframework.com/documentation/2.8.x/JavaBodyParsers#Choosing-an-explicit-body-parser |
| 30 | + */ |
| 31 | +class PlayBodyParserAnnotation extends Annotation { |
| 32 | + PlayBodyParserAnnotation() { this.getType().hasQualifiedName("play.mvc", "BodyParser<>$Of") } |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Play Framework AddCSRFToken Annotation |
| 37 | + * |
| 38 | + * Documentation: https://www.playframework.com/documentation/2.8.x/JavaCsrf |
| 39 | + */ |
| 40 | +class PlayAddCSRFTokenAnnotation extends Annotation { |
| 41 | + PlayAddCSRFTokenAnnotation() { |
| 42 | + this.getType().hasQualifiedName("play.filters.csrf", "AddCSRFToken") |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Play Framework Async Promise - Gets the Promise<Result> Generic Member/Type of (play.libs.F) |
| 48 | + * |
| 49 | + * Documentation: https://www.playframework.com/documentation/2.5.1/api/java/play/libs/F.Promise.html |
| 50 | + */ |
| 51 | +class PlayAsyncResultPromise extends Member { |
| 52 | + PlayAsyncResultPromise() { |
| 53 | + exists(Class c | |
| 54 | + c.hasQualifiedName("play.libs", "F") and |
| 55 | + this = c.getAMember() and |
| 56 | + this.getQualifiedName() = "F.Promise<Result>" |
| 57 | + ) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * Play Framework Async Generic Result - Gets the CompletionStage<Result> Generic Type of (java.util.concurrent) |
| 63 | + * |
| 64 | + * Documentation: https://www.playframework.com/documentation/2.6.x/JavaAsync |
| 65 | + */ |
| 66 | +class PlayAsyncResultCompletionStage extends Type { |
| 67 | + PlayAsyncResultCompletionStage() { |
| 68 | + this.hasName("CompletionStage<Result>") and |
| 69 | + this.getCompilationUnit().getPackage().hasName("java.util.concurrent") |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +/** |
| 74 | + * Play Framework Controllers which extends PlayMVCController recursively - Used to find all Controllers |
| 75 | + */ |
| 76 | +class PlayController extends Class { |
| 77 | + PlayController() { |
| 78 | + this.extendsOrImplements*(any(Class t | t.hasQualifiedName("play.mvc", "Controller"))) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * Play Framework Controller Action Methods - Mappings to route files |
| 84 | + * |
| 85 | + * Sample Route - `POST /login @com.company.Application.login()` |
| 86 | + * |
| 87 | + * Example - class get's `index` & `login` as valid action methods. |
| 88 | + * ``` |
| 89 | + * public class Application extends Controller { |
| 90 | + * public Result index(String username, String password) { |
| 91 | + * return ok("It works!"); |
| 92 | + * } |
| 93 | + * |
| 94 | + * public Result login() { |
| 95 | + * return ok("Log me In!"); |
| 96 | + * } |
| 97 | + * } |
| 98 | + * ``` |
| 99 | + * |
| 100 | + * Documentation: https://www.playframework.com/documentation/2.8.x/JavaActions |
| 101 | + */ |
| 102 | +class PlayControllerActionMethod extends Method { |
| 103 | + PlayControllerActionMethod() { |
| 104 | + this = any(PlayController c).getAMethod() and |
| 105 | + ( |
| 106 | + this.getReturnType() instanceof PlayAsyncResultPromise or |
| 107 | + this.getReturnType() instanceof PlayMVCResultClass or |
| 108 | + this.getReturnType() instanceof PlayAsyncResultCompletionStage |
| 109 | + ) |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +/** |
| 114 | + * Play Action-Method parameters. These are a source of user input |
| 115 | + * |
| 116 | + * Example - Class get's `username` & `password` as valid parameters |
| 117 | + * ``` |
| 118 | + * public class Application extends Controller { |
| 119 | + * public Result index(String username, String password) { |
| 120 | + * return ok("It works!"); |
| 121 | + * } |
| 122 | + * } |
| 123 | + * ``` |
| 124 | + */ |
| 125 | +class PlayActionMethodQueryParameter extends Parameter { |
| 126 | + PlayActionMethodQueryParameter() { |
| 127 | + exists(PlayControllerActionMethod a | |
| 128 | + a.isPublic() and |
| 129 | + this = a.getAParameter() |
| 130 | + ) |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +/** |
| 135 | + * Play Framework HTTPRequestHeader Methods - `headers`, `getQueryString`, `getHeader` |
| 136 | + * |
| 137 | + * Documentation: https://www.playframework.com/documentation/2.6.0/api/java/play/mvc/Http.RequestHeader.html |
| 138 | + */ |
| 139 | +class PlayMVCHTTPRequestHeaderMethods extends Method { |
| 140 | + PlayMVCHTTPRequestHeaderMethods() { this.getDeclaringType() instanceof PlayMVCHTTPRequestHeader } |
| 141 | + |
| 142 | + /** |
| 143 | + * Gets all references to play.mvc.HTTP.RequestHeader `getQueryString` method |
| 144 | + */ |
| 145 | + MethodAccess getQueryString() { this.hasName("getQueryString") and result = this.getAReference() } |
| 146 | +} |
| 147 | + |
| 148 | +/** |
| 149 | + * Play Framework mvc.Results Methods - `ok`, `status`, `redirect` |
| 150 | + * |
| 151 | + * Documentation: https://www.playframework.com/documentation/2.5.8/api/java/play/mvc/Results.html |
| 152 | + */ |
| 153 | +class PlayMVCResultsMethods extends Method { |
| 154 | + PlayMVCResultsMethods() { this.getDeclaringType() instanceof PlayMVCResultsClass } |
| 155 | + |
| 156 | + /** |
| 157 | + * Gets all references to play.mvc.Results `ok` method |
| 158 | + */ |
| 159 | + MethodAccess getAnOkAccess() { this.hasName("ok") and result = this.getAReference() } |
| 160 | + |
| 161 | + /** |
| 162 | + * Gets all references to play.mvc.Results `redirect` method |
| 163 | + */ |
| 164 | + MethodAccess getARedirectAccess() { this.hasName("redirect") and result = this.getAReference() } |
| 165 | +} |
0 commit comments