Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

C++: Replace QL models for std::map (and friends) with MaD models - #22939

Open
MathiasVP wants to merge 32 commits into
github:mainfrom
MathiasVP:replace-ql-models-with-mad-for-assoc-cleaned-up
Open

MathiasVP wants to merge 32 commits into
github:mainfrom
MathiasVP:replace-ql-models-with-mad-for-assoc-cleaned-up

Conversation

@MathiasVP

@MathiasVP MathiasVP commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds MaD summaries for std::map, std::unordered_map, std::string, std::pair, and std::string_view.

Commit-by-commit review strongly recommended!

This work brings together a bunch of PRs that has been merged over the last couple of weeks/months(/years):

There are a lot of moving parts here. Here are the highlights:

  • It turns out there were a lot of type issues in our std container tests. These were not a problem with the old models, but they cause missing forward-related flow (since we use the argument/parameter types to identify the right constructor to forward to).
  • The forwarding MaD syntax didn't handle nested typedefs, which meant it was impossible to refer to specify that std::map::emplace constructed a value of type std::map<Key, Value>::value_type.
  • In order to forward arguments to a specific constructor that constructor has to exist in the database. So the tests had to be rewritten slightly to ensure that the right templates were instantiated so that the constructors existed. This won't be a problem in a real database since those constructors are invoked by the std container implementations, so they obviously exist in the database.
  • After adding all the forwarding models the forwarding logic turned out to have some performance problems.
  • Correctly tracking the values in cpp/cleartext-storage-file revealed two problems in that query (and the other CWE-311 query):
    • The barriers were too strong. They blocked flow to chars which meant that a copying loop iterating over each char in a std::string would be blocked.
    • The queries always used asExpr which meant that we tracked the reference when the sensitive variable was a reference, and otherwise we tracked the value.
  • Being more precise about taint into containers also revealed a problem with how we picked which node for which asExpr and asIndirectExpr should have a result when the expression is a glvalue. I've added a rather long explanation for why the new behavior is what we want.
  • Adding more STL stubs made the extractor (with --check-databases) unhappy about duplicated declarations breaking ODR. So I also refactored those tests at the very end.

DCA is rather uneventful. A couple of new results:

  • The SAMATE ones are new TPs
  • The new cpp/return-c-str-of-std-string result is a false positive which comes from the existing query logic.
  • The 5 lost cpp/non-constant-format result are FPs which are now removed. The sources in those query results are all allocations of internal STL buffers which we now exclude from dataflow since we have precise MaD models of the enclosing functions.
  • The lost results in the Diffed query result tuple counts table are all from results now being deduplicated better:
    • The cpp/command-line-injection ones are similar to what we've seen in our query tests
    • The cpp/tainted-format-string ones are because we now track indirection flow properly through std::map. For example we'd previously get a result for both data and *data here because we conflated the pointer and the pointee when we insert into (and pull out) the std::map, and now we only get a result for *data as expected.

… using 'char*' instead of 'const char*' which meant it would not type check when attempting to use string literals as keys (if we had been using a real implementation of those containers).
This commit should be read with `?w=1`.
…nce it in models.

Ideally, we should have a synthetic fields in dataflow for this instead. But this PR is large enough as it is, and this won't be a problem in real code as the member will always exist.
…ing test with missing flow through 'SetQueryParameters'.
…ue in a map is stored in an EleentContent and a pair::second content we only need to add an implicit read of pair::second. We could consider adding an implicit read of pair::first for symmetry.
…pair's constructor which has always bothered me since we dont depend on the implementations of any models in any other tests.
…in the forward pruning phase before constructing the IPA type.
… all integral types, and one from incorrectly picking the non-indirect node for a glvalue expression.

While here, we also add MaD pretty-printing to this query as this will be relevant later.
…the underlying instruction is of type glvalue.
…e<->expr mapping didn't work for this case, but with the changes in this PR we can now just use asExpr. As a bonus, we now get proper result deduplication (which is handled by asExpr) which removes a duplicated result.
@MathiasVP MathiasVP added the C++ label Oct 29, 2026
Copilot AI auto review requested due to automatic review settings October 29, 2026 14:28

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 changes omit assignment-return and iterator-pointee taint flows and weaken the cleartext queries’ barriers for non-character integral values.

4 open issues
What changed in this PR

Migrates C++ container and string flow modeling from handwritten QL taint models to models-as-data, improving field and indirection precision.

Changes:

  • Adds associative-container, pair, and string-view summaries, and switches vector emplacement to constructor forwarding.
  • Supports member typedefs in forwarding models, optimizes constructor matching, and adjusts glvalue expression-node mapping.
  • Updates cleartext queries, Azure models, command-concatenation handling, and regression tests.
File Description
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-611/​XXE.expected Updated as part of this pull request.
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-311/​semmle/​tests/​test2.cpp Updated as part of this pull request.
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-311/​semmle/​tests/​CleartextFileWrite.qlref Updated as part of this pull request.
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-311/​semmle/​tests/​CleartextFileWrite.expected Updated as part of this pull request.
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-078/​semmle/​ExecTainted/​ExecTainted.expected Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​taint-tests/​string.cpp Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​taint-tests/​stl.h Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​fields/​ir-path-flow.expected Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​validatemodels.expected Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​test.cpp Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​sources.expected Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​sinks.expected Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​flow.ext.yml Updated as part of this pull request.
cpp/​ql/​test/​library-tests/​dataflow/​external-models/​azure.cpp Updated as part of this pull request.
cpp/​ql/​src/​Security/​CWE/​CWE-311/​CleartextTransmission.ql Updated as part of this pull request.
cpp/​ql/​src/​Security/​CWE/​CWE-311/​CleartextFileWrite.ql Updated as part of this pull request.
cpp/​ql/​src/​Security/​CWE/​CWE-311/​ClearText.qll Updated as part of this pull request.
cpp/​ql/​src/​Security/​CWE/​CWE-078/​ExecTainted.ql Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​models/​implementations/​StdString.qll Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​models/​implementations/​StdPair.qll Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​models/​implementations/​StdMap.qll Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​TaintTrackingUtil.qll Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​ExprNodes.qll Updated as part of this pull request.
cpp/​ql/​lib/​semmle/​code/​cpp/​dataflow/​ExternalFlow.qll Updated as part of this pull request.
cpp/​ql/​lib/​ext/​std.vector.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​std.unordered_map.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​std.string_view.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​std.pair.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​std.map.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​bsl.vector.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​bsl.unordered_map.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​bsl.pair.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​bsl.map.model.yml Updated as part of this pull request.
cpp/​ql/​lib/​ext/​azure.core.model.yml Updated as part of this pull request.

Review effort: Max (auto)

Comment thread cpp/ql/lib/ext/bsl.map.model.yml Resolved
Comment thread cpp/ql/lib/ext/std.map.model.yml Resolved

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants