Skip to content

Commit 8a372e9

Browse files
Merge pull request #2482 from step-security/fix-2479
Fix 2479
2 parents d61982f + fa5ec87 commit 8a372e9

File tree

13 files changed

+51
-19
lines changed

13 files changed

+51
-19
lines changed

Diff for: .github/workflows/automatePR.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717

1818
steps:
1919
- name: Harden Runner
20-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
20+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
2121
with:
2222
egress-policy: audit
2323

24-
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6
24+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
2525
with:
2626
repository: step-security/secure-repo
2727

Diff for: .github/workflows/codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141

4242
steps:
4343
- name: Harden Runner
44-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
44+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
4545
with:
4646
egress-policy: audit
4747

4848
- name: Checkout repository
49-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
49+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
5050

5151
# Initializes the CodeQL tools for scanning.
5252
- name: Initialize CodeQL

Diff for: .github/workflows/int.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Harden Runner
18-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
18+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
1919
with:
2020
egress-policy: audit
2121
- name: Checkout
22-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
22+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
2323
with:
2424
fetch-depth: 0
2525
- name: Set up Go

Diff for: .github/workflows/kb-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
contents: read
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5 # v1
17+
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
1818
with:
1919
allowed-endpoints: >
2020
api.github.com:443
@@ -25,7 +25,7 @@ jobs:
2525
objects.githubusercontent.com:443
2626
golang.org:443
2727
- name: Checkout
28-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
28+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v2
2929
with:
3030
ref: ${{ github.event.pull_request.head.sha }}
3131
- name: Set up Go

Diff for: .github/workflows/kbanalysis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222

2323
steps:
2424
- name: Harden Runner
25-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
25+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
2626
with:
2727
egress-policy: audit
2828

29-
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
29+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
3030
with:
3131
repository: step-security/secure-repo
3232

Diff for: .github/workflows/release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Harden Runner
20-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
20+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
2121
with:
2222
egress-policy: audit
2323
- name: Checkout
24-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
24+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
2525
with:
2626
fetch-depth: 0
2727
- name: Set up Go
@@ -33,7 +33,7 @@ jobs:
3333
env:
3434
PAT: ${{ secrets.PAT }}
3535

36-
- uses: step-security/wait-for-secrets@1204ba02d7a707c4ef2e906d2ea1e36eebd9bbd2
36+
- uses: step-security/wait-for-secrets@5809f7d044804a5a1d43217fa8f3e855939fc9ef
3737
id: wait-for-secrets
3838
with:
3939
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

Diff for: .github/workflows/scorecards.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ jobs:
3232

3333
steps:
3434
- name: Harden Runner
35-
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
35+
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
3636
with:
3737
egress-policy: audit
3838

3939
- name: "Checkout code"
40-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
40+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
4141
with:
4242
persist-credentials: false
4343

Diff for: .github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
contents: read
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
19+
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
2020
with:
2121
egress-policy: audit
2222
allowed-endpoints: >
@@ -31,7 +31,7 @@ jobs:
3131
objects.githubusercontent.com:443
3232
golang.org:443
3333
- name: Checkout
34-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
34+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
3535
with:
3636
ref: ${{ github.event.pull_request.head.sha }}
3737
- name: Set up Go

Diff for: knowledge-base/actions/homebrew/actions/remove-disabled-formulae/action-security.yml

-2
This file was deleted.

Diff for: remediation/workflow/metadata/actionmetadata.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Step struct {
3030
type Job struct {
3131
Permissions Permissions `yaml:"permissions"`
3232
Uses string `yaml:"uses"`
33+
Env Env `yaml:"env"`
3334
// RunsOn []string `yaml:"runs-on"`
3435
Steps []Step `yaml:"steps"`
3536
}

Diff for: remediation/workflow/permissions/permissions.go

+16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const errorMissingAction = "KnownIssue-4: Action %s is not in the knowledge base
3838
const errorAlreadyHasPermissions = "KnownIssue-5: Permissions were not added to the job since it already had permissions defined"
3939
const errorDockerAction = "KnownIssue-6: Action %s is a docker action which uses Github token. Docker actions that uses token are not supported"
4040
const errorReusableWorkflow = "KnownIssue-7: Action %s is a reusable workflow. Reusable workflows are not supported as of now."
41+
const errorGithubTokenInJobEnv = "KnownIssue-8: Permissions were not added to the jobs since it has GITHUB_TOKEN in job level env variable"
4142
const errorIncorrectYaml = "Unable to parse the YAML workflow file"
4243

4344
// To avoid a typo while adding the permissions
@@ -78,6 +79,15 @@ func alreadyHasWorkflowPermissions(workflow metadata.Workflow) bool {
7879
return workflow.Permissions.IsSet
7980
}
8081

82+
func githubTokenInJobLevelEnv(job metadata.Job) bool {
83+
for _, envValue := range job.Env {
84+
if strings.Contains(envValue, "secrets.GITHUB_TOKEN") || strings.Contains(envValue, "github.token") {
85+
return true
86+
}
87+
}
88+
return false
89+
}
90+
8191
func AddWorkflowLevelPermissions(inputYaml string, addProjectComment bool) (string, error) {
8292
workflow := metadata.Workflow{}
8393

@@ -177,6 +187,12 @@ func AddJobLevelPermissions(inputYaml string) (*SecureWorkflowReponse, error) {
177187
continue
178188
}
179189

190+
if githubTokenInJobLevelEnv(job) {
191+
fixWorkflowPermsReponse.HasErrors = true
192+
errors[jobName] = append(errors[jobName], errorGithubTokenInJobEnv)
193+
continue
194+
}
195+
180196
if metadata.IsCallingReusableWorkflow(job) {
181197
fixWorkflowPermsReponse.HasErrors = true
182198
errors[jobName] = append(errors[jobName], fmt.Sprintf(errorReusableWorkflow, job.Uses))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Job level env
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
jobs:
7+
job-with-error:
8+
env:
9+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
14+
- name: some step that uses token
15+
run: |
16+
npm ci
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KnownIssue-8: Permissions were not added to the jobs since it has GITHUB_TOKEN in job level env variable

0 commit comments

Comments
 (0)