Skip to content

Commit 27c554c

Browse files
committed
feedback integration - Move all files to Play.qll, improvements to add methods to remotetainted method for play
1 parent 5d5b849 commit 27c554c

File tree

9 files changed

+166
-200
lines changed

9 files changed

+166
-200
lines changed

java/ql/src/semmle/code/java/dataflow/FlowSources.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import semmle.code.java.frameworks.android.WebView
1717
import semmle.code.java.frameworks.JaxWS
1818
import semmle.code.java.frameworks.javase.WebSocket
1919
import semmle.code.java.frameworks.android.Intent
20-
import semmle.code.java.frameworks.play.PlayController
21-
import semmle.code.java.frameworks.play.PlayHTTPRequestHeader
20+
import semmle.code.java.frameworks.play.Play
2221
import semmle.code.java.frameworks.spring.SpringWeb
2322
import semmle.code.java.frameworks.spring.SpringController
2423
import semmle.code.java.frameworks.spring.SpringWebClient
@@ -279,7 +278,7 @@ private class RemoteTaintedMethod extends Method {
279278
private class PlayRequestGetMethod extends Method {
280279
PlayRequestGetMethod() {
281280
this.getDeclaringType() instanceof PlayMVCHTTPRequestHeader and
282-
this.hasName(["header", "getHeader"])
281+
this.hasName(["queryString","getQueryString","header", "getHeader"])
283282
}
284283
}
285284

Lines changed: 164 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,165 @@
11
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+
}

java/ql/src/semmle/code/java/frameworks/play/PlayAddCSRFToken.qll

Lines changed: 0 additions & 12 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayAsyncResult.qll

Lines changed: 0 additions & 28 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayBodyParser.qll

Lines changed: 0 additions & 10 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayController.qll

Lines changed: 0 additions & 73 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayHTTPRequestHeader.qll

Lines changed: 0 additions & 25 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayMVCResult.qll

Lines changed: 0 additions & 8 deletions
This file was deleted.

java/ql/src/semmle/code/java/frameworks/play/PlayMVCResults.qll

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)