Skip to content

Commit 35831ac

Browse files
authored
Merge pull request #86 from taras/security/hardening
security(ci): harden workflow supply chain and token handling
2 parents 82f16e1 + f57a919 commit 35831ac

8 files changed

Lines changed: 101 additions & 54 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v6
13+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
1414

15-
- uses: actions/setup-node@v4
15+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
1616
with:
1717
node-version: "22"
1818

19-
- uses: pnpm/action-setup@v4
19+
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
2020

2121
- run: pnpm install
2222

@@ -29,9 +29,9 @@ jobs:
2929
test-deno:
3030
runs-on: ubuntu-latest
3131
steps:
32-
- uses: actions/checkout@v6
32+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
3333

34-
- uses: denoland/setup-deno@v2.0.3
34+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
3535
with:
3636
deno-version: v2.9.1
3737

@@ -50,9 +50,9 @@ jobs:
5050
site:
5151
runs-on: ubuntu-latest
5252
steps:
53-
- uses: actions/checkout@v6
53+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
5454

55-
- uses: denoland/setup-deno@v2.0.3
55+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
5656
with:
5757
deno-version: v2.9.1
5858

@@ -70,13 +70,13 @@ jobs:
7070
test-node:
7171
runs-on: ubuntu-latest
7272
steps:
73-
- uses: actions/checkout@v6
73+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
7474

75-
- uses: actions/setup-node@v4
75+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
7676
with:
7777
node-version: "22"
7878

79-
- uses: pnpm/action-setup@v4
79+
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
8080

8181
- run: pnpm install
8282

@@ -89,9 +89,9 @@ jobs:
8989
test-bun:
9090
runs-on: ubuntu-latest
9191
steps:
92-
- uses: actions/checkout@v6
92+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
9393

94-
- uses: oven-sh/setup-bun@v2
94+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
9595

9696
- run: bun install
9797

‎.github/workflows/deploy.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
if: ${{ vars.DENO_DEPLOY_PROJECT != '' }}
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v6
26+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2727

28-
- uses: denoland/setup-deno@v2
28+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
2929
with:
3030
deno-version: v2.9.1
3131

@@ -37,7 +37,7 @@ jobs:
3737
working-directory: site
3838

3939
- name: Deploy to Deno Deploy
40-
uses: denoland/deployctl@v1
40+
uses: denoland/deployctl@35381c73621e1731268f80e51b54718d086f1e64 # v1
4141
with:
4242
project: ${{ vars.DENO_DEPLOY_PROJECT }}
4343
entrypoint: server-entry.js

‎.github/workflows/publish-one.yml‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ permissions:
2323
jobs:
2424
publish:
2525
runs-on: ubuntu-latest
26+
# Environment protection rules (required reviewers, v* tag-only deployment
27+
# rule) gate every publish; the npm trusted publisher is also bound to this
28+
# environment name, so npm rejects OIDC tokens minted outside it.
29+
environment: npm-publish
2630
env:
2731
# @effectionx/* peer-depend on effection `^3 || ^4`, which npm won't match
2832
# against the pinned 4.x prerelease during dnt's install step.
@@ -31,14 +35,14 @@ jobs:
3135
# Reusable workflows run at the caller's commit, so the default checkout
3236
# ref (github.sha) is the tag's commit on a tag push and the dispatched
3337
# branch's HEAD on a manual run — no explicit ref needed.
34-
- uses: actions/checkout@v6
38+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
3539

36-
- uses: denoland/setup-deno@v2
40+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
3741
with:
3842
deno-version: v2.9.1
3943

