Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The foundational CFG and data-flow migration has broad compatibility implications that warrant final human validation.
Review effort: Balanced
Findings: None
What changed in this PR
Migrates GitHub Actions control-flow analysis to the shared CFG framework while retaining compatibility APIs.
Changes:
- Rebuilds CFG scopes, nodes, basic blocks, and data-flow integration on shared infrastructure.
- Corrects environment-expression ownership and adds consistency/regression checks.
- Documents intentional API and raw-CFG compatibility changes.
| File | Description |
|---|---|
actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll |
Implements the shared CFG integration. |
actions/ql/lib/codeql/actions/controlflow/BasicBlocks.qll |
Adapts existing basic-block APIs. |
actions/ql/lib/codeql/actions/Cfg.qll |
Re-exports the new implementation. |
actions/ql/lib/codeql/actions/dataflow/internal/DataFlowPrivate.qll |
Selects unique injected CFG nodes for data flow. |
actions/ql/lib/change-notes/2026-09-29-shared-cfg.md |
Documents breaking changes. |
actions/ql/consistency-queries/qlpack.yml |
Defines the Actions consistency pack. |
actions/ql/consistency-queries/CfgConsistency.ql |
Enables shared CFG checks. |
actions/ql/test/library-tests/cfg-environment/test.ql |
Tests environment CFG integrity. |
actions/ql/test/library-tests/cfg-environment/test.expected |
Records environment test results. |
actions/ql/test/library-tests/cfg-environment/.github/workflows/test.yml |
Supplies environment ownership cases. |
actions/ql/test/library-tests/basic/test.ql |
Extends CFG API regression coverage. |
actions/ql/test/library-tests/basic/test.expected |
Updates shared-CFG expectations. |
actions/ql/test/query-tests/Security/CWE-078/CONSISTENCY/CfgConsistency.expected |
Records empty consistency findings. |
actions/ql/test/query-tests/Security/CWE-088/CONSISTENCY/CfgConsistency.expected |
Records empty consistency findings. |
actions/ql/test/query-tests/Security/CWE-094/CONSISTENCY/CfgConsistency.expected |
Records empty consistency findings. |
actions/ql/test/query-tests/Security/CWE-829/CONSISTENCY/CfgConsistency.expected |
Records empty consistency findings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
2e616bb to
c5f521d
Compare
| Callable getEnclosingCallable(AstNode node) { | ||
| result = node.(Callable) | ||
| or | ||
| result = getEnclosingCallable(node.getParentNode()) |
There was a problem hiding this comment.
I don't know about actions, but in most languages this is wrong. If a callable is nested inside another callable then the innermost nodes get 2 enclosing callables.
There was a problem hiding this comment.
I see what you mean. However, for actions, Callable is either a Workflow or a CompositeAction and these are both the root node of the file, so there isn't the kind of nesting you can have in other programming languages. I've added not node instanceof Callable and to make it clearer, as it makes no difference and is easier to understand for those not familiar with actions (which is most of us). I've also updated the QLDoc for getEnclosingCallable to document that it although getParentNode can have multiple results, all paths with give the same root callable.
Actually, it is technically possible to make a file that is both, though no one would do this in practice. I have updated the definition of Callable to always choose CompositeAction in that case. I've added a test for this.
c5f521d to
a913e57
Compare
Replace the legacy Actions CFG implementation with the shared CFG pipeline, keep data-flow nodes canonical, and ensure callable roots are connected without scalar-expression cycles. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Attach environment expressions once to their declaring workflow, job, or step so shared CFG nodes do not acquire multiple parents or form cycles. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Prefer the composite-action interpretation when a YAML document is recognized as both a workflow and a composite action, ensuring each CFG node has a unique enclosing callable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a913e57 to
755e78b
Compare
| query predicate cfgDeadEnds(Cfg::Node n) { | ||
| not n instanceof Cfg::ExitNode and | ||
| not exists(n.getASuccessor()) | ||
| } |
There was a problem hiding this comment.
Why is this here? Dead ends are detected as part of the consistency queries.
| ) | ||
| } | ||
|
|
||
| query predicate cfgConsistency(string query, int results) { |
There was a problem hiding this comment.
What's the point of this?
| query predicate legacyCfgSplits(Cfg::AstCfgNode node) { | ||
| exists(node.getSplitsString()) or | ||
| exists(node.getASplit()) | ||
| } |
There was a problem hiding this comment.
Anything referencing splits should be trivially empty and should be deleted.
|
|
||
| query predicate normalExitNodes(Cfg::AnnotatedExitNode exit) { exit.isNormal() } | ||
|
|
||
| query predicate legacyNodeProperties( |
There was a problem hiding this comment.
Legacy node properties? What's the point here?
|
|
||
| query predicate cfgDeadEnds(Cfg::Node node) { | ||
| not node instanceof Cfg::ExitNode and | ||
| not exists(node.getASuccessor()) | ||
| } | ||
|
|
||
| query predicate cfgConsistency(string query, int results) { | ||
| Cfg::Consistency::consistencyOverview(query, results) and | ||
| results != 0 | ||
| } |
| @@ -1,419 +1,85 @@ | |||
| /** Provides classes representing basic blocks. */ | |||
There was a problem hiding this comment.
Can we delete this file? If not, please explain why not.
| private AstNode getLastCfgAstNode(AstNode node) { | ||
| not exists(getCfgChild(node, _)) and result = node | ||
| or | ||
| exists(AstNode child, int index | | ||
| child = getCfgChild(node, index) and | ||
| not exists(int later | later > index and exists(getCfgChild(node, later))) and | ||
| result = getLastCfgAstNode(child) | ||
| ) |
There was a problem hiding this comment.
I think this is dead code, right?
| cached | ||
| AstNode getAControlFlowEntryNode(AstNode node) { | ||
| result = node and | ||
| exists(Node cfgNode | cfgNode.injects(node)) | ||
| } |
There was a problem hiding this comment.
This is dead, right? Delete.
| /** Gets a potential last AST node executed within `node`. */ | ||
| cached | ||
| AstNode getAControlFlowExitNode(AstNode node) { | ||
| exists(Node cfgNode | cfgNode.injects(node)) and | ||
| result = getLastCfgAstNode(node) | ||
| } |
There was a problem hiding this comment.
This is dead, right? Delete.
| * If needed, call this predicate to force a stage dependency on the cached CFG stage. | ||
| */ | ||
| cached | ||
| predicate forceCachingInSameStage() { CfgCachedStage::ref() } |
There was a problem hiding this comment.
This does absolutely nothing when it isn't in a cached module. Also, the reference to CfgCachedStage::ref() here is plain bogus.
Delete.
| cached | ||
| CfgScope getNodeCfgScope(Node node) { result = node.getScope() } |
There was a problem hiding this comment.
This is completely useless - it's caching a copy of the member predicate, which is then itself not cached. Do we have any indications that caching getEnclosingCallable is needed? If not, delete. If we do, perhaps just cache the input to the shared lib - that's way simpler (and actually works as opposed to this).
| /** Gets a comma-separated list of splits in this node, if any. */ | ||
| string getSplitsString() { none() } | ||
|
|
||
| /** Gets a split for this control flow node, if any. */ | ||
| Split getASplit() { none() } |
|
|
||
| private class ScalarValueLeaf extends LeafTree instanceof ScalarValue { } | ||
| /** The empty split type retained for compatibility with the legacy Actions CFG. */ | ||
| class Split = Void; |
| * | ||
| * Only nodes that can be reached from an entry point are included in the CFG. | ||
| */ | ||
| class Node extends ControlFlowNode { |
There was a problem hiding this comment.
Do we need this subclassing? It would be preferable if we cold just use the ControlFlowNode class that we got from the shared lib.
Migrates the GitHub Actions control-flow graph to the shared CFG construction library already used by Java, C#, Ruby and Go.
Meaningful CFG changes
Ignoring the synthetic before/after and entry/exit nodes introduced by the shared library, there are two intentional topology changes relative to the old CFG:
Environment expressions are evaluated at their declaration site.
Run,UsesStep, or reusable-workflow job that could consume it. An inherited workflow- or job-level expression could therefore appear under many consumers, giving the same AST node multiple structural parents and successors.envmapping declares it. Consumers no longer become structural CFG parents of inherited expressions.Expressions embedded in run scripts have a single structural path.
Runand a child of the scriptScalarValue, creating duplicate paths to the same AST expression.ScalarValueis now a CFG leaf. Script expressions remain direct children of theRun, so no expression is lost; only the redundant parent/edge is removed.Compatibility
The shared implementation introduces explicit before/after and entry/exit nodes, so code relying on exact raw CFG nodes, edges, textual representations, or basic-block boundaries may need updating.
The obsolete
Completion,NormalCompletion,SimpleCompletion,BooleanCompletion, andReturnCompletionclasses are intentionally removed. Callers should inspect successor edge types such asDirectSuccessor,BooleanSuccessor, andReturnSuccessorinstead. Other established Actions CFG APIs are retained on top of the shared implementation.Commit structure
The history is organized into three independently testable commits: