Skip to content

Commit ec12035

Browse files
Copilotoscarsj
andauthored
Extend unpinned-tag query to scan composite action metadata
Agent-Logs-Url: https://github.com/github/codeql/sessions/c52790be-00f6-4250-b46b-38c05365ddd7 Co-authored-by: oscarsj <1410188+oscarsj@users.noreply.github.com>
1 parent 386872c commit ec12035

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,26 @@ private predicate isPinnedContainer(string version) {
3131
bindingset[nwo]
3232
private predicate isContainerImage(string nwo) { nwo.regexpMatch("^docker://.+") }
3333

34-
from UsesStep uses, string nwo, string version, Workflow workflow, string name
34+
private predicate getStepContainerName(UsesStep uses, string name) {
35+
exists(Workflow workflow |
36+
uses.getEnclosingWorkflow() = workflow and
37+
(
38+
workflow.getName() = name
39+
or
40+
not exists(workflow.getName()) and workflow.getLocation().getFile().getBaseName() = name
41+
)
42+
)
43+
or
44+
exists(CompositeAction action |
45+
uses.getEnclosingCompositeAction() = action and
46+
name = action.getLocation().getFile().getBaseName()
47+
)
48+
}
49+
50+
from UsesStep uses, string nwo, string version, string name
3551
where
3652
uses.getCallee() = nwo and
37-
uses.getEnclosingWorkflow() = workflow and
38-
(
39-
workflow.getName() = name
40-
or
41-
not exists(workflow.getName()) and workflow.getLocation().getFile().getBaseName() = name
42-
) and
53+
getStepContainerName(uses, name) and
4354
uses.getVersion() = version and
4455
not isTrustedOwner(nwo) and
4556
not (if isContainerImage(nwo) then isPinnedContainer(version) else isPinnedCommit(version)) and
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Composite unpinned tag test
2+
runs:
3+
using: "composite"
4+
steps:
5+
- uses: foo/bar@v2
6+
- uses: foo/bar@25b062c917b0c75f8b47d8469aff6c94ffd89abb

actions/ql/test/query-tests/Security/CWE-829/UnpinnedActionsTag.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| .github/actions/unpinned-tag/action.yml:5:13:5:22 | foo/bar@v2 | Unpinned 3rd party Action 'action.yml' step $@ uses 'foo/bar' with ref 'v2', not a pinned commit hash | .github/actions/unpinned-tag/action.yml:5:7:6:60 | Uses Step | Uses Step |
12
| .github/workflows/actor_trusted_checkout.yml:19:13:19:36 | completely/fakeaction@v2 | Unpinned 3rd party Action 'actor_trusted_checkout.yml' step $@ uses 'completely/fakeaction' with ref 'v2', not a pinned commit hash | .github/workflows/actor_trusted_checkout.yml:19:7:23:4 | Uses Step | Uses Step |
23
| .github/workflows/actor_trusted_checkout.yml:23:13:23:37 | fakerepo/comment-on-pr@v1 | Unpinned 3rd party Action 'actor_trusted_checkout.yml' step $@ uses 'fakerepo/comment-on-pr' with ref 'v1', not a pinned commit hash | .github/workflows/actor_trusted_checkout.yml:23:7:26:21 | Uses Step | Uses Step |
34
| .github/workflows/artifactpoisoning21.yml:13:15:13:49 | dawidd6/action-download-artifact@v2 | Unpinned 3rd party Action 'Pull Request Open' step $@ uses 'dawidd6/action-download-artifact' with ref 'v2', not a pinned commit hash | .github/workflows/artifactpoisoning21.yml:13:9:18:6 | Uses Step | Uses Step |

0 commit comments

Comments
 (0)