Skip to content

Commit 8ea4f85

Browse files
committed
Ruby: Rework Sinatra.FilterJumpStep
1 parent 95c764e commit 8ea4f85

File tree

3 files changed

+85
-52
lines changed

3 files changed

+85
-52
lines changed

ruby/ql/lib/codeql/ruby/frameworks/Sinatra.qll

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,23 @@ module Sinatra {
279279
filter.getApp() = route.getApp() and
280280
// the filter applies to all routes
281281
not filter.hasPattern() and
282-
blockPostUpdate(pred, filter.getBody()) and
283-
blockSelfParameterNode(succ, route.getBody().asExpr().getExpr())
282+
blockPostSelf(pred, filter.getBody()) and
283+
blockSelf(succ, route.getBody().asExpr().getExpr())
284284
)
285285
}
286286
}
287287

288-
/** Holds if `n` is a post-update node for the block `b`. */
289-
private predicate blockPostUpdate(DataFlow::PostUpdateNode n, DataFlow::BlockNode b) {
290-
n.getPreUpdateNode() = b
288+
/** Holds if `n` is a post-update node referencing `self` in the block `b`. */
289+
private predicate blockPostSelf(DataFlow::PostUpdateNode n, DataFlow::BlockNode b) {
290+
exists(SelfVariableAccessCfgNode self |
291+
n.getPreUpdateNode().asExpr() = self and
292+
self.getScope() = b.asExpr().getAstNode()
293+
)
291294
}
292295

293-
/** Holds if `n` is a `self` parameter belonging to block `b`. */
294-
private predicate blockSelfParameterNode(DataFlowPrivate::LambdaSelfReferenceNode n, Block b) {
295-
n.getCallable() = b
296+
/** Holds if `n` is a node referencing `self` in the block `b`. */
297+
private predicate blockSelf(DataFlow::VariableAccessNode self, Block b) {
298+
self.getExprNode().getBasicBlock().getScope() = b and
299+
self.asVariableAccessAstNode().getVariable() instanceof SelfVariable
296300
}
297301
}

ruby/ql/test/library-tests/frameworks/sinatra/Flow.expected

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ edges
88
| app.rb:76:32:76:35 | @foo | app.rb:76:25:76:36 | call to [] [element :foo] | provenance | |
99
| app.rb:76:32:76:35 | self [@foo] | app.rb:76:32:76:35 | @foo | provenance | |
1010
| app.rb:95:10:95:14 | self [@user] | app.rb:95:10:95:14 | @user | provenance | |
11-
| app.rb:102:10:104:5 | [post] do ... end [captured self, @user] | app.rb:95:10:95:14 | self [@user] | provenance | |
12-
| app.rb:103:5:103:9 | [post] self [@user] | app.rb:102:10:104:5 | [post] do ... end [captured self, @user] | provenance | |
13-
| app.rb:103:5:103:9 | [post] self [@user] | app.rb:102:10:104:5 | [post] do ... end [captured self, @user] | provenance | heuristic-callback |
11+
| app.rb:103:5:103:9 | [post] self [@user] | app.rb:95:10:95:14 | self [@user] | provenance | |
1412
| app.rb:103:13:103:22 | call to source | app.rb:103:5:103:9 | [post] self [@user] | provenance | |
1513
nodes
1614
| app.rb:75:5:75:8 | [post] self [@foo] | semmle.label | [post] self [@foo] |
@@ -21,7 +19,6 @@ nodes
2119
| app.rb:76:32:76:35 | self [@foo] | semmle.label | self [@foo] |
2220
| app.rb:95:10:95:14 | @user | semmle.label | @user |
2321
| app.rb:95:10:95:14 | self [@user] | semmle.label | self [@user] |
24-
| app.rb:102:10:104:5 | [post] do ... end [captured self, @user] | semmle.label | [post] do ... end [captured self, @user] |
2522
| app.rb:103:5:103:9 | [post] self [@user] | semmle.label | [post] self [@user] |
2623
| app.rb:103:13:103:22 | call to source | semmle.label | call to source |
2724
| views/index.erb:2:10:2:12 | call to foo | semmle.label | call to foo |

ruby/ql/test/library-tests/frameworks/sinatra/Sinatra.expected

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,75 @@ filterPatterns
4343
| app.rb:106:3:108:5 | call to before | app.rb:106:10:106:23 | "/protected/*" |
4444
| app.rb:111:3:113:5 | call to after | app.rb:111:9:111:23 | "/create/:slug" |
4545
additionalFlowSteps
46-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:2:22:4:5 | lambda self in do ... end |
47-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:6:24:8:5 | lambda self in do ... end |
48-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:10:21:13:5 | lambda self in do ... end |
49-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:15:23:18:5 | lambda self in do ... end |
50-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:20:23:22:5 | lambda self in do ... end |
51-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:24:26:26:5 | lambda self in do ... end |
52-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:28:26:31:5 | lambda self in do ... end |
53-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:33:25:35:5 | lambda self in do ... end |
54-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:37:16:42:5 | lambda self in do ... end |
55-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:44:53:46:5 | lambda self in do ... end |
56-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:48:14:50:5 | lambda self in do ... end |
57-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:52:37:54:5 | lambda self in do ... end |
58-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:56:32:58:5 | lambda self in do ... end |
59-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:60:48:62:5 | lambda self in do ... end |
60-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:66:41:68:5 | lambda self in do ... end |
61-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:70:20:72:5 | lambda self in do ... end |
62-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:74:11:77:5 | lambda self in do ... end |
63-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:79:11:82:5 | lambda self in do ... end |
64-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:89:16:92:5 | lambda self in do ... end |
65-
| app.rb:84:10:87:5 | [post] do ... end | app.rb:94:15:96:5 | lambda self in do ... end |
66-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:2:22:4:5 | lambda self in do ... end |
67-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:6:24:8:5 | lambda self in do ... end |
68-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:10:21:13:5 | lambda self in do ... end |
69-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:15:23:18:5 | lambda self in do ... end |
70-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:20:23:22:5 | lambda self in do ... end |
71-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:24:26:26:5 | lambda self in do ... end |
72-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:28:26:31:5 | lambda self in do ... end |
73-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:33:25:35:5 | lambda self in do ... end |
74-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:37:16:42:5 | lambda self in do ... end |
75-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:44:53:46:5 | lambda self in do ... end |
76-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:48:14:50:5 | lambda self in do ... end |
77-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:52:37:54:5 | lambda self in do ... end |
78-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:56:32:58:5 | lambda self in do ... end |
79-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:60:48:62:5 | lambda self in do ... end |
80-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:66:41:68:5 | lambda self in do ... end |
81-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:70:20:72:5 | lambda self in do ... end |
82-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:74:11:77:5 | lambda self in do ... end |
83-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:79:11:82:5 | lambda self in do ... end |
84-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:89:16:92:5 | lambda self in do ... end |
85-
| app.rb:102:10:104:5 | [post] do ... end | app.rb:94:15:96:5 | lambda self in do ... end |
46+
| app.rb:85:5:85:9 | [post] self | app.rb:3:14:3:19 | self |
47+
| app.rb:85:5:85:9 | [post] self | app.rb:12:5:12:10 | self |
48+
| app.rb:85:5:85:9 | [post] self | app.rb:17:5:17:10 | self |
49+
| app.rb:85:5:85:9 | [post] self | app.rb:25:15:25:20 | self |
50+
| app.rb:85:5:85:9 | [post] self | app.rb:39:13:39:18 | self |
51+
| app.rb:85:5:85:9 | [post] self | app.rb:40:14:40:19 | self |
52+
| app.rb:85:5:85:9 | [post] self | app.rb:45:38:45:43 | self |
53+
| app.rb:85:5:85:9 | [post] self | app.rb:57:5:57:15 | self |
54+
| app.rb:85:5:85:9 | [post] self | app.rb:61:5:61:17 | self |
55+
| app.rb:85:5:85:9 | [post] self | app.rb:75:5:75:8 | self |
56+
| app.rb:85:5:85:9 | [post] self | app.rb:75:12:75:17 | self |
57+
| app.rb:85:5:85:9 | [post] self | app.rb:76:5:76:36 | self |
58+
| app.rb:85:5:85:9 | [post] self | app.rb:76:32:76:35 | self |
59+
| app.rb:85:5:85:9 | [post] self | app.rb:81:5:81:12 | self |
60+
| app.rb:85:5:85:9 | [post] self | app.rb:90:5:90:9 | self |
61+
| app.rb:85:5:85:9 | [post] self | app.rb:91:5:91:10 | self |
62+
| app.rb:85:5:85:9 | [post] self | app.rb:95:5:95:14 | self |
63+
| app.rb:85:5:85:9 | [post] self | app.rb:95:10:95:14 | self |
64+
| app.rb:86:5:86:11 | [post] self | app.rb:3:14:3:19 | self |
65+
| app.rb:86:5:86:11 | [post] self | app.rb:12:5:12:10 | self |
66+
| app.rb:86:5:86:11 | [post] self | app.rb:17:5:17:10 | self |
67+
| app.rb:86:5:86:11 | [post] self | app.rb:25:15:25:20 | self |
68+
| app.rb:86:5:86:11 | [post] self | app.rb:39:13:39:18 | self |
69+
| app.rb:86:5:86:11 | [post] self | app.rb:40:14:40:19 | self |
70+
| app.rb:86:5:86:11 | [post] self | app.rb:45:38:45:43 | self |
71+
| app.rb:86:5:86:11 | [post] self | app.rb:57:5:57:15 | self |
72+
| app.rb:86:5:86:11 | [post] self | app.rb:61:5:61:17 | self |
73+
| app.rb:86:5:86:11 | [post] self | app.rb:75:5:75:8 | self |
74+
| app.rb:86:5:86:11 | [post] self | app.rb:75:12:75:17 | self |
75+
| app.rb:86:5:86:11 | [post] self | app.rb:76:5:76:36 | self |
76+
| app.rb:86:5:86:11 | [post] self | app.rb:76:32:76:35 | self |
77+
| app.rb:86:5:86:11 | [post] self | app.rb:81:5:81:12 | self |
78+
| app.rb:86:5:86:11 | [post] self | app.rb:90:5:90:9 | self |
79+
| app.rb:86:5:86:11 | [post] self | app.rb:91:5:91:10 | self |
80+
| app.rb:86:5:86:11 | [post] self | app.rb:95:5:95:14 | self |
81+
| app.rb:86:5:86:11 | [post] self | app.rb:95:10:95:14 | self |
82+
| app.rb:103:5:103:9 | [post] self | app.rb:3:14:3:19 | self |
83+
| app.rb:103:5:103:9 | [post] self | app.rb:12:5:12:10 | self |
84+
| app.rb:103:5:103:9 | [post] self | app.rb:17:5:17:10 | self |
85+
| app.rb:103:5:103:9 | [post] self | app.rb:25:15:25:20 | self |
86+
| app.rb:103:5:103:9 | [post] self | app.rb:39:13:39:18 | self |
87+
| app.rb:103:5:103:9 | [post] self | app.rb:40:14:40:19 | self |
88+
| app.rb:103:5:103:9 | [post] self | app.rb:45:38:45:43 | self |
89+
| app.rb:103:5:103:9 | [post] self | app.rb:57:5:57:15 | self |
90+
| app.rb:103:5:103:9 | [post] self | app.rb:61:5:61:17 | self |
91+
| app.rb:103:5:103:9 | [post] self | app.rb:75:5:75:8 | self |
92+
| app.rb:103:5:103:9 | [post] self | app.rb:75:12:75:17 | self |
93+
| app.rb:103:5:103:9 | [post] self | app.rb:76:5:76:36 | self |
94+
| app.rb:103:5:103:9 | [post] self | app.rb:76:32:76:35 | self |
95+
| app.rb:103:5:103:9 | [post] self | app.rb:81:5:81:12 | self |
96+
| app.rb:103:5:103:9 | [post] self | app.rb:90:5:90:9 | self |
97+
| app.rb:103:5:103:9 | [post] self | app.rb:91:5:91:10 | self |
98+
| app.rb:103:5:103:9 | [post] self | app.rb:95:5:95:14 | self |
99+
| app.rb:103:5:103:9 | [post] self | app.rb:95:10:95:14 | self |
100+
| app.rb:103:13:103:22 | [post] self | app.rb:3:14:3:19 | self |
101+
| app.rb:103:13:103:22 | [post] self | app.rb:12:5:12:10 | self |
102+
| app.rb:103:13:103:22 | [post] self | app.rb:17:5:17:10 | self |
103+
| app.rb:103:13:103:22 | [post] self | app.rb:25:15:25:20 | self |
104+
| app.rb:103:13:103:22 | [post] self | app.rb:39:13:39:18 | self |
105+
| app.rb:103:13:103:22 | [post] self | app.rb:40:14:40:19 | self |
106+
| app.rb:103:13:103:22 | [post] self | app.rb:45:38:45:43 | self |
107+
| app.rb:103:13:103:22 | [post] self | app.rb:57:5:57:15 | self |
108+
| app.rb:103:13:103:22 | [post] self | app.rb:61:5:61:17 | self |
109+
| app.rb:103:13:103:22 | [post] self | app.rb:75:5:75:8 | self |
110+
| app.rb:103:13:103:22 | [post] self | app.rb:75:12:75:17 | self |
111+
| app.rb:103:13:103:22 | [post] self | app.rb:76:5:76:36 | self |
112+
| app.rb:103:13:103:22 | [post] self | app.rb:76:32:76:35 | self |
113+
| app.rb:103:13:103:22 | [post] self | app.rb:81:5:81:12 | self |
114+
| app.rb:103:13:103:22 | [post] self | app.rb:90:5:90:9 | self |
115+
| app.rb:103:13:103:22 | [post] self | app.rb:91:5:91:10 | self |
116+
| app.rb:103:13:103:22 | [post] self | app.rb:95:5:95:14 | self |
117+
| app.rb:103:13:103:22 | [post] self | app.rb:95:10:95:14 | self |

0 commit comments

Comments
 (0)