Skip to content

Rust: Don't report cleartext logging in test functions - #23069

Open
johncarmack1984 wants to merge 2 commits into
github:mainfrom
johncarmack1984:rust-cleartext-logging-test-code
Open

johncarmack1984 wants to merge 2 commits into
github:mainfrom
johncarmack1984:rust-cleartext-logging-test-code

Conversation

@johncarmack1984

Copy link
Copy Markdown
Contributor

rust/cleartext-logging reports assert! and println! inside Rust tests, since panic messages and printed output are log sinks. All five of its open results in maplibre/martin are test assertions (tls.rs, source.rs), and inline tests don't get code scanning's test classification. This adds a barrier inside functions whose attribute path ends in test (#[test], #[tokio::test]), which only build into test binaries, so every removed result runs under a test.

The first commit adds the cases as SPURIOUS; the second adds the barrier and leaves CleartextLogging.expected identical to main.

@johncarmack1984
johncarmack1984 requested a review from a team as a code owner November 10, 2026 05:32
Copilot AI auto review requested due to automatic review settings November 10, 2026 05:32

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

The production cleartext-logging barrier changes reported paths, but missing DCA results and regression analysis leave its real-world impact unverified by the focused fixture alone.

1 open issue
What changed in this PR

This PR reduces false positives in rust/cleartext-logging by suppressing data flow within functions whose attribute path ends in test, including standard Rust and Tokio tests.

Changes:

  • Adds a test-function barrier, including expressions in nested closures.
  • Adds regression cases for printing and assertions in synchronous and asynchronous tests, plus the Tokio dependency.
  • Documents the analysis change in a release note.
File Description
rust/​ql/​test/​query-tests/​security/​CWE-312/​test_logging.rs Adds standard, closure, and async test cases.
rust/​ql/​test/​query-tests/​security/​CWE-312/​options.yml Adds Tokio for async test coverage.
rust/​ql/​test/​query-tests/​security/​CWE-312/​Cargo.lock Records Tokio and its dependencies.
rust/​ql/​src/​change-notes/​2026-11-10-cleartext-logging-test-functions.md Documents suppression of test-function results.
rust/​ql/​lib/​codeql/​rust/​security/​CleartextLoggingExtensions.qll Adds the test-function data-flow barrier.

Review effort: Balanced (auto)

* attribute. A test's assertion messages and output go to the test runner, not
* to an application's log.
*/
private class TestFunctionBarrier extends Barrier {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

DCA runs on the CodeQL team's side, so that one's for a maintainer to start. The only query whose results this changes is rust/cleartext-logging.

@github-actions github-actions Bot added documentation Rust Pull requests that update Rust code external-contribution labels Nov 10, 2026
@paldepind

Copy link
Copy Markdown
Contributor

Hello @johncarmack1984. Thanks for the PR and for making us aware of this. Recently we've considered removing all results inside tests by default. Given that, I'm not sure if this is the approach that makes the most sense. For now I'll leave this PR open until we make a decision on how to proceed.

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

documentation external-contribution Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants