Skip to content

Commit 71670a4

Browse files
committed
Ruby: add RequestInputAccess#getKind predicate
1 parent dea53d8 commit 71670a4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

ruby/ql/lib/codeql/ruby/Concepts.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ module Http {
314314
* This is typically the name of the method that gives rise to this input.
315315
*/
316316
string getSourceType() { result = super.getSourceType() }
317+
318+
/**
319+
* Gets the kind of the accessed input,
320+
* Can be one of "parameter", "header", "body", "url", "cookie".
321+
*
322+
* Note that this predicate is functional.
323+
*/
324+
string getKind() { result = super.getKind() }
317325
}
318326

319327
/** Provides a class for modeling new HTTP request inputs. */
@@ -331,6 +339,14 @@ module Http {
331339
* This is typically the name of the method that gives rise to this input.
332340
*/
333341
abstract string getSourceType();
342+
343+
/**
344+
* Gets the kind of the accessed input,
345+
* Can be one of "parameter", "header", "body", "url", "cookie".
346+
*
347+
* Note that this predicate is functional.
348+
*/
349+
abstract string getKind();
334350
}
335351
}
336352

@@ -411,6 +427,8 @@ module Http {
411427
RoutedParameter() { this.getParameter() = handler.getARoutedParameter() }
412428

413429
override string getSourceType() { result = handler.getFramework() + " RoutedParameter" }
430+
431+
override string getKind() { result = "url" }
414432
}
415433

416434
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class ParamsSource extends Http::Server::RequestInputAccess::Range {
141141
ParamsSource() { this.asExpr().getExpr() instanceof Rails::ParamsCall }
142142

143143
override string getSourceType() { result = "ActionController::Metal#params" }
144+
145+
override string getKind() { result = "parameter" }
144146
}
145147

146148
/**
@@ -151,6 +153,8 @@ class CookiesSource extends Http::Server::RequestInputAccess::Range {
151153
CookiesSource() { this.asExpr().getExpr() instanceof Rails::CookiesCall }
152154

153155
override string getSourceType() { result = "ActionController::Metal#cookies" }
156+
157+
override string getKind() { result = "cookie" }
154158
}
155159

156160
/** A call to `cookies` from within a controller. */

ruby/ql/lib/codeql/ruby/security/SensitiveGetQueryCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module SensitiveGetQuery {
3333
RequestInputAccessSource() {
3434
handler = this.asExpr().getExpr().getEnclosingMethod() and
3535
handler.getAnHttpMethod() = "get" and
36-
this.getSourceType().matches(["%params%", "%parameters%"])
36+
this.getKind() = "parameter"
3737
}
3838

3939
override Http::Server::RequestHandler getHandler() { result = handler }

0 commit comments

Comments
 (0)