Skip to content

Commit 977ceb8

Browse files
committed
Ruby: rack - remove PotentialResponseNode#getAStatusCode
1 parent af1ca7f commit 977ceb8

File tree

3 files changed

+4
-30
lines changed

3 files changed

+4
-30
lines changed

ruby/ql/lib/codeql/ruby/frameworks/rack/internal/Response.qll

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,11 @@ private import App as A
1212

1313
/** Contains implementation details for modeling `Rack::Response`. */
1414
module Private {
15-
private DataFlow::LocalSourceNode trackInt(TypeTracker t, int i) {
16-
t.start() and
17-
result.getConstantValue().isInt(i)
18-
or
19-
exists(TypeTracker t2 | result = trackInt(t2, i).track(t2, t))
20-
}
21-
22-
private DataFlow::Node trackInt(int i) { trackInt(TypeTracker::end(), i).flowsTo(result) }
23-
2415
/** A `DataFlow::Node` that may be a rack response. This is detected heuristically, if something "looks like" a rack response syntactically then we consider it to be a potential response node. */
2516
class PotentialResponseNode extends DataFlow::ArrayLiteralNode {
2617
// [status, headers, body]
2718
PotentialResponseNode() { this.getNumberOfArguments() = 3 }
2819

29-
/**
30-
* Gets an HTTP status code that may be returned in this response.
31-
*/
32-
int getAStatusCode() { this.getElement(0) = trackInt(result) }
33-
3420
/** Gets the headers returned with this response. */
3521
DataFlow::Node getHeaders() { result = this.getElement(1) }
3622

@@ -87,8 +73,10 @@ module Public {
8773

8874
/** A `DataFlow::Node` returned from a rack request that has a redirect HTTP status code. */
8975
class RedirectResponse extends ResponseNode, Http::Server::HttpRedirectResponse::Range {
90-
RedirectResponse() { this.getAStatusCode() = [300, 301, 302, 303, 307, 308] }
76+
private DataFlow::Node redirectLocation;
77+
78+
RedirectResponse() { redirectLocation = getHeaderValue(this, "location") }
9179

92-
override DataFlow::Node getRedirectLocation() { result = getHeaderValue(this, "location") }
80+
override DataFlow::Node getRedirectLocation() { result = redirectLocation }
9381
}
9482
}

ruby/ql/test/library-tests/frameworks/rack/Rack.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ rackApps
44
| rack.rb:24:1:37:3 | Logger | rack.rb:30:12:30:14 | env |
55
| rack.rb:39:1:45:3 | Redirector | rack.rb:40:12:40:14 | env |
66
| rack.rb:59:1:75:3 | Baz | rack.rb:60:12:60:14 | env |
7-
rackResponseStatusCodes
8-
| rack.rb:8:5:8:38 | call to [] | 200 |
9-
| rack.rb:8:5:8:38 | call to [] | 500 |
10-
| rack.rb:20:5:20:27 | call to [] | <unknown> |
11-
| rack.rb:35:5:35:26 | call to [] | <unknown> |
12-
| rack.rb:43:5:43:45 | call to [] | 302 |
13-
| rack.rb:66:7:66:22 | call to [] | 200 |
14-
| rack.rb:73:5:73:21 | call to [] | 400 |
157
rackResponseContentTypes
168
| rack.rb:8:5:8:38 | call to [] | rack.rb:7:34:7:45 | "text/plain" |
179
| rack.rb:20:5:20:27 | call to [] | rack.rb:19:28:19:54 | call to mime_type |

ruby/ql/test/library-tests/frameworks/rack/Rack.ql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ query predicate rackApps(Rack::App::AppCandidate c, DataFlow::ParameterNode env)
66
env = c.getEnv()
77
}
88

9-
query predicate rackResponseStatusCodes(Rack::Response::ResponseNode resp, string status) {
10-
if exists(resp.getAStatusCode())
11-
then status = resp.getAStatusCode().toString()
12-
else status = "<unknown>"
13-
}
14-
159
query predicate rackResponseContentTypes(
1610
Rack::Response::ResponseNode resp, DataFlow::Node contentType
1711
) {

0 commit comments

Comments
 (0)