Skip to content

Unified: Basic data flow and clear-text logging query - #22560

Merged
asgerf merged 30 commits into
github:mainfrom
asgerf:unified/dataflow2
Sep 15, 2026
Merged

asgerf merged 30 commits into
github:mainfrom
asgerf:unified/dataflow2

Conversation

@asgerf

@asgerf asgerf commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Adds the first basic version of data flow, with the following features:

  • Taint flow through string concatenation
  • SSA-based flow through local variables, including implicit self access
  • Flow through field access (name-based; fields with the same name can be conflated)
  • Flow through tuples, including tuple-destructuring

The PR also adds a basic version of the clear-text logging query, mainly for exercising data flow in DCA. This query was chosen because it is easily stubbed without elaborate library modelling and will tend to have sources and sinks in many projects. It is not expected to be precise at this point in time.

What is not included:

  • Inter-procedural flow (i.e. call graph, capture, argument/parameter positions etc)
  • Fixing issues related to the CFG and AST mappings. There is an issue with assignments captured by tests, but I'm deliberately not trying to fix it in this PR.
  • Attempts to make the clear-text logging query precise. That's not the focus right now.

Commit-by-commit review strongly recommended.

@asgerf asgerf added the no-change-note-required This PR does not need a change note label Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

QHelp previews:

unified/ql/src/queries/security/CWE-312/CleartextLogging.qhelp

Cleartext logging of sensitive information

Attackers could gain access to sensitive information that is logged unencrypted.

Recommendation

Always make sure to encrypt or obfuscate sensitive information before you log it.

Generally, you should decrypt sensitive information only at the point where it is necessary for it to be used in cleartext.

Be aware that external processes often store the standard output and standard error streams of the application. This will include logged sensitive information.

Example

The following example code logs user credentials (in this case, their password) in plaintext:

let password = "P@ssw0rd"
NSLog("User password changed to \(password)")

Instead, you should encrypt or obfuscate the credentials, or omit them entirely:

let password = "P@ssw0rd"
NSLog("User password changed")

References

  • M. Dowd, J. McDonald and J. Schuhm, The Art of Software Security Assessment, 1st Edition, Chapter 2 - 'Common Vulnerabilities of Encryption', p. 43. Addison Wesley, 2006.
  • M. Howard and D. LeBlanc, Writing Secure Code, 2nd Edition, Chapter 9 - 'Protecting Secret Data', p. 299. Microsoft, 2002.
  • OWASP: Logging Cheat Sheet.
  • Common Weakness Enumeration: CWE-312.
  • Common Weakness Enumeration: CWE-359.
  • Common Weakness Enumeration: CWE-532.

Comment thread unified/ql/lib/codeql/unified/internal/dataflow/DataFlowNode.qll Fixed
*/
predicate relevantNode(AstNode node) {
// Match an ancestor node by location so its whole subtree is shown.
node.getParent*().getLocation().toString().matches("%test.swift@13:%")

from DummyFlow::PathNode source, DummyFlow::PathNode sink
where DummyFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "Logging of $@", source.getNode(), "sensitive data"

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

The standard query is knowingly noisy, while type contexts and tuple indices above 20 are modeled incorrectly.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 3 Medium severity

Open findings (3)
What changed in this PR

Adds foundational Unified data-flow/taint tracking and a Swift cleartext-logging query.

Changes:

  • Implements data-flow nodes, SSA integration, content tracking, and flow steps.
  • Exposes public data-flow APIs and testing utilities.
  • Adds cleartext-logging query documentation and tests.
File Description
CleartextLoggingGood.swift (test) Adds negative query case.
CleartextLoggingBad.swift (test) Adds positive query case.
CleartextLogging.qlref Configures query test.
CleartextLogging.expected Generated query expectation.
dataflow/​test.swift Exercises local and taint flow.
dataflow/​test.ql Runs inline flow tests.
dataflow/​test.expected Generated flow expectations.
dataflow/​implicit-self.swift Tests implicit receiver flow.
CleartextLoggingGood.swift (query) Adds safe documentation example.
CleartextLoggingBad.swift (query) Adds unsafe documentation example.
CleartextLogging.ql Implements the security query.
CleartextLogging.qhelp Documents the query.
InlineFlowTest.qll Adds Unified flow-test support.
unified.qll Exports the data-flow API.
qlpack.yml Adds data-flow dependencies.
StaticNameBinding.qll Exposes member names.
FacadeAst.qll Adds call argument counting.
ExprPositions.qll Classifies expression contexts.
debugDataFlowGraph.ql Adds graph visualization.
VariableRefKind.qll Defines variable access kinds.
TaintTrackingInstantiation.qll Instantiates taint tracking.
Step.qll Defines flow-step kinds.
LocalSsa.qll Integrates local SSA.
DataFlowPublic.qll Exposes public modules.
DataFlowNode.qll Defines data-flow nodes.
DataFlowInstantiation.qll Instantiates data flow.
DataFlowGraph.qll Constructs local flow edges.
Content.qll Models field-sensitive content.
AllDataFlow.qll Aggregates internal modules.
AstExtra.qll Separates identifier labels.
DataFlowConsistency.ql Adds consistency checks.

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

Comment thread unified/ql/lib/codeql/unified/internal/ExprPositions.qll
or
// Tuple elements can be accessed as named members, e.g. `tuple.0`, `tuple.1`, etc,
// so just model their elements as named members.
name = [0 .. 20].toString()
* @kind path-problem
* @problem.severity error
* @security-severity 7.5
* @precision high
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@asgerf
asgerf marked this pull request as ready for review September 14, 2026 13:31
@asgerf
asgerf requested a review from a team as a code owner September 14, 2026 13:31

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

Prototype query, .qhelp and query test LGTM (apart from one dead link). 🎉 🚀

Comment thread unified/ql/src/queries/security/CWE-312/CleartextLogging.qhelp Outdated
Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>

@hvitved hvitved 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 great, some minor comments.

Comment thread unified/ql/lib/codeql/unified/internal/dataflow/DataFlowGraph.qll
Comment thread unified/ql/test/library-tests/dataflow/test.ql
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll
Comment thread unified/ql/test/library-tests/dataflow/implicit-self.swift
Comment thread unified/ql/consistency-queries/DataFlowConsistency.ql
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/DataFlowGraph.qll Outdated
@asgerf

asgerf commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @hvitved! I've answered all comments, PTAL.

//
// Types
//
class DataFlowType = Unit; // TODO: track types

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.

Let's override toString with "" to avoid the unit output in the path graph.

@asgerf
asgerf merged commit 3ac67c5 into github:main Sep 15, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants