Skip to content

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

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

owen-mc wants to merge 2 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.

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

Comment on lines +82 to +87
func calleeReadsOnly(p *inner) {
if p == nil {
p = &inner{val: source()}
}
_ = p.val
}
owen-mc and others added 2 commits November 27, 2026 09:16
…ences

Propagate PostUpdateNodes recursively along the full readStep predecessor chain
(including call arguments, method receivers, address-of operands, and channel
receives) and stop generating PostUpdateNodes on read-only pointer dereferences.
This resolves all DataFlowConsistency reverseRead warnings across Go tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously, `calleeReadsOnly` assigned `p = &inner{val: source()}`, which
stored taint inside `[PointerContent, FieldContent(val)]` rather than
tainting `p` with an empty access path. Before removing `PostUpdateNode`s
on read-only pointer dereferences, `_ = p.val` generated `p [postupdate]`
and spurious backflow to the caller happened via `referenceStep`
(`implicit-deref p -> p [postupdate]`), an additional taint step that
only fires when `implicit-deref p` has an empty access path. As a result,
`testNoBackflowFromReadOnlyDeref` passed even without the fix.

Assign `p = taint()` from a pointer-returning source instead so `p` itself
is tainted and the test fails without the fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@owen-mc
owen-mc force-pushed the go/missing-post-update-nodes branch from 8a281d1 to e121a13 Compare November 27, 2026 09:17

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