Skip to content

Commit 506f085

Browse files
authored
github-app: test repositories, not repository (#2011)
* github-app: test `repositories`, not `repository` * Record changes * Clean up test
1 parent 53dea37 commit 506f085

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

crates/zizmor/src/audit/github_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ impl GitHubApp {
116116
}
117117
}
118118

119-
// `owner: ...` without `repository: ...` grants the app token access to all
119+
// `owner: ...` without `repositories: ...` grants the app token access to all
120120
// repositories in the owner's account, which is likely more access than the
121121
// user intended.
122-
if with.contains_key("owner") && !with.contains_key("repository") {
122+
if with.contains_key("owner") && !with.contains_key("repositories") {
123123
findings.push(
124124
Self::finding()
125125
.confidence(Confidence::High)

crates/zizmor/tests/integration/audit/github_app.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,61 @@ fn test_regular_persona() -> anyhow::Result<()> {
88
.run()?,
99
@"
1010
error[github-app]: dangerous use of GitHub App tokens
11-
--> @@INPUT@@:19:11
11+
--> @@INPUT@@:21:11
1212
|
13-
17 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
13+
19 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
1414
| ------------------------------------------------------------------------ app token requested here
15-
18 | with:
16-
19 | skip-token-revoke: true
15+
20 | with:
16+
21 | skip-token-revoke: true
1717
| ^^^^^^^^^^^^^^^^^^^^^^^ token revocation disabled here
1818
|
1919
= note: audit confidence → High
2020
2121
error[github-app]: dangerous use of GitHub App tokens
22-
--> @@INPUT@@:27:11
22+
--> @@INPUT@@:29:11
2323
|
24-
25 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
24+
27 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
2525
| ------------------------------------------------------------------------ app token requested here
26-
26 | with:
27-
27 | skip-token-revoke: ${{ github.ref_name == 'main' }}
26+
28 | with:
27+
29 | skip-token-revoke: ${{ github.ref_name == 'main' }}
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ token revocation conditionally disabled here
2929
|
3030
= note: audit confidence → Low
3131
3232
error[github-app]: dangerous use of GitHub App tokens
33-
--> @@INPUT@@:35:11
33+
--> @@INPUT@@:37:11
3434
|
35-
33 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
35+
35 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
3636
| ------------------------------------------------------------------------ app token requested here
37-
34 | with:
38-
35 | owner: github
37+
36 | with:
38+
37 | owner: github
3939
| ^^^^^^^^^^^^^ token granted access to all repositories for this owner's app installation
4040
|
4141
= note: audit confidence → High
4242
= tip: use `repositories: 'repo1,repo2'` to scope the token to specific repositories
4343
4444
error[github-app]: dangerous use of GitHub App tokens
45-
--> @@INPUT@@:43:11
45+
--> @@INPUT@@:45:11
4646
|
47-
41 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
47+
43 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
4848
| ------------------------------------------------------------------------ app token requested here
49-
42 | with:
50-
43 | owner: github
49+
44 | with:
50+
45 | owner: github
5151
| ^^^^^^^^^^^^^ token granted access to all repositories for this owner's app installation
5252
|
5353
= note: audit confidence → High
5454
= tip: use `repositories: 'repo1,repo2'` to scope the token to specific repositories
5555
5656
error[github-app]: dangerous use of GitHub App tokens
57-
--> @@INPUT@@:41:15
57+
--> @@INPUT@@:43:15
5858
|
59-
41 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
59+
43 | uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app token inherits blanket installation permissions
6161
|
6262
= note: audit confidence → High
6363
= tip: specify at least one `permission-<name>` input to limit the token's permissions
6464
65-
9 findings (4 suppressed): 0 informational, 0 low, 0 medium, 5 high
65+
5 findings: 0 informational, 0 low, 0 medium, 5 high
6666
");
6767
Ok(())
6868
}

crates/zizmor/tests/integration/test-data/github-app.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
github-app:
1313
name: github-app
1414
runs-on: ubuntu-latest
15+
environment:
16+
name: test
1517
steps:
1618
- name: github-app-skips-token-revoke
1719
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
@@ -43,3 +45,13 @@ jobs:
4345
owner: github
4446
client-id: ${{ vars.GHES_APP_CLIENT_ID }}
4547
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
48+
49+
# OK: repositories is explicitly provided.
50+
- name: github-app-owner-with-repositories
51+
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
52+
with:
53+
owner: github
54+
repositories: github/docs
55+
client-id: ${{ vars.GHES_APP_CLIENT_ID }}
56+
private-key: ${{ secrets.GHES_APP_PRIVATE_KEY }}
57+
permission-issues: write

docs/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ of `zizmor`.
2323

2424
Many thanks to @martincostello for implementing this fix!
2525

26+
* Fixed a bug where the [github-app] audit would incorrectly flag some safe
27+
uses of @actions/create-github-app-token as unsafe (#2011)
28+
2629
## 1.25.0
2730

2831
### New Features 🌈

0 commit comments

Comments
 (0)