Skip to content

Ruby: model Grape request sub-accessors as remote flow sources - #22586

Open
felickz wants to merge 4 commits into
github:mainfrom
forks-felickz:grape-request-accessors
Open

felickz wants to merge 4 commits into
github:mainfrom
forks-felickz:grape-request-accessors

Conversation

@felickz

@felickz felickz commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #20427 (Grape framework support). Models the request object's common sub-accessors within a Grape::API endpoint as remote flow sources, so taint tracking recognizes them the same way it already recognizes params, headers, cookies, and bare request.

Grape's request is a Rack::Request-like object; the following accessors are now modeled as sources:

  • request.body.read / request.body.string
  • request.params
  • request.GET / request.POST
  • request.cookies
  • request.env
  • request.query_string
  • request.path_info

Testing

  • ruby/ql/test/library-tests/frameworks/grape: extended app.rb with a RequestAccessorsAPI class covering all 9 accessors, with matching Grape.ql query predicates and inline # $ hasTaintFlow expectations in Flow.ql.
  • ruby/ql/test/query-tests/security/cwe-089: added ConnectedToInjection.rb, a regression fixture for ActiveRecord's connected_to role-switch block pattern (block-captured remote input interpolated into raw SQL, including a deferred/post-block variant), with inline # $ Source / # $ Alert annotations matching the sibling fixtures' convention.

All three tests pass (Flow.ql, Grape.ql, SqlInjection.qlref).

Change note

Added ruby/ql/lib/change-notes/2026-09-15-grape-request-sources.md (category feature).

Adds request.body.read/.string, .params, .GET, .POST, .cookies, .env,
.query_string, and .path_info as Http::Server::RequestInputAccess sources
within Grape::API endpoints, plus matching Grape.ql test predicates and
app.rb coverage. Also adds ConnectedToInjection.rb, exercising
ActiveRecord connected_to role-switch blocks with captured variables
as an SQL injection regression fixture.

.expected files intentionally not yet updated pending a CodeQL CLI
upgrade/test pass.
…089 tests

Adds # $ Source / # $ Alert annotations to ConnectedToInjection.rb matching
the sibling fixtures' convention. Regenerated Grape.expected/Flow.expected
and SqlInjection.expected from verified actual output (codeql test run,
CLI 2.27.0). All 3 tests pass: Flow.ql, Grape.ql, SqlInjection.qlref.
Comment thread ruby/ql/test/library-tests/frameworks/grape/Grape.ql Fixed
Comment thread ruby/ql/test/library-tests/frameworks/grape/Grape.ql Fixed
grapeRequestGET/grapeRequestPOST -> grapeRequestGet/grapeRequestPost,
per CodeQL code-scanning naming-convention review comments on the PR.
@felickz
felickz marked this pull request as ready for review September 16, 2026 02:01
@felickz
felickz requested a review from a team as a code owner September 16, 2026 02:01
Copilot AI balanced review requested due to automatic review settings September 16, 2026 02:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Three moderate source-modeling issues remain in Grape.qll.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite (auto)
Findings: 2 Medium severity

Note

Copilot is running an experiment and ran this review at Lite.

Open (2)
What changed in this PR

Extends Ruby Grape request modeling with remote-flow sources and adds regression coverage.

Changes:

  • Models nine request sub-accessors as sources.
  • Expands Grape and SQL-injection tests.
  • Adds generated expectations and a feature change note.
File Description
ruby/​ql/​test/​query-tests/​security/​cwe-089/​SqlInjection.expected Updates SQL-injection expectations.
ruby/​ql/​test/​query-tests/​security/​cwe-089/​ConnectedToInjection.rb Adds connected_to SQL-injection regression cases.
ruby/​ql/​test/​library-tests/​frameworks/​grape/​Grape.ql Queries the new source types.
ruby/​ql/​test/​library-tests/​frameworks/​grape/​Grape.expected Records Grape test results.
ruby/​ql/​test/​library-tests/​frameworks/​grape/​Flow.expected Records flow-test results.
ruby/​ql/​test/​library-tests/​frameworks/​grape/​app.rb Adds request accessor flow cases.
ruby/​ql/​lib/​codeql/​ruby/​frameworks/​Grape.qll Adds Grape request sub-accessor source models.
ruby/​ql/​lib/​change-notes/​2026-09-15-grape-request-sources.md Documents the feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +226 to +228
override Http::Server::RequestInputKind getKind() {
result = Http::Server::parameterInputKind()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like Copilot is right here. I would also expect bodyInputKind on line 291 and cookieInputKind on line 305.

override string getSourceType() { result = "Grape::Request#path_info" }

override Http::Server::RequestInputKind getKind() {
result = Http::Server::parameterInputKind()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants