Skip to content

Rust: Source/sink/barrier MaD trait models apply to implementations - #22445

Merged
hvitved merged 3 commits into
mainfrom
hvitved-add-source-sink-barrier-tests
Sep 1, 2026
Merged

Rust: Source/sink/barrier MaD trait models apply to implementations#22445
hvitved merged 3 commits into
mainfrom
hvitved-add-source-sink-barrier-tests

Conversation

@hvitved

@hvitvedhvitved commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR applies the same inheritance logic to source/sink/barrier MaD models for trait functions as for summary models, that is, a model for <Foo>::bar applies to any function implementing the trait function foo, unless an explicit model exists for that particular implementation.

In order to ensure that the same prioritization rules apply as for summary models, this logic is defined in the shared library, but currently only Rust and C++ make use of it.

The updated test output shows that we fix some existing FNs, and DCA shows that we both remove some alerts (presumably because we now have more barriers) and we gain some alerts (presumably because we now have more sources and sinks).

@hvitved
hvitvedforce-pushed the hvitved-add-source-sink-barrier-tests branch from 157403e to 3778964CompareAugust 27, 2026 13:27
Comment threadrust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll Fixed
Comment threadrust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll Fixed
@hvitved
hvitvedforce-pushed the hvitved-add-source-sink-barrier-tests branch 3 times, most recently from 4305c61 to 42cbd6bCompareAugust 27, 2026 17:42
@hvitved
hvitvedforce-pushed the hvitved-add-source-sink-barrier-tests branch 3 times, most recently from d94dc40 to 4a7a072CompareAugust 31, 2026 17:52
@hvitved
hvitved requested a balanced review from CopilotAugust 31, 2026 18:03

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.

Copilot review overview

🟡 Changes recommended

Concrete trait targets can produce duplicate endpoint models, and barrier coverage does not independently exercise all new paths.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity · 2 Low severity

New issues introduced by this change (3)
SeverityFinding
Medium severityrust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​ModelsAsData.qll — The inherited endpoint fallback is also applied to concrete &lt;Type as Trait&gt;::method functions.…
Low severityrust/​ql/​test/​library-tests/​dataflow/​barrier/​main.rssanitize3 is not tested independently: s has already passed through the sanitize2 barrier, so…
Low severityrust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​ModelsAsData.qll — The new barrierGuardModel inheritance path has no corresponding trait-implementation test, while…
What changed in this PR

Extends Rust MaD source, sink, and barrier models to trait implementations, aligning them with summary-model inheritance.

Changes:

  • Adds exactness-aware endpoint model selection and Rust trait resolution.
  • Updates shared and language-specific dataflow adapters.
  • Expands Rust cryptography and dataflow tests.
FileDescription
shared/​dataflow/​codeql/​dataflow/​internal/​FlowSummaryImpl.qllAdds exactness-aware endpoint selection.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​ModelsAsData.qllResolves models through trait implementations.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​FlowSummaryImpl.qllIntegrates inherited Rust models.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowSource.qllMarks explicit sources exact.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowSink.qllMarks explicit sinks exact.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowBarrier.qllMarks explicit barriers and guards exact.
rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qllAdds call-target debugging support.
rust/​ql/​test/​library-tests/​dataflow/​models/​models.ext.ymlAdds trait source and sink models.
rust/​ql/​test/​library-tests/​dataflow/​models/​main.rsExercises modeled trait implementations.
rust/​ql/​test/​library-tests/​dataflow/​models/​external_file.rsAdds external trait implementations.
rust/​ql/​test/​library-tests/​dataflow/​models/​models.expectedUpdates generated model baseline.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​main.rsAdds trait barrier cases.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​external_file.rsAdds an external barrier trait.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​inline-flow.ext.ymlDefines trait barrier models.
rust/​ql/​test/​query-tests/​security/​CWE-798/​test_cipher.rsEnables newly detected expectations.
rust/​ql/​test/​query-tests/​security/​CWE-798/​HardcodedCryptographicValue.expectedUpdates generated query results.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​test.rsEnables trait-based hashing expectations.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​WeakSensitiveDataHashing.expectedUpdates generated hashing baseline.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​CryptographicOperations.expectedUpdates generated operation baseline.
cpp/​ql/​lib/​semmle/​code/​cpp/​dataflow/​internal/​FlowSummaryImpl.qllAdapts C++ to the shared contract.
csharp/​ql/​lib/​semmle/​code/​csharp/​dataflow/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.
java/​ql/​lib/​semmle/​code/​java/​dataflow/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.
javascript/​ql/​lib/​semmle/​javascript/​dataflow/​internal/​FlowSummaryPrivate.qllRemoves obsolete endpoint bases.
python/​ql/​lib/​semmle/​python/​dataflow/​new/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.
ruby/​ql/​lib/​codeql/​ruby/​dataflow/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.
swift/​ql/​lib/​codeql/​swift/​dataflow/​internal/​FlowSummaryImpl.qllRemoves obsolete endpoint bases.

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

Comment threadrust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll
Comment threadrust/ql/test/library-tests/dataflow/barrier/main.rs
Comment threadrust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll
@hvitvedhvitved added the no-change-note-required This PR does not need a change note label Aug 31, 2026
@hvitved
hvitvedforce-pushed the hvitved-add-source-sink-barrier-tests branch from 4a7a072 to 2d69fc3CompareSeptember 1, 2026 08:06
@hvitved
hvitved marked this pull request as ready for review September 1, 2026 11:35
@hvitved
hvitved requested review from a team as code ownersSeptember 1, 2026 11:35
@hvitved
hvitved requested review from a team as code ownersSeptember 1, 2026 11:35

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

LGTM

@hvitved
hvitved merged commit b0fa3e7 into mainSep 1, 2026
126 checks passed
@hvitved
hvitved deleted the hvitved-add-source-sink-barrier-tests branch September 1, 2026 14:02
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C#C++DataFlow LibraryGoJavaJSno-change-note-requiredThis PR does not need a change notePythonRubyRustPull requests that update Rust codeSwift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@hvitved@paldepind@github-advanced-security