Skip to content

Unified: flow summaries - #22809

Draft
asgerf wants to merge 24 commits into
github:mainfrom
asgerf:unified/flow-summaries
Draft

asgerf wants to merge 24 commits into
github:mainfrom
asgerf:unified/flow-summaries

Conversation

@asgerf

@asgerf asgerf commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for flow summaries, that is, MaD entries in legacySummaryModel that describe flow through a function.

'Inout' parameters

This PR includes support for summaries that involve an inout parameter, such as the swap model which adds Argument[0] -> Argument[1] flow. We use argument's post-update node to propagate the new value.

Support for user-written inout parameters is not part of this PR, nor do we insert (uncertain) writes in SSA, which is needed for some non-dataflow use-cases for SSA. I expect another PR to flesh out support for inout parameters in the future.

Call site 'inout' indicator

At a call site, argument to an inout parameter must be prefixed by &, e.g:

swap(&x, &y)

However, when calling an operator with inout parameters, there is no syntactic indicator at the call site that an operand is an inout operand. Some languages like PHP are lacking such syntactic indicators in general. So we shouldn't rely on its presence too much.

The & is currently represented by a UnaryExpr which meant the x and y expressions did not get a post-update node, as they did not appear directly as arguments to the call. A similar issue exists with type casts and the postfix ! operator, so I decided to give the language plugin a hook that makes it possible to add post-update flow through unary operators.

An alternative would have been to change the extractor to roll the & into a modifier on the Argument node, which would have been slightly nicer, but then the issue would persist for type casts and postfix !.

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

Unresolved summary-decoding and node-consistency issues can prevent modeled flows from being analyzed correctly.

4 open issues
What changed in this PR

Adds model-driven flow summaries to Unified data flow, enabling existing Swift library models to propagate values and taint.

Changes:

  • Integrates summarized callables, callbacks, and access paths.
  • Adds Swift must-flow and post-update handling.
  • Adds summary tests and debugging support, and updates alert expectations.
File Description
unified/​ql/​test/​query-tests/​security/​CWE-022/​PathInjection/​testPathInjection.swift Updates inline alert expectations.
unified/​ql/​test/​query-tests/​security/​CWE-022/​PathInjection/​PathInjectionTest.expected Updates expected path-injection results.
unified/​ql/​test/​library-tests/​dataflow/​test.swift Marks optional tuple flow as detected.
unified/​ql/​test/​library-tests/​dataflow/​test.ext.yml Defines test summary models.
unified/​ql/​test/​library-tests/​dataflow/​test.expected Updates expected flow graphs and results.
unified/​ql/​test/​library-tests/​dataflow/​flow-summaries.swift Adds summary propagation fixtures.
unified/​ql/​lib/​codeql/​unified/​internal/​mad/​LegacyMaD.qll Exposes selectors and normalizes summaries.
unified/​ql/​lib/​codeql/​unified/​internal/​dev/​debugSummarizedCallable.ql Adds summary graph debugging.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​TaintTrackingInstantiation.qll Includes summary taint steps.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​ParameterPositions.qll Exposes model operand encoding.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​FlowSummaries.qll Instantiates shared summary machinery.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowPluginSwift.qll Models inout and unwrap must-flow.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowPlugin.qll Adds a language-specific must-flow hook.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowNode.qll Adds summary nodes and post-update propagation.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowInstantiation.qll Integrates summary nodes and flow steps.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowCallable.qll Represents summarized callables.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowCall.qll Represents synthesized callback calls.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​Content.qll Includes model-defined named contents.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​CallGraph.qll Resolves calls to summary models.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​AllDataFlow.qll Imports the summary implementation.
unified/​ql/​consistency-queries/​DataFlowConsistency.ql Adjusts consistency checks for summary post-updates.

Review effort: Max

Comment thread unified/ql/lib/codeql/unified/internal/dataflow/FlowSummaries.qll
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/Content.qll
TLocalSsaNode(LocalSsaDataFlowOutput::SsaNode node) or
TCaptureSsaNode(CaptureSsaOutput::SynthesizedCaptureNode node)
TCaptureSsaNode(CaptureSsaOutput::SynthesizedCaptureNode node) or
TSummaryNode(FlowSummaryOutput::SummaryNode node)
// Adapters for the old Swift MaD models
token = "OptionalSome" and result = ContentSet::namedMember("some.0")
or
token = "CollectionElement" and result = ContentSet::arrayElement()
@asgerf
asgerf force-pushed the unified/flow-summaries branch from 74885e3 to 14602be Compare October 19, 2026 12:29

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants