@gadicc/loom 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.loom-source-manifest.json +3 -1
- package/README.md +5 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +2 -0
- package/esm/src/cli/mod.js.map +1 -1
- package/esm/src/release/githubOidc.d.ts +20 -0
- package/esm/src/release/githubOidc.d.ts.map +1 -0
- package/esm/src/release/githubOidc.js +175 -0
- package/esm/src/release/githubOidc.js.map +1 -0
- package/esm/src/release/mod.d.ts +2 -0
- package/esm/src/release/mod.d.ts.map +1 -0
- package/esm/src/release/mod.js +2 -0
- package/esm/src/release/mod.js.map +1 -0
- package/package.json +10 -2
- package/skills/loom/references/release-trusted-sources.md +38 -0
- package/source/src/cli/mod.ts +2 -0
- package/source/src/release/githubOidc.ts +202 -0
- package/source/src/release/mod.ts +4 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Explicit inputs for GitHub Actions HTTP checks through Vercel Trusted Sources. */
|
|
2
|
+
export interface GithubActionsOidcFetchOptions {
|
|
3
|
+
/** Exact HTTPS origin already verified against the deployment provider by the app. */
|
|
4
|
+
origin: string;
|
|
5
|
+
/** Must match the audience in the app's reviewed Trusted Sources rule. */
|
|
6
|
+
audience: string;
|
|
7
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
8
|
+
/** Write each complete workflow command as a line to the runner's stdout. */
|
|
9
|
+
writeWorkflowCommand: (command: string) => void;
|
|
10
|
+
fetch?: typeof globalThis.fetch;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create read-only HTTP checks scoped to one provider-verified HTTPS origin.
|
|
15
|
+
* Requests a masked GitHub identity, coalesces concurrent acquisition and refreshes
|
|
16
|
+
* before expiry. Tokens never leave this closure or follow redirects. There is no
|
|
17
|
+
* bypass-secret fallback. Vercel, not this helper, verifies signature and policy.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createGithubActionsOidcFetch(options: GithubActionsOidcFetchOptions): (path: string | URL, init?: RequestInit) => Promise<Response>;
|
|
20
|
+
//# sourceMappingURL=githubOidc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubOidc.d.ts","sourceRoot":"","sources":["../../../source/src/release/githubOidc.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,WAAW,6BAA6B;IAC5C,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAClD,6EAA6E;IAC7E,oBAAoB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAuCD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,6BAA6B,IAyGpC,MAAM,MAAM,GAAG,GAAG,EAClB,OAAM,WAAgB,KACrB,OAAO,CAAC,QAAQ,CAAC,CAqCrB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
const header = "x-vercel-trusted-oidc-idp-token";
|
|
2
|
+
const issuer = "https://token.actions.githubusercontent.com";
|
|
3
|
+
const maxBody = 65_536;
|
|
4
|
+
async function readJson(response) {
|
|
5
|
+
const reader = response.body?.getReader();
|
|
6
|
+
if (!reader)
|
|
7
|
+
throw new Error("Missing response body");
|
|
8
|
+
const chunks = [];
|
|
9
|
+
let size = 0;
|
|
10
|
+
try {
|
|
11
|
+
for (;;) {
|
|
12
|
+
const { done, value } = await reader.read();
|
|
13
|
+
if (done)
|
|
14
|
+
break;
|
|
15
|
+
size += value.length;
|
|
16
|
+
if (size > maxBody)
|
|
17
|
+
throw new Error("Oversized response");
|
|
18
|
+
chunks.push(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
await reader.cancel();
|
|
23
|
+
reader.releaseLock();
|
|
24
|
+
}
|
|
25
|
+
const bytes = new Uint8Array(size);
|
|
26
|
+
let offset = 0;
|
|
27
|
+
for (const chunk of chunks) {
|
|
28
|
+
bytes.set(chunk, offset);
|
|
29
|
+
offset += chunk.length;
|
|
30
|
+
}
|
|
31
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
32
|
+
}
|
|
33
|
+
function object(value) {
|
|
34
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
35
|
+
throw new Error("Invalid identity response");
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create read-only HTTP checks scoped to one provider-verified HTTPS origin.
|
|
41
|
+
* Requests a masked GitHub identity, coalesces concurrent acquisition and refreshes
|
|
42
|
+
* before expiry. Tokens never leave this closure or follow redirects. There is no
|
|
43
|
+
* bypass-secret fallback. Vercel, not this helper, verifies signature and policy.
|
|
44
|
+
*/
|
|
45
|
+
export function createGithubActionsOidcFetch(options) {
|
|
46
|
+
const audience = options.audience;
|
|
47
|
+
let origin;
|
|
48
|
+
let endpoint;
|
|
49
|
+
const requestToken = options.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
50
|
+
try {
|
|
51
|
+
origin = new URL(options.origin);
|
|
52
|
+
endpoint = new URL(options.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "");
|
|
53
|
+
if (origin.protocol !== "https:" ||
|
|
54
|
+
origin.username ||
|
|
55
|
+
origin.password ||
|
|
56
|
+
origin.pathname !== "/" ||
|
|
57
|
+
origin.search ||
|
|
58
|
+
origin.hash ||
|
|
59
|
+
origin.port ||
|
|
60
|
+
options.env.GITHUB_ACTIONS !== "true" ||
|
|
61
|
+
!requestToken ||
|
|
62
|
+
/[\r\n]/.test(requestToken) ||
|
|
63
|
+
endpoint.protocol !== "https:" ||
|
|
64
|
+
endpoint.username ||
|
|
65
|
+
endpoint.password ||
|
|
66
|
+
endpoint.port ||
|
|
67
|
+
endpoint.hash ||
|
|
68
|
+
!endpoint.hostname.endsWith(".actions.githubusercontent.com") ||
|
|
69
|
+
!audience ||
|
|
70
|
+
/[\r\n]/.test(audience))
|
|
71
|
+
throw new Error("Invalid configuration");
|
|
72
|
+
endpoint.searchParams.set("audience", audience);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new Error("GitHub OIDC requires a verified HTTPS origin, audience and Actions identity endpoint");
|
|
76
|
+
}
|
|
77
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
78
|
+
const now = options.now ?? Date.now;
|
|
79
|
+
function mask(value) {
|
|
80
|
+
options.writeWorkflowCommand(`::add-mask::${value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A")}`);
|
|
81
|
+
}
|
|
82
|
+
mask(requestToken);
|
|
83
|
+
let cached;
|
|
84
|
+
let pending;
|
|
85
|
+
async function acquire() {
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetchImpl(endpoint, {
|
|
88
|
+
headers: {
|
|
89
|
+
Authorization: `Bearer ${requestToken}`,
|
|
90
|
+
Accept: "application/json",
|
|
91
|
+
},
|
|
92
|
+
redirect: "error",
|
|
93
|
+
cache: "no-store",
|
|
94
|
+
signal: AbortSignal.timeout(30_000),
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok)
|
|
97
|
+
throw new Error("Identity request denied");
|
|
98
|
+
const token = object(await readJson(response)).value;
|
|
99
|
+
if (typeof token !== "string" ||
|
|
100
|
+
!token ||
|
|
101
|
+
token.length > 32_768 ||
|
|
102
|
+
/[\r\n]/.test(token)) {
|
|
103
|
+
throw new Error("Invalid identity token");
|
|
104
|
+
}
|
|
105
|
+
mask(token);
|
|
106
|
+
const segments = token.split(".");
|
|
107
|
+
if (segments.length !== 3 ||
|
|
108
|
+
segments.some((part) => !/^[A-Za-z0-9_-]+$/.test(part))) {
|
|
109
|
+
throw new Error("Invalid identity token");
|
|
110
|
+
}
|
|
111
|
+
const claims = object(JSON.parse(atob(segments[1].replaceAll("-", "+").replaceAll("_", "/"))));
|
|
112
|
+
// Cache hints and configuration sanity only; these are not signature verification.
|
|
113
|
+
if (claims.iss !== issuer ||
|
|
114
|
+
claims.aud !== audience ||
|
|
115
|
+
typeof claims.exp !== "number" ||
|
|
116
|
+
!Number.isSafeInteger(claims.exp) ||
|
|
117
|
+
claims.exp * 1000 <= now() + 30_000) {
|
|
118
|
+
throw new Error("Invalid identity claims");
|
|
119
|
+
}
|
|
120
|
+
return { token, expires: claims.exp * 1000 };
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Transport exceptions can contain request headers. Never expose their cause.
|
|
124
|
+
throw new Error("GitHub OIDC token acquisition failed");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function token() {
|
|
128
|
+
if (cached && cached.expires > now() + 30_000)
|
|
129
|
+
return cached.token;
|
|
130
|
+
pending ??= acquire();
|
|
131
|
+
try {
|
|
132
|
+
cached = await pending;
|
|
133
|
+
return cached.token;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
pending = undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return async (path, init = {}) => {
|
|
140
|
+
let destination;
|
|
141
|
+
const headers = new Headers(init.headers);
|
|
142
|
+
try {
|
|
143
|
+
destination = new URL(path, origin);
|
|
144
|
+
if (destination.origin !== origin.origin ||
|
|
145
|
+
destination.username ||
|
|
146
|
+
destination.password ||
|
|
147
|
+
destination.hash ||
|
|
148
|
+
(init.method && !["GET", "HEAD"].includes(init.method.toUpperCase())) ||
|
|
149
|
+
init.body ||
|
|
150
|
+
(init.redirect && !["manual", "error"].includes(init.redirect)) ||
|
|
151
|
+
headers.has(header) ||
|
|
152
|
+
headers.has("x-vercel-protection-bypass")) {
|
|
153
|
+
throw new Error("Invalid destination or request");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
throw new Error("OIDC checks require a read-only request to the verified origin without redirects or bypass headers");
|
|
158
|
+
}
|
|
159
|
+
headers.set(header, await token());
|
|
160
|
+
try {
|
|
161
|
+
return await fetchImpl(destination, {
|
|
162
|
+
...init,
|
|
163
|
+
headers,
|
|
164
|
+
method: init.method ?? "GET",
|
|
165
|
+
redirect: init.redirect ?? "manual",
|
|
166
|
+
cache: "no-store",
|
|
167
|
+
signal: init.signal ?? AbortSignal.timeout(30_000),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
throw new Error("OIDC deployment HTTP check failed");
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=githubOidc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubOidc.js","sourceRoot":"","sources":["../../../source/src/release/githubOidc.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,GAAG,iCAAiC,CAAC;AACjD,MAAM,MAAM,GAAG,6CAA6C,CAAC;AAC7D,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,KAAK,UAAU,QAAQ,CAAC,QAAkB;IACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC;IAC1C,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtD,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,CAAC;QACH,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAChB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;YACrB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appings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,KAAK,6BAA6B,GACnC,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../source/src/release/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,GAE7B,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadicc/loom",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Shared helpers and verification tooling for Next.js applications.",
|
|
5
5
|
"homepage": "https://github.com/gadicc/loom#readme",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/gadicc/loom/issues"
|
|
12
12
|
},
|
|
13
13
|
"loom": {
|
|
14
|
-
"gitCommit": "
|
|
14
|
+
"gitCommit": "933e6a54831bf15b6d18539bfbb588551e2e9e58"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "./esm/mod.js",
|
|
@@ -89,6 +89,10 @@
|
|
|
89
89
|
"types": "./esm/src/next/secrets/mod.d.ts",
|
|
90
90
|
"import": "./esm/src/next/secrets/mod.js"
|
|
91
91
|
},
|
|
92
|
+
"./src/release/mod.js": {
|
|
93
|
+
"types": "./esm/src/release/mod.d.ts",
|
|
94
|
+
"import": "./esm/src/release/mod.js"
|
|
95
|
+
},
|
|
92
96
|
"./src/secrets/legacy.js": {
|
|
93
97
|
"types": "./esm/src/secrets/legacy.d.ts",
|
|
94
98
|
"import": "./esm/src/secrets/legacy.js"
|
|
@@ -110,6 +114,10 @@
|
|
|
110
114
|
"types": "./esm/mod.d.ts",
|
|
111
115
|
"import": "./esm/mod.js"
|
|
112
116
|
},
|
|
117
|
+
"./release": {
|
|
118
|
+
"types": "./esm/src/release/mod.d.ts",
|
|
119
|
+
"import": "./esm/src/release/mod.js"
|
|
120
|
+
},
|
|
113
121
|
"./client-data": {
|
|
114
122
|
"types": "./esm/src/clientData/mod.d.ts",
|
|
115
123
|
"import": "./esm/src/clientData/mod.js"
|
|
@@ -50,6 +50,44 @@ Keep existing bypass-secret workflows working until each app deliberately adopts
|
|
|
50
50
|
this setup. Publishing a newer Loom package does not change another app's Vercel
|
|
51
51
|
settings or workflow.
|
|
52
52
|
|
|
53
|
+
## Shared HTTP checks
|
|
54
|
+
|
|
55
|
+
`@gadicc/loom/release` provides `createGithubActionsOidcFetch` for GET/HEAD
|
|
56
|
+
checks. First verify the immutable origin against the provider's exact project,
|
|
57
|
+
owner and artifact/source metadata in the app. Then create one client per origin:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { createGithubActionsOidcFetch } from "@gadicc/loom/release";
|
|
61
|
+
|
|
62
|
+
const check = createGithubActionsOidcFetch({
|
|
63
|
+
origin: verifiedDeploymentOrigin,
|
|
64
|
+
audience: "https://github.com/your-owner", // from the reviewed trust proposal
|
|
65
|
+
env: process.env,
|
|
66
|
+
writeWorkflowCommand: (command) => console.log(command),
|
|
67
|
+
});
|
|
68
|
+
const response = await check("/api/ready");
|
|
69
|
+
// The app must assert its expected status, content type and readiness body.
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The job needs `permissions: { contents: read, id-token: write }` and the exact
|
|
73
|
+
GitHub environment in its policy. Identity capability is job-scoped, including
|
|
74
|
+
other steps in that job; keep dependencies/actions pinned and secrets scoped.
|
|
75
|
+
The helper masks the request credential and JWT before use, coalesces concurrent
|
|
76
|
+
identity requests and refreshes 30 seconds before expiry. It refuses other
|
|
77
|
+
origins, redirects that would follow, caller-supplied OIDC/bypass headers and
|
|
78
|
+
non-read-only requests. It returns manual redirect responses for app assertions,
|
|
79
|
+
uses bounded timeouts and sanitizes transport errors. It has no bypass fallback.
|
|
80
|
+
JWT decoding only supplies cache/sanity hints; Vercel verifies signature and all
|
|
81
|
+
configured identity claims.
|
|
82
|
+
|
|
83
|
+
Test real positive access and real denial (for example a token from a job with
|
|
84
|
+
no GitHub environment, or a wrong audience) before deleting the old bypass.
|
|
85
|
+
Assert anonymous application sessions separately. Do not reuse a bootstrap smoke
|
|
86
|
+
that expected an inactive database after that database has been activated.
|
|
87
|
+
Keep deploy/migrate/promote operations out of a read-only credential acceptance
|
|
88
|
+
job. Browser routing and non-GitHub local access need their own adapters; this
|
|
89
|
+
helper does not grant either capability.
|
|
90
|
+
|
|
53
91
|
References:
|
|
54
92
|
[Vercel Trusted Sources](https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/trusted-sources),
|
|
55
93
|
[GitHub OIDC claims](https://docs.github.com/en/actions/reference/security/oidc).
|
package/source/src/cli/mod.ts
CHANGED
|
@@ -1395,6 +1395,8 @@ const ENV_LOADER_SCAN_EXTENSIONS = new Set([
|
|
|
1395
1395
|
]);
|
|
1396
1396
|
const ENV_LOADER_SCAN_IGNORED_DIRS = new Set([
|
|
1397
1397
|
".agents",
|
|
1398
|
+
// Managed local package copies contain Loom implementation, never app source.
|
|
1399
|
+
".loom",
|
|
1398
1400
|
".git",
|
|
1399
1401
|
".next",
|
|
1400
1402
|
".turbo",
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/** Explicit inputs for GitHub Actions HTTP checks through Vercel Trusted Sources. */
|
|
2
|
+
export interface GithubActionsOidcFetchOptions {
|
|
3
|
+
/** Exact HTTPS origin already verified against the deployment provider by the app. */
|
|
4
|
+
origin: string;
|
|
5
|
+
/** Must match the audience in the app's reviewed Trusted Sources rule. */
|
|
6
|
+
audience: string;
|
|
7
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
8
|
+
/** Write each complete workflow command as a line to the runner's stdout. */
|
|
9
|
+
writeWorkflowCommand: (command: string) => void;
|
|
10
|
+
fetch?: typeof globalThis.fetch;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const header = "x-vercel-trusted-oidc-idp-token";
|
|
15
|
+
const issuer = "https://token.actions.githubusercontent.com";
|
|
16
|
+
const maxBody = 65_536;
|
|
17
|
+
|
|
18
|
+
async function readJson(response: Response): Promise<unknown> {
|
|
19
|
+
const reader = response.body?.getReader();
|
|
20
|
+
if (!reader) throw new Error("Missing response body");
|
|
21
|
+
const chunks: Uint8Array[] = [];
|
|
22
|
+
let size = 0;
|
|
23
|
+
try {
|
|
24
|
+
for (;;) {
|
|
25
|
+
const { done, value } = await reader.read();
|
|
26
|
+
if (done) break;
|
|
27
|
+
size += value.length;
|
|
28
|
+
if (size > maxBody) throw new Error("Oversized response");
|
|
29
|
+
chunks.push(value);
|
|
30
|
+
}
|
|
31
|
+
} finally {
|
|
32
|
+
await reader.cancel();
|
|
33
|
+
reader.releaseLock();
|
|
34
|
+
}
|
|
35
|
+
const bytes = new Uint8Array(size);
|
|
36
|
+
let offset = 0;
|
|
37
|
+
for (const chunk of chunks) {
|
|
38
|
+
bytes.set(chunk, offset);
|
|
39
|
+
offset += chunk.length;
|
|
40
|
+
}
|
|
41
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function object(value: unknown): Record<string, unknown> {
|
|
45
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
46
|
+
throw new Error("Invalid identity response");
|
|
47
|
+
}
|
|
48
|
+
return value as Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create read-only HTTP checks scoped to one provider-verified HTTPS origin.
|
|
53
|
+
* Requests a masked GitHub identity, coalesces concurrent acquisition and refreshes
|
|
54
|
+
* before expiry. Tokens never leave this closure or follow redirects. There is no
|
|
55
|
+
* bypass-secret fallback. Vercel, not this helper, verifies signature and policy.
|
|
56
|
+
*/
|
|
57
|
+
export function createGithubActionsOidcFetch(
|
|
58
|
+
options: GithubActionsOidcFetchOptions,
|
|
59
|
+
) {
|
|
60
|
+
const audience = options.audience;
|
|
61
|
+
let origin: URL;
|
|
62
|
+
let endpoint: URL;
|
|
63
|
+
const requestToken = options.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
64
|
+
try {
|
|
65
|
+
origin = new URL(options.origin);
|
|
66
|
+
endpoint = new URL(options.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "");
|
|
67
|
+
if (
|
|
68
|
+
origin.protocol !== "https:" ||
|
|
69
|
+
origin.username ||
|
|
70
|
+
origin.password ||
|
|
71
|
+
origin.pathname !== "/" ||
|
|
72
|
+
origin.search ||
|
|
73
|
+
origin.hash ||
|
|
74
|
+
origin.port ||
|
|
75
|
+
options.env.GITHUB_ACTIONS !== "true" ||
|
|
76
|
+
!requestToken ||
|
|
77
|
+
/[\r\n]/.test(requestToken) ||
|
|
78
|
+
endpoint.protocol !== "https:" ||
|
|
79
|
+
endpoint.username ||
|
|
80
|
+
endpoint.password ||
|
|
81
|
+
endpoint.port ||
|
|
82
|
+
endpoint.hash ||
|
|
83
|
+
!endpoint.hostname.endsWith(".actions.githubusercontent.com") ||
|
|
84
|
+
!audience ||
|
|
85
|
+
/[\r\n]/.test(audience)
|
|
86
|
+
)
|
|
87
|
+
throw new Error("Invalid configuration");
|
|
88
|
+
endpoint.searchParams.set("audience", audience);
|
|
89
|
+
} catch {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"GitHub OIDC requires a verified HTTPS origin, audience and Actions identity endpoint",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
95
|
+
const now = options.now ?? Date.now;
|
|
96
|
+
function mask(value: string) {
|
|
97
|
+
options.writeWorkflowCommand(
|
|
98
|
+
`::add-mask::${value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A")}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
mask(requestToken);
|
|
102
|
+
let cached: { token: string; expires: number } | undefined;
|
|
103
|
+
let pending: Promise<{ token: string; expires: number }> | undefined;
|
|
104
|
+
async function acquire() {
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetchImpl(endpoint, {
|
|
107
|
+
headers: {
|
|
108
|
+
Authorization: `Bearer ${requestToken}`,
|
|
109
|
+
Accept: "application/json",
|
|
110
|
+
},
|
|
111
|
+
redirect: "error",
|
|
112
|
+
cache: "no-store",
|
|
113
|
+
signal: AbortSignal.timeout(30_000),
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) throw new Error("Identity request denied");
|
|
116
|
+
const token = object(await readJson(response)).value;
|
|
117
|
+
if (
|
|
118
|
+
typeof token !== "string" ||
|
|
119
|
+
!token ||
|
|
120
|
+
token.length > 32_768 ||
|
|
121
|
+
/[\r\n]/.test(token)
|
|
122
|
+
) {
|
|
123
|
+
throw new Error("Invalid identity token");
|
|
124
|
+
}
|
|
125
|
+
mask(token);
|
|
126
|
+
const segments = token.split(".");
|
|
127
|
+
if (
|
|
128
|
+
segments.length !== 3 ||
|
|
129
|
+
segments.some((part) => !/^[A-Za-z0-9_-]+$/.test(part))
|
|
130
|
+
) {
|
|
131
|
+
throw new Error("Invalid identity token");
|
|
132
|
+
}
|
|
133
|
+
const claims = object(
|
|
134
|
+
JSON.parse(atob(segments[1].replaceAll("-", "+").replaceAll("_", "/"))),
|
|
135
|
+
);
|
|
136
|
+
// Cache hints and configuration sanity only; these are not signature verification.
|
|
137
|
+
if (
|
|
138
|
+
claims.iss !== issuer ||
|
|
139
|
+
claims.aud !== audience ||
|
|
140
|
+
typeof claims.exp !== "number" ||
|
|
141
|
+
!Number.isSafeInteger(claims.exp) ||
|
|
142
|
+
claims.exp * 1000 <= now() + 30_000
|
|
143
|
+
) {
|
|
144
|
+
throw new Error("Invalid identity claims");
|
|
145
|
+
}
|
|
146
|
+
return { token, expires: claims.exp * 1000 };
|
|
147
|
+
} catch {
|
|
148
|
+
// Transport exceptions can contain request headers. Never expose their cause.
|
|
149
|
+
throw new Error("GitHub OIDC token acquisition failed");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function token() {
|
|
153
|
+
if (cached && cached.expires > now() + 30_000) return cached.token;
|
|
154
|
+
pending ??= acquire();
|
|
155
|
+
try {
|
|
156
|
+
cached = await pending;
|
|
157
|
+
return cached.token;
|
|
158
|
+
} finally {
|
|
159
|
+
pending = undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return async (
|
|
163
|
+
path: string | URL,
|
|
164
|
+
init: RequestInit = {},
|
|
165
|
+
): Promise<Response> => {
|
|
166
|
+
let destination: URL;
|
|
167
|
+
const headers = new Headers(init.headers);
|
|
168
|
+
try {
|
|
169
|
+
destination = new URL(path, origin);
|
|
170
|
+
if (
|
|
171
|
+
destination.origin !== origin.origin ||
|
|
172
|
+
destination.username ||
|
|
173
|
+
destination.password ||
|
|
174
|
+
destination.hash ||
|
|
175
|
+
(init.method && !["GET", "HEAD"].includes(init.method.toUpperCase())) ||
|
|
176
|
+
init.body ||
|
|
177
|
+
(init.redirect && !["manual", "error"].includes(init.redirect)) ||
|
|
178
|
+
headers.has(header) ||
|
|
179
|
+
headers.has("x-vercel-protection-bypass")
|
|
180
|
+
) {
|
|
181
|
+
throw new Error("Invalid destination or request");
|
|
182
|
+
}
|
|
183
|
+
} catch {
|
|
184
|
+
throw new Error(
|
|
185
|
+
"OIDC checks require a read-only request to the verified origin without redirects or bypass headers",
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
headers.set(header, await token());
|
|
189
|
+
try {
|
|
190
|
+
return await fetchImpl(destination, {
|
|
191
|
+
...init,
|
|
192
|
+
headers,
|
|
193
|
+
method: init.method ?? "GET",
|
|
194
|
+
redirect: init.redirect ?? "manual",
|
|
195
|
+
cache: "no-store",
|
|
196
|
+
signal: init.signal ?? AbortSignal.timeout(30_000),
|
|
197
|
+
});
|
|
198
|
+
} catch {
|
|
199
|
+
throw new Error("OIDC deployment HTTP check failed");
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|