From 01dff0f829bb7ac73b2e8d9dbc225796d405bde8 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:12:17 +0000 Subject: [PATCH 1/2] fix(ci): reconcile well-known paths and lock-backed action pins Use actual www/.well-known security metadata, require valid expiry, validate SHA resolution through generated actions.lock with negative tests, and align download-artifact use with its locked version. --- .github/workflows/static-analysis-gate.yml | 6 +- .github/workflows/wellknown-enforcement.yml | 25 +++++-- .github/workflows/workflow-linter.yml | 27 ++----- scripts/check-workflow-uses-lock.sh | 73 +++++++++++++++++++ .../check-workflow-uses-lock_test.sh | 31 ++++++++ 5 files changed, 134 insertions(+), 28 deletions(-) create mode 100755 scripts/check-workflow-uses-lock.sh create mode 100755 tests/workflows/check-workflow-uses-lock_test.sh diff --git a/.github/workflows/static-analysis-gate.yml b/.github/workflows/static-analysis-gate.yml index 26a6785..739cbed 100644 --- a/.github/workflows/static-analysis-gate.yml +++ b/.github/workflows/static-analysis-gate.yml @@ -348,17 +348,17 @@ jobs: if: always() steps: - name: Download panic-attack findings - uses: actions/download-artifact@v8.0.2 + uses: actions/download-artifact@v8.0.1 with: name: panic-attack-findings path: findings/ - name: Download hypatia findings - uses: actions/download-artifact@v8.0.2 + uses: actions/download-artifact@v8.0.1 with: name: hypatia-findings path: findings/ - name: Download bridge report - uses: actions/download-artifact@v8.0.2 + uses: actions/download-artifact@v8.0.1 with: name: bridge-report path: findings/ diff --git a/.github/workflows/wellknown-enforcement.yml b/.github/workflows/wellknown-enforcement.yml index a3904ec..c9cb93c 100644 --- a/.github/workflows/wellknown-enforcement.yml +++ b/.github/workflows/wellknown-enforcement.yml @@ -8,10 +8,15 @@ on: branches: [main, master] paths: - '.well-known/**' + - 'www/.well-known/**' - 'security.txt' + - '.github/workflows/wellknown-enforcement.yml' pull_request: paths: - '.well-known/**' + - 'www/.well-known/**' + - 'security.txt' + - '.github/workflows/wellknown-enforcement.yml' schedule: # Weekly expiry check - cron: '0 9 * * *' @@ -29,8 +34,12 @@ jobs: - name: RFC 9116 security.txt validation run: | SECTXT="" - [ -f ".well-known/security.txt" ] && SECTXT=".well-known/security.txt" - [ -f "security.txt" ] && SECTXT="security.txt" + for candidate in www/.well-known/security.txt .well-known/security.txt security.txt; do + if [ -f "$candidate" ]; then + SECTXT="$candidate" + break + fi + done if [ -z "$SECTXT" ]; then echo "::error::No security.txt found — required for OpenSSF Best Practices. See https://github.com/hyperpolymath/well-known-ecosystem" @@ -48,6 +57,10 @@ jobs: # Check expiry EXPIRES=$(grep "^Expires:" "$SECTXT" | cut -d: -f2- | tr -d ' ' | head -1) + if ! date -d "$EXPIRES" > /dev/null 2>&1; then + echo "::error::security.txt Expires field is not a valid date" + exit 1 + fi if date -d "$EXPIRES" > /dev/null 2>&1; then DAYS=$(( ($(date -d "$EXPIRES" +%s) - $(date +%s)) / 86400 )) if [ $DAYS -lt 0 ]; then @@ -62,9 +75,11 @@ jobs: - name: RSR well-known compliance run: | MISSING="" - [ ! -f ".well-known/security.txt" ] && [ ! -f "security.txt" ] && MISSING="$MISSING security.txt" - [ ! -f ".well-known/ai.txt" ] && MISSING="$MISSING ai.txt" - [ ! -f ".well-known/humans.txt" ] && MISSING="$MISSING humans.txt" + for name in security.txt ai.txt humans.txt; do + if [ ! -f "www/.well-known/$name" ] && [ ! -f ".well-known/$name" ] && [ ! -f "$name" ]; then + MISSING="$MISSING $name" + fi + done if [ -n "$MISSING" ]; then echo "::warning::Missing RSR recommended files:$MISSING" diff --git a/.github/workflows/workflow-linter.yml b/.github/workflows/workflow-linter.yml index df6da34..dfe03d5 100644 --- a/.github/workflows/workflow-linter.yml +++ b/.github/workflows/workflow-linter.yml @@ -35,13 +35,13 @@ jobs: failed=0 for file in .github/workflows/*.yml .github/workflows/*.yaml; do [ -f "$file" ] || continue - if ! head -1 "$file" | grep -q "^# SPDX-License-Identifier:"; then + if ! head -6 "$file" | grep -q "^# SPDX-License-Identifier:"; then echo "ERROR: $file missing SPDX header" failed=1 fi done if [ $failed -eq 1 ]; then - echo "Add '# SPDX-License-Identifier: MPL-2.0' as first line" + echo "Require an SPDX identifier in the first six header lines (allow gh actions-lock managed preamble)" exit 1 fi echo "All workflows have SPDX headers" @@ -63,24 +63,11 @@ jobs: fi echo "All workflows have permissions declared" - - name: Check SHA-Pinned Actions - run: | - echo "=== Checking Action Pinning ===" - # Find any uses: lines that don't have @SHA format - # Pattern: uses: owner/repo@<40-char-hex> - unpinned=$(grep -rnE "^[[:space:]]+uses:" .github/workflows/ | \ - grep -v "@[a-f0-9]\{40\}" | \ - grep -v "uses: \./\|uses: docker://\|uses: actions/github-script" || true) - - if [ -n "$unpinned" ]; then - echo "ERROR: Found unpinned actions:" - echo "$unpinned" - echo "" - echo "Replace version tags with SHA pins, e.g.:" - echo " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6.0.1" - exit 1 - fi - echo "All actions are SHA-pinned" + - name: Self-test lock integrity checker (positive and negative) + run: bash tests/workflows/check-workflow-uses-lock_test.sh + + - name: Check SHA-Pinned or generated lockfile-pinned Actions + run: bash scripts/check-workflow-uses-lock.sh . - name: Check for Duplicate Workflows run: | diff --git a/scripts/check-workflow-uses-lock.sh b/scripts/check-workflow-uses-lock.sh new file mode 100755 index 0000000..695ebcf --- /dev/null +++ b/scripts/check-workflow-uses-lock.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Verify that every non-local GitHub Action is pinned directly to a 40-hex +# commit or is resolved to a full commit in the generated gh actions-lock file. +# Do not modify actions.lock by hand. +set -euo pipefail + +root="$(cd "$(dirname "$0")/.." && pwd)" +if [ "$#" -gt 0 ]; then root="$(cd "$1" && pwd)"; fi +lock="$root/.github/workflows/actions.lock" +if [ ! -s "$lock" ]; then + echo "FAIL: missing generated actions.lock: $lock" >&2 + exit 1 +fi + +fail=0 +checked=0 +shopt -s nullglob +for file in "$root"/.github/workflows/*.yml "$root"/.github/workflows/*.yaml; do + rel=".github/workflows/$(basename "$file")" + while IFS= read -r line; do + # Comments (including workflow examples) do not match the anchored selector. + spec="$(printf '%s\n' "$line" | sed -nE 's/^[[:space:]]*uses:[[:space:]]*([^[:space:]#]+).*$/\1/p')" + [ -n "$spec" ] || continue + checked=$((checked + 1)) + case "$spec" in + ./*) continue ;; + docker://*) echo "FAIL: $rel uses a Docker action without a reviewed digest: $spec" >&2; fail=1; continue ;; + esac + + source="$(printf '%s\n' "$spec" | cut -d@ -f1)" + version="$(printf '%s\n' "$spec" | awk -F@ '{print $NF}')" + if [ "$source" = "$spec" ] || ! [[ "$source" == */* ]]; then + echo "FAIL: $rel uses an action without an immutable ref: $spec" >&2 + fail=1 + continue + fi + # Native full-SHA uses (including reusable workflows) are immutable. + if [[ "$version" =~ ^[0-9a-f]{40}$ ]]; then continue; fi + # A tag is allowed only when the generated lock includes a matching + # workflow reference AND an exact ref->sha1-40 dependency record. + owner="$(printf '%s\n' "$source" | cut -d/ -f1)" + name="$(printf '%s\n' "$source" | cut -d/ -f2)" + key="$owner/$name@$version" + + if ! awk -v wf=" '$rel':" -v key=" - '$key'" ' + $0 == "dependencies:" {exit} + $0 == wf {inside=1; next} + inside && /^ [^ ]/ {inside=0} + inside && $0 == key {found=1} + END {exit(found ? 0 : 1)} + ' "$lock"; then + echo "FAIL: $rel: $key is missing from actions.lock workflow entries" >&2 + fail=1 + continue + fi + + record="$(awk -v key=" '$key':" ' + $0 == "dependencies:" {deps=1; next} + deps && $0 == key {inside=1; next} + inside && /^ [^ ]/ {exit} + inside {print} + ' "$lock")" + if ! printf '%s\n' "$record" | grep -Fxq " ref: '$version'" || + ! printf '%s\n' "$record" | grep -Eq "^[[:space:]]+commit: 'sha1-[0-9a-f]{40}'$"; then + echo "FAIL: $rel: lock entry $key lacks matching ref and 40-hex SHA" >&2 + fail=1 + fi + done < "$file" +done +[ "$checked" -gt 0 ] || { echo "FAIL: no active action uses found" >&2; exit 1; } +[ "$fail" -eq 0 ] || exit 1 +echo "PASS: $checked uses resolve to direct 40-hex pins or generated actions.lock SHA records" diff --git a/tests/workflows/check-workflow-uses-lock_test.sh b/tests/workflows/check-workflow-uses-lock_test.sh new file mode 100755 index 0000000..e1e61e3 --- /dev/null +++ b/tests/workflows/check-workflow-uses-lock_test.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Offline positive/negative fixtures for the lock-aware workflow pin checker. +set -euo pipefail +root="$(cd "$(dirname "$0")/../.." && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/.github/workflows" +sha="$(printf 'a%.0s' {1..40})" +cat > "$tmp/.github/workflows/actions.lock" < "$tmp/.github/workflows/fixture.yml" +bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" +sed -i 's/checkout@v7.0.1/checkout@v7.0.2/' "$tmp/.github/workflows/fixture.yml" +if bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" >/dev/null 2>&1; then + echo 'FAIL: mismatched workflow tag was wrongly accepted' >&2 + exit 1 +fi +printf '%s\n' 'name: fixture' 'jobs:' ' run:' ' steps:' " - uses: actions/checkout@$sha" > "$tmp/.github/workflows/fixture.yml" +bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" +printf '%s\n' 'PASS: matching lock, mismatched ref, and direct SHA cases verified' From c9f6e485fb318aa91fa2b7d5e9a0838feee3ac96 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:13:50 +0000 Subject: [PATCH 2/2] fix(tests): include YAML sequence syntax when extracting uses refs --- scripts/check-workflow-uses-lock.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check-workflow-uses-lock.sh b/scripts/check-workflow-uses-lock.sh index 695ebcf..d033f66 100755 --- a/scripts/check-workflow-uses-lock.sh +++ b/scripts/check-workflow-uses-lock.sh @@ -20,7 +20,7 @@ for file in "$root"/.github/workflows/*.yml "$root"/.github/workflows/*.yaml; do rel=".github/workflows/$(basename "$file")" while IFS= read -r line; do # Comments (including workflow examples) do not match the anchored selector. - spec="$(printf '%s\n' "$line" | sed -nE 's/^[[:space:]]*uses:[[:space:]]*([^[:space:]#]+).*$/\1/p')" + spec="$(printf '%s\n' "$line" | sed -nE 's/^[[:space:]]*(-[[:space:]]*)?uses:[[:space:]]*([^[:space:]#]+).*$/\2/p')" [ -n "$spec" ] || continue checked=$((checked + 1)) case "$spec" in