Skip to content

Commit dc76ee9

Browse files
committed
actions: stop unpinned-tag flagging $/ self-references
A $/ reference (e.g. "uses: $/path/to/action") is a same-repo self-reference that resolves to the commit the workflow is running at. It is inherently pinned, exactly like a "./" local reference, so it must never be reported by actions/unpinned-tag. Adds an isSelfReference(nwo) guard to the query plus a test fixture covering the bare "$/actions/foo" form and the "$/actions/foo@v1" form (the latter is rejected by the $/ rule but writable by a user; the guard suppresses it either way). Part of github/actions-dispatch#755.
1 parent 161c8c4 commit dc76ee9

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ private predicate isPinnedContainer(string version) {
3333
bindingset[nwo]
3434
private predicate isContainerImage(string nwo) { nwo.regexpMatch("^docker://.+") }
3535

36+
// A `$/` reference is a same-repo self-reference (e.g. `$/path/to/action`), resolved at the
37+
// commit the calling workflow is running. Like `./` local references, it is inherently pinned
38+
// and can never be an unpinned-tag finding, so we never flag it.
39+
bindingset[nwo]
40+
private predicate isSelfReference(string nwo) { nwo.matches("$/%") }
41+
3642
private predicate getStepContainerName(UsesStep uses, string name) {
3743
exists(Workflow workflow |
3844
uses.getEnclosingWorkflow() = workflow and
@@ -55,6 +61,7 @@ where
5561
getStepContainerName(uses, name) and
5662
uses.getVersion() = version and
5763
not isTrustedOwner(nwo) and
64+
not isSelfReference(nwo) and
5865
not (if isContainerImage(nwo) then isPinnedContainer(version) else isPinnedCommit(version)) and
5966
not isImmutableAction(uses, nwo)
6067
select uses.getCalleeNode(),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `actions/unpinned-tag` query no longer reports `$/` same-repo self-references (e.g. `uses: $/path/to/action`), which are inherently pinned to the running commit, just like `./` local references.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on:
2+
pull_request
3+
4+
jobs:
5+
build:
6+
name: Build and test
7+
runs-on: ubuntu-latest
8+
steps:
9+
# `$/` is a same-repo self-reference resolved at the running commit. It is inherently
10+
# pinned (like `./` local refs) and must never be reported as an unpinned tag.
11+
- uses: $/actions/foo
12+
# `$/…@ref` is rejected by the `$/` rule, but a user could still write it. It must also
13+
# never be flagged; this case exercises the `not isSelfReference(nwo)` suppression, since
14+
# without it `$/actions/foo@v1` would otherwise be reported as an unpinned tag.
15+
- uses: $/actions/foo@v1

0 commit comments

Comments
 (0)