4044
# Node 24 ships npm >= 11.5, required for OIDC trusted publishing to npm.
41-
- uses: actions/setup-node@v4
45+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
4246
with:
4347
node-version: 24
4448
registry-url: https://registry.npmjs.org
@@ -56,9 +60,18 @@ jobs:
5660
echo "build failed after 4 attempts" >&2
5761
exit 1
5862
63+
# Skip an already-published version so re-running a tag's workflow (or
64+
# tagging a version that was hand-bootstrapped) is idempotent instead of
65+
# failing on npm's no-republish rule.
5966
- name: Publish to npm
60-
run: npm publish --access public
6167
working-directory: ${{ inputs.package }}/npm
68+
run: |
69+
NAME="$(node -p "require('./package.json').name")"
70+
if npm view "$NAME@${{ inputs.version }}" version >/dev/null 2>&1; then
71+
echo "$NAME@${{ inputs.version }} is already on npm — skipping"
72+
else
73+
npm publish --access public
74+
fi
6275
6376
- name: Publish to JSR (best-effort)
6477
run: deno publish --allow-dirty || echo "JSR publish skipped/failed (secondary registry)"

‎.github/workflows/release.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ jobs:
3434
# For a tag push, github.ref is the tag. For workflow_dispatch, check out
3535
# the requested tag explicitly so the built revision matches the release
3636
# name (checkout fails if the tag does not exist — fail closed).
37-
- uses: actions/checkout@v6
37+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
3838
with:
3939
ref: ${{ github.event.inputs.tag || github.ref }}
4040

41-
- uses: denoland/setup-deno@v2
41+
- uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb # v2.0.3
4242
with:
4343
deno-version: v2.9.1
4444

@@ -54,7 +54,7 @@ jobs:
5454
cli/src/cli.ts
5555
5656
- name: Upload build artifact
57-
uses: actions/upload-artifact@v4
57+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
5858
with:
5959
name: ${{ matrix.artifact }}
6060
path: dist/${{ matrix.artifact }}
@@ -66,7 +66,7 @@ jobs:
6666
runs-on: ubuntu-latest
6767
steps:
6868
- name: Download all binaries
69-
uses: actions/download-artifact@v4
69+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
7070
with:
7171
path: dist
7272
merge-multiple: true
@@ -76,7 +76,7 @@ jobs:
7676
run: sha256sum xmd-* > checksums.txt
7777

7878
- name: Publish to GitHub Release
79-
uses: softprops/action-gh-release@v2
79+
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
8080
with:
8181
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
8282
draft: false

‎.github/workflows/repo-analysis.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ jobs:
2424
contents: read
2525
issues: write
2626
steps:
27-
- uses: actions/checkout@v6
27+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2828
with:
2929
ref: ${{ inputs.ref }}
3030
fetch-depth: 0
3131

32+
# Version-pinned so a new (or compromised) release cannot silently change
33+
# analysis behavior; bump the pin as part of each release.
3234
- name: Install xmd release binary
3335
run: |
34-
curl -fsSL https://executable.md/install.sh | sh
36+
curl -fsSL https://executable.md/install.sh | XMD_VERSION=v0.2.0 sh
3537
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
3638
3739
- name: Run repo analysis
@@ -71,7 +73,7 @@ jobs:
7173
7274
- name: Upload analysis artifacts
7375
if: always()
74-
uses: actions/upload-artifact@v7
76+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
7577
with:
7678
name: ${{ inputs.report_name }}-${{ github.sha }}
7779
path: |

‎.github/workflows/review.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ jobs:
1111
pull-requests: write
1212
contents: read
1313
steps:
14-
- uses: actions/checkout@v6
14+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
1515
with:
1616
fetch-depth: 0
1717

18+
# Version-pinned so a new (or compromised) release cannot silently change
19+
# PR-review behavior; bump the pin as part of each release.
1820
- name: Install xmd release binary
1921
run: |
20-
curl -fsSL https://executable.md/install.sh | sh
22+
curl -fsSL https://executable.md/install.sh | XMD_VERSION=v0.2.0 sh
2123
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
2224
2325
- name: Run review
@@ -46,7 +48,7 @@ jobs:
4648
4749
- name: Upload journal
4850
if: always()
49-
uses: actions/upload-artifact@v7
51+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
5052
with:
5153
name: review-journal-${{ github.event.pull_request.head.sha }}
5254
path: .reviews/journal.jsonl

