Skip to content

Commit 9a29ceb

Browse files
Fix docker SHA false positive
Fix false positives for pinned Docker container images.
1 parent e1f92b4 commit 9a29ceb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ private predicate isTrustedOwner(string nwo) {
2323
trustedActionsOwnerDataModel(nwo.substring(0, nwo.indexOf("/")))
2424
}
2525

26+
bindingset[version]
27+
private predicate isPinnedContainer(string version) { version.regexpMatch("^sha256:[A-Fa-f0-9]{64}$") }
28+
29+
bindingset[nwo]
30+
private predicate isContainerImage(string nwo) { version.regexpMatch("^docker:\/\/.*") }
31+
2632
from UsesStep uses, string nwo, string version, Workflow workflow, string name
2733
where
2834
uses.getCallee() = nwo and
@@ -33,9 +39,20 @@ where
3339
not exists(workflow.getName()) and workflow.getLocation().getFile().getBaseName() = name
3440
) and
3541
uses.getVersion() = version and
42+
isContainerImage(nwo) = isContainer and
3643
not isTrustedOwner(nwo) and
37-
not isPinnedCommit(version) and
3844
not isImmutableAction(uses, nwo)
45+
not (
46+
(
47+
isContainer and
48+
isPinnedCommit(version)
49+
)
50+
or
51+
(
52+
not isContainer and
53+
isPinnedCommit(version)
54+
)
55+
)
3956
select uses.getCalleeNode(),
4057
"Unpinned 3rd party Action '" + name + "' step $@ uses '" + nwo + "' with ref '" + version +
4158
"', not a pinned commit hash", uses, uses.toString()

actions/ql/test/query-tests/Security/CWE-829/.github/workflows/unpinned_tags.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ jobs:
99
- uses: foo/bar
1010
- uses: foo/bar@v1
1111
- uses: foo/bar@25b062c917b0c75f8b47d8469aff6c94ffd89abb
12+
- uses: docker://foo/bar@latest
13+
- uses: docker://foo/bar@sha256:887a259a5a534f3c4f36cb02dca341673c6089431057242cdc931e9f133147e9

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
| .github/workflows/test17.yml:20:21:20:63 | sonarsource/sonarcloud-github-action@master | Unpinned 3rd party Action 'Sonar' step $@ uses 'sonarsource/sonarcloud-github-action' with ref 'master', not a pinned commit hash | .github/workflows/test17.yml:19:15:23:58 | Uses Step | Uses Step |
3333
| .github/workflows/test18.yml:37:21:37:63 | sonarsource/sonarcloud-github-action@master | Unpinned 3rd party Action 'Sonar' step $@ uses 'sonarsource/sonarcloud-github-action' with ref 'master', not a pinned commit hash | .github/workflows/test18.yml:36:15:40:58 | Uses Step | Uses Step |
3434
| .github/workflows/unpinned_tags.yml:10:13:10:22 | foo/bar@v1 | Unpinned 3rd party Action 'unpinned_tags.yml' step $@ uses 'foo/bar' with ref 'v1', not a pinned commit hash | .github/workflows/unpinned_tags.yml:10:7:11:4 | Uses Step | Uses Step |
35+
| .github/workflows/unpinned_tags.yml:12:13:12:35 | docker://foo/bar@latest | Unpinned 3rd party Action 'unpinned_tags.yml' step $@ uses 'docker://foo/bar' with ref 'latest', not a pinned commit hash | .github/workflows/unpinned_tags.yml:12:7:13:4 | Uses Step | Uses Step |

0 commit comments

Comments
 (0)