Skip to content

Go: Fix PostUpdateNode generation for read chains and pointer dereferences - #23245

Open
owen-mc wants to merge 5 commits into
github:mainfrom
owen-mc:go/missing-post-update-nodes
Open

owen-mc wants to merge 5 commits into
github:mainfrom
owen-mc:go/missing-post-update-nodes

Conversation

@owen-mc

@owen-mc owen-mc commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes all Origin of readStep is missing a PostUpdateNode (reverseRead) data-flow consistency warnings in Go and removes spurious PostUpdateNodes on read-only pointer dereferences.

Changes

  • Propagate PostUpdateNodes along the full readStep chain: Unified direct triggers in insnDirectlyHasPostUpdateNode, added RecvExpr (<-ch) and .stripParens() handling to getAccessPathPredecessorInsn, and defined insnHasPostUpdateNode recursively over getAccessPathPredecessorInsn. Previously, only direct component/pointer writes propagated PostUpdateNodes up the read chain, leaving call arguments (f(a.b)), method receivers (a.b.m()), and address-of operands (&a.b) without PostUpdateNodes on outer bases.
  • Stop creating PostUpdateNodes on read-only pointer dereferences: Removed unconditional PostUpdateNode creation on StarExpr.getBase(), DerefExpr.getOperand(), and EvalImplicitDerefInstruction.getOperand(). Actual mutations through pointers (*x = y, f(*x), (*x).m(), &(*x)) still propagate PostUpdateNodes to x, while pure reads (req.Method, len(params.Text)) no longer turn pointer parameters into taint out-parameters or add redundant [postupdate] path steps.

This fixes all data flow consistency alerts, and removes unnecessary edges from 6 .expected files.

DCA is neutral. I ran QA on 5000 repos. Performance changes were minimal and not statistically significant. There were alert changes on 69 (repo, query) pairs (with some duplication due to forks). I triaged several of these and they were all correct as far as this PR goes (many were FPs for pre-existing reasons).

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 regression test taints only p.val, not the pointer, so it can pass with the old unconditional post-update behavior and fail to detect the regression.

1 open issue
What changed in this PR

Improves CodeQL’s Go data-flow graph by propagating post-update nodes through nested read chains while avoiding unnecessary nodes for read-only pointer dereferences.

Changes:

  • Unifies mutation triggers and extends propagation through field reads, indexing, dereferences, and channel receives.
  • Removes unconditional post-update nodes for pointer reads, reducing spurious caller updates and redundant paths.
  • Adds regression tests, updates expected results, and documents the analysis change.
File Description
go/​ql/​test/​query-tests/​Security/​CWE-918/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-770/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-643/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-640/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-601/​OpenUrlRedirect/​OpenUrlRedirect.expected Removes redundant post-update path steps.
go/​ql/​test/​query-tests/​Security/​CWE-601/​OpenUrlRedirect/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-601/​BadRedirectCheck/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-347/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-327/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-312/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-190/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-117/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-089/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-079/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-078/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-022/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-020/​MissingRegexpAnchor/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​Security/​CWE-020/​IncompleteHostnameRegexp/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​query-tests/​RedundantCode/​DeadStoreOfLocal/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​Types/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​XNetHtml/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​WebSocket/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Twirp/​RequestForgery.expected Removes spurious parameter-return paths.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Twirp/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​TaintSteps/​TaintStep.expected Adds propagated post-update taint steps.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​TaintSteps/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​SystemCommandExecutors/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Slog/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Revel/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Protobuf/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​GoMicro/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Gin/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Fasthttp/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Echo/​OpenRedirect.expected Removes redundant post-update path steps.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Echo/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Chi/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​BeegoOrm/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Beego/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Afero/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​ThreatModels/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSA/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PromotedFields/​LocalFlowStep.expected Removes post-update edges from read-only uses.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​test.ql Limits node assertions to test.go.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​test.go Adds read-chain and channel-receive cases.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​test.expected Updates expected post-update node generation.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​Flows.ql Adds the inline flow-test query.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​flows.go Tests nested mutations and read-only calls.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​Flows.expected Records expected clean flow-test results.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​PostUpdateNodes/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​GlobalVariableSideEffects/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​GlobalValueNumbering/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​ExternalValueFlow/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​ExternalTaintFlow/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​DefaultTaintSanitizer/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​library-tests/​semmle/​go/​concepts/​HTTP/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​Unsafe/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​frameworks/​CleverGo/​CONSISTENCY/​DataFlowConsistency.expected Clears a reverse-read warning expectation.
go/​ql/​test/​experimental/​CWE-942/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-918/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-840/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-807/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-522-DecompressionBombs/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-369/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-321-V2/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-287/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​experimental/​CWE-203/​CONSISTENCY/​DataFlowConsistency.expected Clears reverse-read warning expectations.
go/​ql/​test/​example-tests/​snippets/​typeinfo.expected Removes a read-only post-update node.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​DataFlowNodes.qll Unifies triggers and propagates nodes through reads.
go/​ql/​lib/​change-notes/​2026-11-25-post-update-nodes.md Documents the data-flow analysis improvements.

Review effort: Max

@owen-mc
owen-mc force-pushed the go/missing-post-update-nodes branch 2 times, most recently from e121a13 to 28f0099 Compare December 1, 2026 10:39
@owen-mc
owen-mc marked this pull request as ready for review December 1, 2026 10:39
@owen-mc
owen-mc requested a review from a team as a code owner December 1, 2026 10:39
@owen-mc
owen-mc requested review from a team, aschackmull and hvitved December 1, 2026 10:41
owen-mc and others added 4 commits December 1, 2026 11:09
Cover nested receivers and arguments, channel receives, address-of fields,
and spurious caller updates after read-only dereferences. Record baseline
MISSING and SPURIOUS expectations so later commits expose their effects.

Also check value flow through an explicit double-pointer field write.
This protects necessary post-update nodes when unconditional dereference
nodes are removed, complementing the implicit-dereference cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract insnDirectlyHasPostUpdateNode and inline the write and receiver
helpers. Express their existing recursive definitions as closures, keeping
the same per-trigger propagation and all dereference triggers.

Normalize expression-to-instruction lookups and remove the redundant
Method check. This commit changes no test or consistency output; the next
commit broadens propagation to all post-update triggers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply predecessor closure to every post-update trigger, rather than only
to writes and promoted method receivers, and include channel receives.
This adds the missing nodes for nested arguments, receivers, and addresses
and resolves the existing reverseRead consistency warnings.

Update flow expectations and snapshots for propagation alone. Keep the
unconditional dereference triggers and the SPURIOUS backflow expectations
so their removal is visible independently in the next commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop creating post-update nodes merely because a value is dereferenced. The read-chain propagation added in the preceding commit retains the nodes needed for writes and calls, including the explicit double-dereference write covered by the first commit's regression test.

This prevents a callee's local pointer reassignment from spuriously flowing back to its caller through a read-only dereference. Remove the SPURIOUS expectations and update the affected node and path snapshots separately from the propagation change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@owen-mc
owen-mc force-pushed the go/missing-post-update-nodes branch from 28f0099 to 6d585f9 Compare December 1, 2026 11:23

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

Besides the nit about the change note, this LGTM.

@owen-mc
owen-mc requested a review from aschackmull December 3, 2026 15:46

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.

3 participants