‎.reviews/components/EnsureOxlint.md‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ inputs:
33
dir:
44
type: string
55
default: ".reviews/.oxlint"
6-
oxlintTag:
7-
type: string
8-
default: "apps_v1.74.0"
9-
tsgolintVersion:
10-
type: string
11-
default: "0.25.0"
126
---
137

148
```bash silent exec
15-
# pipefail so a failed download (curl -f) aborts the block instead of being
16-
# masked by tar — provisioning must fail loudly, never silently degrade the
17-
# review. The workflow guards on the resulting binaries (see review.yml).
9+
# Provisions the pinned oxlint + tsgolint binaries with mandatory sha256
10+
# verification, failing closed — a failed or tampered download must abort the
11+
# review, never silently degrade it. Version pins live next to their hashes so
12+
# neither can change without the other. The workflow guards on the resulting
13+
# binaries (see review.yml).
1814
set -euo pipefail
1915
DIR="{dir}"
20-
OXLINT_TAG="{oxlintTag}"
21-
TSGOLINT_VERSION="{tsgolintVersion}"
16+
OXLINT_TAG="apps_v1.74.0"
17+
TSGOLINT_VERSION="0.25.0"
2218
mkdir -p "$DIR"
2319

2420
os="$(uname -s)"
@@ -34,10 +30,35 @@ case "$arch" in
3430
*) echo "EnsureOxlint: unsupported arch $arch" >&2; exit 1 ;;
3531
esac
3632

33+
case "${ox_arch}-${ox_os}" in
34+
aarch64-apple-darwin) ox_sha="768a2d00e7e0a95cbf89837086f475d25dc1a1ba605b8831fb5a1db6d590a643" ;;
35+
x86_64-apple-darwin) ox_sha="04ae38d56ae4990ac96320c03f05f38cf1103b5fe64b08cd7203b87e767b45b4" ;;
36+
aarch64-unknown-linux-gnu) ox_sha="ced0d2433bda2b4295e1ab93b40c3f24224713c32a44e13abcda656590dba1cb" ;;
37+
x86_64-unknown-linux-gnu) ox_sha="fd3ed5d2dc55ab6f7a243583c69dd5da4ac97cd1f6e10321225ca6343c9451a9" ;;
38+
esac
39+
case "${tg_os}-${tg_arch}" in
40+
darwin-arm64) tg_sha="3ad51d1b88070b491b81a4f5c6169148914127b9da65f8087823b25568431e1e" ;;
41+
darwin-x64) tg_sha="6b78caa20db383c055cead96724aeafab3cd277b00b1f95c6f56b4bfcf22fd60" ;;
42+
linux-arm64) tg_sha="20bcbab4bb37dd396102566740ee39e67d1e3d16d06096802180426c022bc414" ;;
43+
linux-x64) tg_sha="f6ea083842395d7439eadbbbf380f23793a1fa890fbda92013ee0f6033e75630" ;;
44+
esac
45+
46+
if command -v sha256sum >/dev/null 2>&1; then sha_cmd="sha256sum"; else sha_cmd="shasum -a 256"; fi
47+
48+
verify() {
49+
actual="$($sha_cmd "$1" | awk '{print $1}')"
50+
if [ "$actual" != "$2" ]; then
51+
echo "EnsureOxlint: checksum mismatch for $1 (expected $2, got $actual)" >&2
52+
exit 1
53+
fi
54+
}
55+
3756
# oxlint: standalone binary from the oxc release (no Node/npm needed).
3857
if [ ! -x "$DIR/oxlint" ]; then
3958
tmp="$(mktemp -d)"
40-
curl -fsSL "https://github.com/oxc-project/oxc/releases/download/${OXLINT_TAG}/oxlint-${ox_arch}-${ox_os}.tar.gz" | tar xz -C "$tmp"
59+
curl -fsSL -o "$tmp/oxlint.tar.gz" "https://github.com/oxc-project/oxc/releases/download/${OXLINT_TAG}/oxlint-${ox_arch}-${ox_os}.tar.gz"
60+
verify "$tmp/oxlint.tar.gz" "$ox_sha"
61+
tar xz -C "$tmp" -f "$tmp/oxlint.tar.gz"
4162
mv "$tmp/oxlint-${ox_arch}-${ox_os}" "$DIR/oxlint"
4263
chmod +x "$DIR/oxlint"
4364
rm -rf "$tmp"
@@ -46,7 +67,9 @@ fi
4667
# tsgolint (type-aware engine): npm-only, so pull the platform tarball directly.
4768
if [ ! -x "$DIR/tsgolint" ]; then
4869
tmp="$(mktemp -d)"
49-
curl -fsSL "https://registry.npmjs.org/@oxlint-tsgolint/${tg_os}-${tg_arch}/-/${tg_os}-${tg_arch}-${TSGOLINT_VERSION}.tgz" | tar xz -C "$tmp"
70+
curl -fsSL -o "$tmp/tsgolint.tgz" "https://registry.npmjs.org/@oxlint-tsgolint/${tg_os}-${tg_arch}/-/${tg_os}-${tg_arch}-${TSGOLINT_VERSION}.tgz"
71+
verify "$tmp/tsgolint.tgz" "$tg_sha"
72+
tar xz -C "$tmp" -f "$tmp/tsgolint.tgz"
5073
mv "$tmp/package/tsgolint" "$DIR/tsgolint"
5174
chmod +x "$DIR/tsgolint"
5275
rm -rf "$tmp"

‎.reviews/components/GitHubComment.md‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ inputs:
44
---
55

66
```ts eval
7+
// GITHUB_TOKEN is read inline at each call site, never assigned to a binding:
8+
// eval bindings are journaled, and the journal is uploaded as a CI artifact.
79
const content = yield* renderChildren();
810
const body = marker + "\n" + content.trim();
911

