Skip to content

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

Draft
hvitved wants to merge 3 commits into
mainfrom
hvitved-add-source-sink-barrier-tests
Draft

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

Conversation

@hvitved

@hvitved hvitved 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
hvitved force-pushed the hvitved-add-source-sink-barrier-tests branch from 157403e to 3778964 Compare August 27, 2026 13:27
Comment thread rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll Fixed
Comment thread rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll Fixed
@hvitved
hvitved force-pushed the hvitved-add-source-sink-barrier-tests branch 3 times, most recently from 4305c61 to 42cbd6b Compare August 27, 2026 17:42
@hvitved
hvitved force-pushed the hvitved-add-source-sink-barrier-tests branch from 42cbd6b to 7a8ac86 Compare August 31, 2026 12:33
@hvitved
hvitved force-pushed the hvitved-add-source-sink-barrier-tests branch from 7a8ac86 to d94dc40 Compare August 31, 2026 15:52
@hvitved
hvitved force-pushed the hvitved-add-source-sink-barrier-tests branch from d94dc40 to 4a7a072 Compare August 31, 2026 17:52
@hvitved
hvitved requested a balanced review from Copilot August 31, 2026 18:03

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.

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)
Severity Finding
Medium severity rust/​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 severity rust/​ql/​test/​library-tests/​dataflow/​barrier/​main.rssanitize3 is not tested independently: s has already passed through the sanitize2 barrier, so…
Low severity rust/​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.
File Description
shared/​dataflow/​codeql/​dataflow/​internal/​FlowSummaryImpl.qll Adds exactness-aware endpoint selection.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​ModelsAsData.qll Resolves models through trait implementations.
rust/​ql/​lib/​codeql/​rust/​dataflow/​internal/​FlowSummaryImpl.qll Integrates inherited Rust models.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowSource.qll Marks explicit sources exact.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowSink.qll Marks explicit sinks exact.
rust/​ql/​lib/​codeql/​rust/​dataflow/​FlowBarrier.qll Marks explicit barriers and guards exact.
rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qll Adds call-target debugging support.
rust/​ql/​test/​library-tests/​dataflow/​models/​models.ext.yml Adds trait source and sink models.
rust/​ql/​test/​library-tests/​dataflow/​models/​main.rs Exercises modeled trait implementations.
rust/​ql/​test/​library-tests/​dataflow/​models/​external_file.rs Adds external trait implementations.
rust/​ql/​test/​library-tests/​dataflow/​models/​models.expected Updates generated model baseline.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​main.rs Adds trait barrier cases.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​external_file.rs Adds an external barrier trait.
rust/​ql/​test/​library-tests/​dataflow/​barrier/​inline-flow.ext.yml Defines trait barrier models.
rust/​ql/​test/​query-tests/​security/​CWE-798/​test_cipher.rs Enables newly detected expectations.
rust/​ql/​test/​query-tests/​security/​CWE-798/​HardcodedCryptographicValue.expected Updates generated query results.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​test.rs Enables trait-based hashing expectations.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​WeakSensitiveDataHashing.expected Updates generated hashing baseline.
rust/​ql/​test/​query-tests/​security/​CWE-327/​WeakSensitiveDataHashing/​CryptographicOperations.expected Updates generated operation baseline.
cpp/​ql/​lib/​semmle/​code/​cpp/​dataflow/​internal/​FlowSummaryImpl.qll Adapts C++ to the shared contract.
csharp/​ql/​lib/​semmle/​code/​csharp/​dataflow/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.
java/​ql/​lib/​semmle/​code/​java/​dataflow/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.
javascript/​ql/​lib/​semmle/​javascript/​dataflow/​internal/​FlowSummaryPrivate.qll Removes obsolete endpoint bases.
python/​ql/​lib/​semmle/​python/​dataflow/​new/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.
ruby/​ql/​lib/​codeql/​ruby/​dataflow/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.
swift/​ql/​lib/​codeql/​swift/​dataflow/​internal/​FlowSummaryImpl.qll Removes obsolete endpoint bases.

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

Comment on lines +189 to +193
f.implements(f0) and
isExact = false and
// making inherited models generated means that source code definitions and
// exact generated models take precedence
p = "hq-generated"
Comment on lines +63 to +67
let s = source(2);
<()>::sanitize2(s);
sink(s);
<()>::sanitize3(s);
sink(s);
Comment on lines 336 to +338
FlowBarrierGuardFromModel() {
barrierGuardModel(path, _, _, _, _, _) and
this.getCanonicalPath() = path
barrierGuardModel(path, _, _, _, orig, _) and
interpretPath(path, this, orig, p_, isExact_)
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# C++ DataFlow Library Go Java JS no-change-note-required This PR does not need a change note Python Ruby Rust Pull requests that update Rust code Swift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants