Skip to content

unified: Add taint reach stats - #22692

Open
asgerf wants to merge 1 commit into
github:mainfrom
asgerf:unified/taint-reach
Open

asgerf wants to merge 1 commit into
github:mainfrom
asgerf:unified/taint-reach

Conversation

@asgerf

@asgerf asgerf commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Adds taint reach stats.

I've tested locally but there are still issues with getting DCA to show the numbers.

@asgerf
asgerf marked this pull request as ready for review September 30, 2026 13:35
@asgerf
asgerf requested a review from a team as a code owner September 30, 2026 13:35
Copilot AI balanced review requested due to automatic review settings September 30, 2026 13:35

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 metric includes disabled sources, excludes valid nodes, and omits its denominator row.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds Unified taint-reach metrics for DCA reporting.

Changes:

  • Computes tainted-node counts and per-million reach.
  • Exposes reach metrics through summary statistics.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​AnalysisQuality.qll Adds taint-reach analysis and reporting.

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


module TaintReach {
private class Candidate extends DataFlow::Node {
Candidate() { exists(this.asExpr()) }

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.

I would have written any() here as well I think. But if there's a reason you restricted candidate nodes to those corresponding with expressions, I think it's fine and we still have a useful metric.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid counting synthetic nodes, so we don't move the goal posts whenever synthetic nodes are added/removed. E.g. something like the introduction of use-use flow can add a large number of synthetic nodes, but then you can't compare the taint reach numbers across that change.

IMO Rust should should also stop measuring synthetic nodes.

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.

Ah, then I agree with you, that has been a problem with the rust taint reach statistic.

👍

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

LGTM.

Getting DCA to show the numbers will require some (minor) changes in that repo. Let me know if you've hit problems there. Or I'm happy to do it, I'm quite familiar with how that stuff is wired.

@asgerf asgerf added the no-change-note-required This PR does not need a change note label Oct 1, 2026
module TaintReachConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) { Models::isSource(node, _) }

predicate isSink(DataFlow::Node node) { node instanceof Candidate }

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.

This might work for now, but I would expect performance to eventually be horrendous to the point of breaking dca. If you were to try this on e.g. Java or C# then I'd be fairly certain that it just wouldn't work. We could perhaps draw the numbers from an early data flow stage - that would be a coarse over-approximation, but could guard against severe performance degradation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's somewhat alleviated by the use of flowTo instead of flowPath and for the languages where we do this (JS, Ruby, Swift, and Rust) it hasn't actually been that bad. I don't think unified needs to be different than the other languages in this respect.

But it would be great we could get the data flow library to report a better version of taint reach.

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.

But it would be great we could get the data flow library to report a better version of taint reach.

See below for a stage-2-representation. I don't think it's possible in general, otherwise we could calculate taint up front and share it across queries instead of having individual configurations.

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.

I'd expect stage 3 and beyond to be infeasible for a large chunk of repos. And given that I expect the trouble to begin already there, the improvement of using flowTo instead of flowPath won't help.

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.

Huh, I just tested on a couple of Java repos and I must admit that this was surprisingly more feasible than I had imagined. It won't work for customer dbs, but I'll concede that it indeed might work on dca.

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.

I can actually calculate stage 4 on a very large Java db (but stage 5 failed).

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.

I guess that's perhaps somewhat explainable - stage 4 limits the access path representation to the (precise) head, so type pruning likely prevents cartesian blowups in many places.

In any case, that's probably enough of my hypothetical rambling - let's go with what we have if it works, and then we can always limit it to e.g. stage 4 if necessary.


module TaintReachFlow = TaintTracking::Global<TaintReachConfig>;

DataFlow::Node taintedNode() { TaintReachFlow::flowTo(result) }

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.

Possibly something like this:

Suggested change
DataFlow::Node taintedNode() { TaintReachFlow::flowTo(result) }
DataFlow::Node taintedNode() {
exists(TaintReachFlow::Stages::Stage2::Graph::Public::PathNode sink |
sink.isSink() and result = sink.getNode()
)
}

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants