Skip to content

Rust: Fix FPs in rust/hard-coded-cryptographic-value#22053

Open
geoffw0 wants to merge 5 commits into
github:mainfrom
geoffw0:arith
Open

Rust: Fix FPs in rust/hard-coded-cryptographic-value#22053
geoffw0 wants to merge 5 commits into
github:mainfrom
geoffw0:arith

Conversation

@geoffw0

@geoffw0 geoffw0 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Addresses a common source of false positive results in rust/hard-coded-cryptographic-value where arithmetic involves constants but the result is not constant. For example:

nonce += 1; // this is acceptable
encryption_routine(..., nonce);

Copilot AI review requested due to automatic review settings June 25, 2026 11:28
@geoffw0 geoffw0 requested a review from a team as a code owner June 25, 2026 11:28
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label Jun 25, 2026

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.

Pull request overview

This PR adjusts the Rust rust/hard-coded-cryptographic-value query’s dataflow configuration to reduce false positives when hard-coded constants are combined with non-constant data via arithmetic/bitwise operations (and +/+=-style string concatenation), and updates the associated tests and change note.

Changes:

  • Add a new barrier for arithmetic/bitwise operations to stop “hard-coded” flow across these operations.
  • Update the CWE-798 Rust query test to ensure arithmetic-with-variable no longer triggers alerts and to cover string append scenarios.
  • Add a change note documenting the analysis behavior change.
Show a summary per file
File Description
rust/ql/test/query-tests/security/CWE-798/test_heuristic.rs Updates inline expectations to assert the FP fix and adds string append test cases.
rust/ql/test/query-tests/security/CWE-798/HardcodedCryptographicValue.expected Regenerates expected output reflecting the new barrier behavior/models.
rust/ql/src/change-notes/2026-06-25-hard-coded-cryptographic-value-arithmetic-barrier.md Adds a change note for the query behavior change.
rust/ql/lib/codeql/rust/security/HardcodedCryptographicValueExtensions.qll Introduces a new barrier node class for arithmetic/bitwise operations.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread rust/ql/lib/codeql/rust/security/HardcodedCryptographicValueExtensions.qll Outdated
Comment thread rust/ql/lib/codeql/rust/security/HardcodedCryptographicValueExtensions.qll Outdated
@geoffw0

geoffw0 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Change suggestions accepted. I will need to check the DCA run still.

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

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants