Skip to content

Rust: Fixes to flow through captured variables - #22917

Draft
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:rust/captured-flow-fixes
Draft

hvitved wants to merge 3 commits into
github:mainfrom
hvitved:rust/captured-flow-fixes

Conversation

@hvitved

@hvitved hvitved commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes various data flow issues uncovered by this report:

  1. Captured variables introduced by parameters will only have incoming flow from the parameter when it is a simple non-destructuring parameter.
  2. Captured variables will take all writes into account, for example also variables that are introduced in a destructuring pattern.
  3. Parenthesized patterns will now have flow into the sub pattern.
  4. Parenthesized expressions will now hav flow into the sub expression when it appears in an assignment context.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Oct 28, 2026
@hvitved
hvitved force-pushed the rust/captured-flow-fixes branch from 8da4e2d to 5040b9f Compare October 28, 2026 14:34
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 28, 2026
@hvitved
hvitved marked this pull request as ready for review October 28, 2026 18:16
Copilot AI max review requested due to automatic review settings October 28, 2026 18:16
@hvitved
hvitved requested a review from a team as a code owner October 28, 2026 18:16
@hvitved
hvitved requested a review from paldepind October 28, 2026 18:16

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.

🟡 Changes recommended

Unresolved capture-flow regressions can suppress alerts for parenthesized parameters and self-dependent assignments, while the committed sink baseline contains failed expectations and required regression coverage remains incomplete.

4 open issues
What changed in this PR

This PR refines Rust’s captured-variable data flow to address the Axum State false positive reported in #22912 and account for writes introduced by destructuring patterns.

Changes:

  • Distinguishes direct parameters from bindings introduced by destructuring.
  • Uses binding and assignment-access nodes to model captured-variable writes.
  • Adds Axum closure-capture regression cases and updates dependencies and flow expectations.
File Description
rust/​ql/​test/​query-tests/​security/​CWE-022/​TaintedPathSinks.expected Records sink-expectation output for the new cases.
rust/​ql/​test/​query-tests/​security/​CWE-022/​TaintedPath.expected Updates alert and flow-path expectations.
rust/​ql/​test/​query-tests/​security/​CWE-022/​src/​main.rs Adds State and Json closure-capture regression cases.
rust/​ql/​test/​query-tests/​security/​CWE-022/​options.yml Adds the Axum test dependency.
rust/​ql/​test/​query-tests/​security/​CWE-022/​Cargo.lock Locks Axum and related test dependencies.
rust/​ql/​test/​library-tests/​dataflow/​models/​models.expected Updates captured-variable provenance paths.
rust/​ql/​test/​library-tests/​dataflow/​local/​DataFlowStep.expected Updates local-flow write-node expectations.
rust/​ql/​test/​library-tests/​dataflow/​lambdas/​inline-flow.expected Updates closure and async capture-flow paths.
rust/​ql/​lib/​codeql/​rust/​internal/​typeinference/​TypeInference.qll Uses the direct-parameter check for self definitions.
rust/​ql/​lib/​codeql/​rust/​elements/​internal/​VariableImpl.qll Adds a direct-parameter predicate and clarifies binding documentation.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​DataFlowImpl.qll Revises captured-parameter handling and write-node mapping.

Review effort: Max

Comment thread rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll
Comment thread rust/ql/test/query-tests/security/CWE-022/TaintedPathSinks.expected Outdated
Comment thread rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated
Comment thread rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll
@hvitved
hvitved marked this pull request as draft October 29, 2026 07:42
@hvitved
hvitved force-pushed the rust/captured-flow-fixes branch from 5040b9f to 2b8d678 Compare October 29, 2026 10:22
@hvitved
hvitved requested a max review from Copilot October 29, 2026 10:25

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.

🟡 Changes recommended

Data-flow regressions lose source-to-sink paths through closures for dereferenced reference bindings and parenthesized assignments.

2 open issues
4 resolved since last review

Review effort: Max

Comment thread rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated
Comment thread rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll
@hvitved
hvitved force-pushed the rust/captured-flow-fixes branch from 2b8d678 to 6afe533 Compare October 29, 2026 12:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants