Skip to content

Rust: Add taint model for add on String - #20559

Merged
paldepind merged 2 commits into
github:mainfrom
paldepind:rust/string-add-ref
Oct 1, 2025
Merged

Rust: Add taint model for add on String#20559
paldepind merged 2 commits into
github:mainfrom
paldepind:rust/string-add-ref

Conversation

@paldepind

Copy link
Copy Markdown
Contributor

No description provided.

@github-actionsgithub-actionsBot added the Rust Pull requests that update Rust code label Sep 30, 2025
let s1 = source_slice(22);
let s2 = s1.to_string();
sink(s2); // $ MISSING: hasTaintFlow=22 - we are not currently able to resolve the `to_string` call above, which comes from `impl<T: fmt::Display + ?Sized> ToString for T`
sink(s2); // $ MISSING: hasTaintFlow=22

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The explanation here was outdated. We actually resolve the call now, but we can't model the method in a blanket implementation.

@paldepind
paldepind marked this pull request as ready for review September 30, 2025 13:37
@paldepind
paldepind requested a review from a team as a code ownerSeptember 30, 2025 13:37
CopilotAI review requested due to automatic review settings September 30, 2025 13:37

CopilotAI 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 adds a taint model for the add operation on String types in Rust. It enables taint tracking to flow through string concatenation operations where tainted data is added to strings.

  • Adds taint flow models for <alloc::string::String as core::ops::arith::Add>::add
  • Updates test expectations to reflect new taint tracking capabilities for string concatenation
  • Fixes previously missed taint flows in SQL injection and other security tests

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
rust/ql/lib/codeql/rust/frameworks/stdlib/lang-alloc.model.ymlAdds taint models for String::add operation
rust/ql/test/query-tests/security/CWE-825/AccessAfterLifetime.expectedUpdates test expectations with new taint model references
rust/ql/test/query-tests/security/CWE-312/CleartextStorageDatabase.expectedUpdates test expectations with additional taint flows detected
rust/ql/test/query-tests/security/CWE-312/CleartextLogging.expectedUpdates test expectations with new string concatenation taint flows
rust/ql/test/query-tests/security/CWE-089/sqlx.rsUpdates comments from "MISSING" to found alerts for SQL injection cases
rust/ql/test/query-tests/security/CWE-089/SqlInjection.expectedUpdates test expectations with many new SQL injection flows now detected
rust/ql/test/library-tests/dataflow/strings/main.rsUpdates comment to reflect fixed taint flow case
rust/ql/test/library-tests/dataflow/strings/inline-taint-flow.expectedUpdates test expectations with new taint flows through string concatenation

@paldepindpaldepind added the no-change-note-required This PR does not need a change note label Sep 30, 2025

@geoffw0geoffw0 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.

Looks good, great results in tests, waiting for DCA...

@paldepind

Copy link
Copy Markdown
ContributorAuthor

DCA looks fine to me. There's a ❌ for stage timings, but it doesn't look like an issue to me.

@paldepind
paldepind merged commit a359a24 into github:mainOct 1, 2025
19 of 20 checks passed
@paldepind
paldepind deleted the rust/string-add-ref branch October 1, 2025 07:38
Comment on lines +49 to +50
- ["<alloc::string::String as core::ops::arith::Add>::add", "Argument[self]", "ReturnValue", "taint", "manual"]
- ["<alloc::string::String as core::ops::arith::Add>::add", "Argument[0].Reference", "ReturnValue", "taint", "manual"]

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.

Should we instead lift this to <_ as core::ops::arith::Add>::add?

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.

If we do this as follow-up, we can include other similar traits (e.g. Sub) as well.

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.

I've created an issue for this.

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

Labels

no-change-note-requiredThis PR does not need a change noteRustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@paldepind@hvitved@geoffw0