Skip to content

Commit 55ee70e

Browse files
authored
Check that actions specify hashes instead of allowlist (#24042)
* Check that actions specify hashes instead of allowlist * Fixes for unhashed version * Update actions-workflows.js
1 parent d5c3731 commit 55ee70e

File tree

3 files changed

+7
-50
lines changed

3 files changed

+7
-50
lines changed

.github/allowed-actions.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
34-
- uses: github/codeql-action/init@v1
34+
- uses: github/codeql-action/init@5f532563584d71fdef14ee64d17bafb34f751ce5
3535
with:
3636
languages: javascript # comma separated list of values from {go, python, javascript, java, cpp, csharp} (not YET ruby, sorry!)
37-
- uses: github/codeql-action/analyze@v1
37+
- uses: github/codeql-action/analyze@5f532563584d71fdef14ee64d17bafb34f751ce5
3838
continue-on-error: true

tests/unit/actions-workflows.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import path from 'path'
33
import fs from 'fs'
44
import yaml from 'js-yaml'
55
import flat from 'flat'
6-
import { chain, difference, get } from 'lodash-es'
7-
import allowedActions from '../../.github/allowed-actions.js'
6+
import { chain, get } from 'lodash-es'
87
const __dirname = path.dirname(fileURLToPath(import.meta.url))
98
const workflowsDir = path.join(__dirname, '../../.github/workflows')
109
const workflows = fs
@@ -31,16 +30,13 @@ const scheduledWorkflows = workflows
3130
const allUsedActions = chain(workflows).map(actionsUsedInWorkflow).flatten().uniq().sort().value()
3231

3332
describe('GitHub Actions workflows', () => {
34-
test('all used actions are allowed in .github/allowed-actions.js', () => {
33+
test('all used actions are listed', () => {
3534
expect(allUsedActions.length).toBeGreaterThan(0)
36-
const unusedActions = difference(allowedActions, allUsedActions)
37-
expect(unusedActions).toEqual([])
3835
})
3936

40-
test('all allowed actions by .github/allowed-actions.js are used by at least one workflow', () => {
41-
expect(allowedActions.length).toBeGreaterThan(0)
42-
const disallowedActions = difference(allUsedActions, allowedActions)
43-
expect(disallowedActions).toEqual([])
37+
test.each(allUsedActions)('requires specific hash: %p', (actionName) => {
38+
const actionRegexp = /^[A-Za-z0-9-/]+@[0-9a-f]{40}$/
39+
expect(actionName).toMatch(actionRegexp)
4440
})
4541

4642
test('no scheduled workflows run on the hour', () => {

0 commit comments

Comments
 (0)