Skip to content

Commit 9eff493

Browse files
committed
Ruby: Restrict request methods to user-controlled
1 parent ad464ab commit 9eff493

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ private module Request {
203203

204204
/** A method call on `request` which returns part or all of the request path. */
205205
private class PathCall extends RequestInputAccess {
206-
PathCall() {
207-
this.getMethodName() =
208-
["fullpath", "original_fullpath", "original_url", "url", "path", "filtered_path"]
209-
}
206+
PathCall() { this.getMethodName() = ["path", "filtered_path"] }
210207
}
211208

212209
/** A method call on `request` which returns a specific request header. */
@@ -216,8 +213,13 @@ private module Request {
216213
[
217214
"authorization", "script_name", "path_info", "user_agent", "referer", "referrer",
218215
"host_authority", "content_type", "host", "hostname", "accept_encoding",
219-
"accept_language", "if_none_match", "if_none_match_etags", "get_header", "fetch_header"
216+
"accept_language", "if_none_match", "if_none_match_etags"
220217
]
218+
or
219+
// Request headers are prefixed with `HTTP_` to distinguish them from
220+
// "headers" supplied by Rack middleware.
221+
this.getMethodName() = ["get_header", "fetch_header"] and
222+
this.getArgument(0).asExpr().getExpr().getConstantValue().getString().regexpMatch("^HTTP_.+")
221223
}
222224
}
223225

@@ -254,7 +256,10 @@ private module Request {
254256

255257
/** A method call on `request` which returns the rack env. */
256258
private class EnvCall extends RequestInputAccess {
257-
EnvCall() { this.getMethodName() = ["env", "filtered_env"] }
259+
EnvCall() {
260+
this.getMethodName() = ["env", "filtered_env"] and
261+
this.getArgument(0).asExpr().getExpr().getConstantValue().getString().regexpMatch("^HTTP_.+")
262+
}
258263
}
259264
}
260265

0 commit comments

Comments
 (0)