10-
const token = process.env.GITHUB_TOKEN;
1112
const repo = process.env.GITHUB_REPOSITORY;
1213
const prNumber = process.env.PR_NUMBER;
1314
const [owner, name] = repo.split("/");
1415
const api = `https://api.github.com/repos/${owner}/${name}`;
1516

16-
const headers = {
17-
"Authorization": `Bearer ${token}`,
18-
"Accept": "application/vnd.github+json",
19-
};
20-
21-
const commentsResult = yield* fetch(
22-
`${api}/issues/${prNumber}/comments`, { headers }
23-
)
17+
const commentsResult = yield* fetch(`${api}/issues/${prNumber}/comments`, {
18+
headers: {
19+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`,
20+
"Accept": "application/vnd.github+json",
21+
},
22+
})
2423
.expect()
2524
.json();
2625

@@ -31,13 +30,21 @@ const existing = commentsResult.find(c =>
3130
if (existing) {
3231
yield* fetch(`${api}/issues/comments/${existing.id}`, {
3332
method: "PATCH",
34-
headers: { ...headers, "Content-Type": "application/json" },
33+
headers: {
34+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`,
35+
"Accept": "application/vnd.github+json",
36+
"Content-Type": "application/json",
37+
},
3538
body: JSON.stringify({ body }),
3639
}).expect();
3740
} else {
3841
yield* fetch(`${api}/issues/${prNumber}/comments`, {
3942
method: "POST",
40-
headers: { ...headers, "Content-Type": "application/json" },
43+
headers: {
44+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`,
45+
"Accept": "application/vnd.github+json",
46+
"Content-Type": "application/json",
47+
},
4148
body: JSON.stringify({ body }),
4249
}).expect();
4350
}

0 commit comments

Comments
 (0)