From 041886edd71968dabcbed73424953a9a17d082ed Mon Sep 17 00:00:00 2001 From: Imani Manyara Date: Wed, 4 Nov 2026 15:37:27 -0500 Subject: [PATCH] Give every workflow a top-level contents: read permission Closes S9. None of these jobs writes, so contents: read is the whole grant. A test fails if a workflow loses the block. --- .github/workflows/code-quality.yml | 3 +++ .github/workflows/tests.yml | 3 +++ CHANGELOG.md | 4 ++++ tests/Unit/WorkflowPermissionsTest.php | 33 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tests/Unit/WorkflowPermissionsTest.php diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 2cac9f1..a9911bc 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -5,6 +5,9 @@ on: branches: [main] workflow_dispatch: +permissions: + contents: read + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 53282f9..3c53384 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,9 @@ on: branches: [main] workflow_dispatch: +permissions: + contents: read + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true diff --git a/CHANGELOG.md b/CHANGELOG.md index d811887..9b6fe59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ All notable changes to `ichava/icon-sets-flag` follow [Keep a Changelog](https:/ token is not allowed to create pull requests in this organisation, so the sync failed at its last step after refreshing the assets. +### Security + +- **Every workflow declares a top-level `permissions: contents: read`** (S9), so its token no longer depends on the organisation's default. None of these jobs writes. `tests/Unit/WorkflowPermissionsTest.php` fails if a workflow loses the block. + ## [0.1.0] - TBD First release of `ichava/icon-sets-flag`. The repository is published as a single commit; the 0.1.x tags cut between 2026-10-23 and 2026-10-26 (v0.1.0 to v0.1.1) are folded into this release, and their notes are kept below under *Archived history*. diff --git a/tests/Unit/WorkflowPermissionsTest.php b/tests/Unit/WorkflowPermissionsTest.php new file mode 100644 index 0000000..cf67857 --- /dev/null +++ b/tests/Unit/WorkflowPermissionsTest.php @@ -0,0 +1,33 @@ + + */ +function workflow_files(): array +{ + $dir = dirname(__DIR__, 2) . '/.github/workflows'; + + return array_values(array_merge(glob($dir . '/*.yml') ?: [], glob($dir . '/*.yaml') ?: [])); +} + +it(description: 'reads the workflow files it is meant to guard', closure: function () { + // Floor: the number of workflows today. A glob that stops matching must fail, not pass empty. + expect(count(workflow_files()))->toBeGreaterThanOrEqual(7); +}); + +it(description: 'declares a top-level permissions block in every workflow', closure: function () { + $missing = []; + + foreach (workflow_files() as $file) { + if (! preg_match('/^permissions:/m', (string) file_get_contents($file))) { + $missing[] = basename($file); + } + } + + expect($missing)->toBe([]); +});