Skip to content

Commit a1fab31

Browse files
committed
Ruby: Model Sinatra
Adds some very basic modeling of Sinatra applications. We recognise the `params` call in Sinatra routes as an HTTP request input access.
1 parent ab58d4c commit a1fab31

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** Provides modeling for the Sinatra library. */
2+
3+
private import codeql.ruby.controlflow.CfgNodes::ExprNodes
4+
private import codeql.ruby.DataFlow
5+
private import codeql.ruby.Concepts
6+
7+
/** Provides modeling for the Sinatra library. */
8+
module Sinatra {
9+
private class App extends DataFlow::ClassNode {
10+
App() { this = DataFlow::getConstant("Sinatra").getConstant("Base").getADescendentModule() }
11+
12+
Route getRoute() { result.getApp() = this }
13+
}
14+
15+
private class Route extends DataFlow::CallNode {
16+
private App app;
17+
18+
Route() {
19+
this =
20+
app.getAModuleLevelCall([
21+
"get", "post", "put", "patch", "delete", "options", "link", "unlink"
22+
])
23+
}
24+
25+
App getApp() { result = app }
26+
27+
DataFlow::BlockNode getBody() { result = this.getBlock() }
28+
}
29+
30+
private class Params extends DataFlow::CallNode, Http::Server::RequestInputAccess::Range {
31+
private Route route;
32+
33+
Params() {
34+
this.asExpr().getExpr().getEnclosingCallable() = route.getBody().asCallableAstNode() and
35+
this.getMethodName() = "params"
36+
}
37+
38+
override string getSourceType() { result = "Sinatra::Base#params" }
39+
40+
override Http::Server::RequestInputKind getKind() {
41+
result = Http::Server::parameterInputKind()
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)