Skip to content

Commit 2bbbce7

Browse files
authored
🐛 Discard GitHub token in dangerous workflow check (#1772)
* Discard GitHub token in dangerous workflow check * missing files
1 parent 66b3d8c commit 2bbbce7

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

checks/dangerous_workflow.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,13 @@ func checkSecretInScript(script string, pos *actionlint.Pos, path string,
466466
return sce.WithMessage(sce.ErrScorecardInternal, errInvalidGitHubWorkflow.Error())
467467
}
468468

469+
// Note: The default GitHub token is allowed, as it has
470+
// only read permission for `pull_request`.
471+
// For `pull_request_event`, we use other signals such as
472+
// whether checkout action is used.
469473
variable := strings.Trim(script[s:s+e+2], " ")
470-
if strings.Contains(variable, "secrets.") {
474+
if !strings.Contains(variable, "secrets.GITHUB_TOKEN") &&
475+
strings.Contains(variable, "secrets.") {
471476
line := fileparser.GetLineNumber(pos)
472477
dl.Warn(&checker.LogMessage{
473478
Path: path,

checks/dangerous_workflow_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,28 @@ func TestGithubDangerousWorkflow(t *testing.T) {
241241
NumberOfDebug: 0,
242242
},
243243
},
244+
{
245+
name: "default secret in pull request",
246+
filename: "./testdata/.github/workflows/github-workflow-dangerous-pattern-default-secret-pr.yml",
247+
expected: scut.TestReturn{
248+
Error: nil,
249+
Score: checker.MaxResultConfidence,
250+
NumberOfWarn: 0,
251+
NumberOfInfo: 0,
252+
NumberOfDebug: 0,
253+
},
254+
},
255+
{
256+
name: "default secret in pull request target",
257+
filename: "./testdata/.github/workflows/github-workflow-dangerous-pattern-default-secret-prt.yml",
258+
expected: scut.TestReturn{
259+
Error: nil,
260+
Score: checker.MinResultConfidence,
261+
NumberOfWarn: 1,
262+
NumberOfInfo: 0,
263+
NumberOfDebug: 0,
264+
},
265+
},
244266
{
245267
name: "secret in top env no checkout pull request target",
246268
filename: "./testdata/.github/workflows/github-workflow-dangerous-pattern-secret-env-no-checkout-prt.yml",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Close issue on Jira
2+
3+
on:
4+
pull_request
5+
6+
env:
7+
BLA: ${{ secrets.GITHUB_TOKEN }}
8+
9+
jobs:
10+
test1:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1.2.3
14+
with:
15+
ref: ${{ github.event.pull_request.head.sha }}
16+
name: Use in env toJson
17+
18+
- uses: some/action@v1.2.3
19+
with:
20+
option: ${{ secrets.GITHUB_TOKEN }}
21+
name: Use secret in args
22+
23+
- name: Use in with toJson
24+
env:
25+
GITHUB_CONTEXT: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
echo "$GITHUB_CONTEXT"
28+
echo "${{ secrets.GITHUB_TOKEN }}"
29+
30+
- name: Use in with toJson
31+
uses: some/action@v1.2.3
32+
env:
33+
GITHUB_CONTEXT: ${{ secrets.GITHUB_TOKEN }}
34+
run: |
35+
echo "$GITHUB_CONTEXT"
36+
echo "${{ secrets.GITHUB_TOKEN }}"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Close issue on Jira
2+
3+
on:
4+
pull_request_target
5+
6+
env:
7+
BLA: ${{ secrets.GITHUB_TOKEN }}
8+
9+
jobs:
10+
test1:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1.2.3
14+
with:
15+
ref: ${{ github.event.pull_request.head.sha }}
16+
name: Use in env toJson
17+
18+
- uses: some/action@v1.2.3
19+
with:
20+
option: ${{ secrets.GITHUB_TOKEN }}
21+
name: Use secret in args
22+
23+
- name: Use in with toJson
24+
env:
25+
GITHUB_CONTEXT: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
echo "$GITHUB_CONTEXT"
28+
echo "${{ secrets.GITHUB_TOKEN }}"
29+
30+
- name: Use in with toJson
31+
uses: some/action@v1.2.3
32+
env:
33+
GITHUB_CONTEXT: ${{ secrets.GITHUB_TOKEN }}
34+
run: |
35+
echo "$GITHUB_CONTEXT"
36+
echo "${{ secrets.GITHUB_TOKEN }}"

0 commit comments

Comments
 (0)