@run402/functions 3.12.0 → 3.14.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/README.md +32 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +43 -43
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/types.d.ts +5 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +31 -38
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/jwt.d.ts +105 -10
- package/dist/lib/jwt.d.ts.map +1 -1
- package/dist/lib/jwt.js +163 -28
- package/dist/lib/jwt.js.map +1 -1
- package/dist/lib/project-jwt-keys.d.ts +73 -0
- package/dist/lib/project-jwt-keys.d.ts.map +1 -0
- package/dist/lib/project-jwt-keys.js +169 -0
- package/dist/lib/project-jwt-keys.js.map +1 -0
- package/package.json +1 -1
package/dist/lib/jwt.d.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Minimal HS256/HS512 JWT sign + verify built directly on `node:crypto`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `lodash
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* Drop-in replacement for the subset of `jsonwebtoken` this codebase used
|
|
5
|
+
* (sign / verify / decode + TokenExpiredError + JwtPayload). Replaces the
|
|
6
|
+
* `jsonwebtoken` package and its transitive tree (`jws`, `jwa`,
|
|
7
|
+
* `ecdsa-sig-formatter`, `lodash.*`, `ms`, `semver`, `safe-buffer`) — the
|
|
8
|
+
* cryptographic primitive (HMAC) comes from `node:crypto`; the rest is JWT
|
|
9
|
+
* envelope handling per RFC 7519.
|
|
10
|
+
*
|
|
11
|
+
* VENDORED, KEPT IN SYNC WITH THE GATEWAY'S `packages/gateway/src/lib/jwt.ts`.
|
|
12
|
+
* Same file lineage; this copy had drifted to a pre-keyring version (238 lines
|
|
13
|
+
* vs 344 — no `VerificationKey`, no `verifyWithKey`, no kid-aware selection),
|
|
14
|
+
* which is why no deployed function at any version could verify a keyset. That
|
|
15
|
+
* gap is what blocked project-JWT rotation entirely: pushing a new key broke
|
|
16
|
+
* old tokens, pushing the old one changed nothing, and pushing a JWKS broke
|
|
17
|
+
* every version including the newest.
|
|
18
|
+
*
|
|
19
|
+
* The symmetric HMAC algorithms plus **ES256** are implemented. ES256 exists
|
|
20
|
+
* here so the project keyring can hold a key whose VERIFICATION material is
|
|
21
|
+
* safe to hand out: with an HMAC key, verify and sign are the same capability,
|
|
22
|
+
* so any consumer able to check a signature can forge one. RS/PS remain
|
|
23
|
+
* unsupported; for OIDC JWKS verification the gateway uses `jose` directly
|
|
24
|
+
* (see services/oidc-jwks.ts).
|
|
25
|
+
*
|
|
26
|
+
* The verifier's algorithm allowlist defaults to ["HS256"] and any token
|
|
27
|
+
* claiming a different `alg` is rejected before any cryptographic work —
|
|
28
|
+
* defence against the classic "alg=none" / algorithm-confusion attacks. A key
|
|
29
|
+
* only ever verifies a token whose `alg` matches its own, so an ES256 public
|
|
30
|
+
* key can never be pressed into service as HMAC key material (the specific
|
|
31
|
+
* confusion attack that asymmetric-alongside-symmetric invites).
|
|
11
32
|
*/
|
|
33
|
+
import { type KeyObject } from "node:crypto";
|
|
12
34
|
export interface JwtPayload {
|
|
13
35
|
[key: string]: unknown;
|
|
14
36
|
iat?: number;
|
|
@@ -19,16 +41,59 @@ export interface JwtPayload {
|
|
|
19
41
|
sub?: string;
|
|
20
42
|
jti?: string;
|
|
21
43
|
}
|
|
22
|
-
export type SupportedAlgorithm = "HS256" | "HS512";
|
|
44
|
+
export type SupportedAlgorithm = "HS256" | "HS512" | "ES256";
|
|
45
|
+
/** True for algorithms whose verification material is not signing material. */
|
|
46
|
+
export declare function isAsymmetricAlg(alg: string): alg is "ES256";
|
|
23
47
|
export interface SignOptions {
|
|
24
48
|
algorithm?: SupportedAlgorithm;
|
|
49
|
+
/** Seconds (number) or duration string (`"1h"`, `"15m"`, `"-1s"`). */
|
|
25
50
|
expiresIn?: string | number;
|
|
51
|
+
/** Skip auto-populating `iat`. */
|
|
26
52
|
noTimestamp?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Emit a `kid` header. Omitted entirely when unset, so legacy issuance keeps
|
|
55
|
+
* producing byte-identical bare `{alg,typ}` headers.
|
|
56
|
+
*/
|
|
57
|
+
kid?: string;
|
|
27
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* One symmetric verification key. `key` is the RAW HMAC key material: a legacy
|
|
61
|
+
* passphrase contributes `Buffer.from(passphrase, "utf8")`, a JWKS `oct` entry
|
|
62
|
+
* contributes `Buffer.from(k, "base64url")` — which are byte-identical for the
|
|
63
|
+
* same secret, so lifting a passphrase into a one-key JWKS is a no-op.
|
|
64
|
+
*
|
|
65
|
+
* `legacy: true` marks the single key eligible to verify tokens that carry NO
|
|
66
|
+
* `kid` header (what `deriveProjectKeys` emits today).
|
|
67
|
+
*/
|
|
68
|
+
export interface VerificationKey {
|
|
69
|
+
kid?: string;
|
|
70
|
+
/**
|
|
71
|
+
* HMAC key material for `HS*`.
|
|
72
|
+
*
|
|
73
|
+
* For `ES256` this is the SPKI DER of the PUBLIC key — never private
|
|
74
|
+
* material. It exists so the keyring's fingerprint and duplicate-material
|
|
75
|
+
* checks work identically across key types, and so nothing that digests or
|
|
76
|
+
* logs a key can reach a secret by doing so.
|
|
77
|
+
*/
|
|
78
|
+
key: Buffer;
|
|
79
|
+
alg: SupportedAlgorithm;
|
|
80
|
+
legacy?: boolean;
|
|
81
|
+
/** `ES256` verification material. Absent for `HS*`. */
|
|
82
|
+
publicKey?: KeyObject;
|
|
83
|
+
/**
|
|
84
|
+
* `ES256` signing material. Present ONLY on an entry configured with a
|
|
85
|
+
* private component; its absence is what makes a key verify-only, which the
|
|
86
|
+
* keyring relies on to refuse designating it as the signing key.
|
|
87
|
+
*/
|
|
88
|
+
privateKey?: KeyObject;
|
|
89
|
+
}
|
|
90
|
+
/** A bare passphrase (legacy) or an ordered verification keyset. */
|
|
91
|
+
export type SecretOrKeys = string | ReadonlyArray<VerificationKey>;
|
|
28
92
|
export interface VerifyOptions {
|
|
29
93
|
algorithms?: ReadonlyArray<SupportedAlgorithm>;
|
|
30
94
|
issuer?: string;
|
|
31
95
|
audience?: string | string[];
|
|
96
|
+
/** Seconds of slack applied to both `exp` and `nbf` checks. */
|
|
32
97
|
clockTolerance?: number;
|
|
33
98
|
}
|
|
34
99
|
export declare class JsonWebTokenError extends Error {
|
|
@@ -42,12 +107,42 @@ export declare class NotBeforeError extends JsonWebTokenError {
|
|
|
42
107
|
date: Date;
|
|
43
108
|
constructor(message: string, date: Date);
|
|
44
109
|
}
|
|
45
|
-
|
|
46
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Raised when a token names a `kid` no configured key provides. Declared here
|
|
112
|
+
* (after `JsonWebTokenError`) because `extends` is evaluated in source order.
|
|
113
|
+
*/
|
|
114
|
+
export declare class UnknownKeyIdError extends JsonWebTokenError {
|
|
115
|
+
kid: string;
|
|
116
|
+
constructor(kid: string);
|
|
117
|
+
}
|
|
118
|
+
export declare function sign(payload: object, secret: string | Buffer | KeyObject, options?: SignOptions): string;
|
|
119
|
+
/**
|
|
120
|
+
* Verify and report WHICH key matched.
|
|
121
|
+
*
|
|
122
|
+
* Key selection (mirrors the shipped gateway policy, and is deliberately
|
|
123
|
+
* stricter than PostgREST v12.2.3, which ignores `kid` entirely):
|
|
124
|
+
* - `kid` present and known -> verify against THAT key alone; a signature
|
|
125
|
+
* mismatch is an error, never a fallback.
|
|
126
|
+
* - `kid` present but unknown -> reject immediately, no HMAC work.
|
|
127
|
+
* - `kid` absent -> try only keys marked `legacy`.
|
|
128
|
+
*
|
|
129
|
+
* A bare-string `secret` keeps the legacy single-key behavior exactly.
|
|
130
|
+
*/
|
|
131
|
+
export declare function verifyWithKey<T = JwtPayload>(token: string, secretOrKeys: SecretOrKeys, options?: VerifyOptions): {
|
|
132
|
+
payload: T;
|
|
133
|
+
kid?: string;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Verify a token, returning only the payload. Accepts a legacy passphrase or a
|
|
137
|
+
* keyset; use `verifyWithKey` when the caller needs to know which key matched
|
|
138
|
+
* (legacy-usage telemetry during a rotation).
|
|
139
|
+
*/
|
|
140
|
+
export declare function verify<T = JwtPayload>(token: string, secretOrKeys: SecretOrKeys, options?: VerifyOptions): T;
|
|
47
141
|
export declare function decode<T = JwtPayload>(token: string): T | null;
|
|
48
142
|
declare const jwt: {
|
|
49
143
|
sign: typeof sign;
|
|
50
144
|
verify: typeof verify;
|
|
145
|
+
verifyWithKey: typeof verifyWithKey;
|
|
51
146
|
decode: typeof decode;
|
|
52
147
|
};
|
|
53
148
|
export default jwt;
|
package/dist/lib/jwt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/lib/jwt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/lib/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAyD,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpG,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CA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AED,qBAAa,cAAe,SAAQ,iBAAiB;IACnD,IAAI,EAAE,IAAI,CAAC;gBACC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKxC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,GAAG,EAAE,MAAM,CAAC;gBACA,GAAG,EAAE,MAAM;CAKxB;AA0CD,wBAAgB,IAAI,CAClB,OAAO,EAAE,MAAM,EAOf,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EACnC,OAAO,CAAC,EAAE,WAAW,GACpB,MAAM,CAuDR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,UAAU,EAC1C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,aAAa,GACtB;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAoH9B;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,UAAU,EACnC,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,aAAa,GACtB,CAAC,CAEH;AAED,wBAAgB,MAAM,CAAC,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAW9D;AAED,QAAA,MAAM,GAAG;;;;;CAA0C,CAAC;AACpD,eAAe,GAAG,CAAC"}
|
package/dist/lib/jwt.js
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Minimal HS256/HS512 JWT sign + verify built directly on `node:crypto`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `lodash
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* Drop-in replacement for the subset of `jsonwebtoken` this codebase used
|
|
5
|
+
* (sign / verify / decode + TokenExpiredError + JwtPayload). Replaces the
|
|
6
|
+
* `jsonwebtoken` package and its transitive tree (`jws`, `jwa`,
|
|
7
|
+
* `ecdsa-sig-formatter`, `lodash.*`, `ms`, `semver`, `safe-buffer`) — the
|
|
8
|
+
* cryptographic primitive (HMAC) comes from `node:crypto`; the rest is JWT
|
|
9
|
+
* envelope handling per RFC 7519.
|
|
10
|
+
*
|
|
11
|
+
* VENDORED, KEPT IN SYNC WITH THE GATEWAY'S `packages/gateway/src/lib/jwt.ts`.
|
|
12
|
+
* Same file lineage; this copy had drifted to a pre-keyring version (238 lines
|
|
13
|
+
* vs 344 — no `VerificationKey`, no `verifyWithKey`, no kid-aware selection),
|
|
14
|
+
* which is why no deployed function at any version could verify a keyset. That
|
|
15
|
+
* gap is what blocked project-JWT rotation entirely: pushing a new key broke
|
|
16
|
+
* old tokens, pushing the old one changed nothing, and pushing a JWKS broke
|
|
17
|
+
* every version including the newest.
|
|
18
|
+
*
|
|
19
|
+
* The symmetric HMAC algorithms plus **ES256** are implemented. ES256 exists
|
|
20
|
+
* here so the project keyring can hold a key whose VERIFICATION material is
|
|
21
|
+
* safe to hand out: with an HMAC key, verify and sign are the same capability,
|
|
22
|
+
* so any consumer able to check a signature can forge one. RS/PS remain
|
|
23
|
+
* unsupported; for OIDC JWKS verification the gateway uses `jose` directly
|
|
24
|
+
* (see services/oidc-jwks.ts).
|
|
25
|
+
*
|
|
26
|
+
* The verifier's algorithm allowlist defaults to ["HS256"] and any token
|
|
27
|
+
* claiming a different `alg` is rejected before any cryptographic work —
|
|
28
|
+
* defence against the classic "alg=none" / algorithm-confusion attacks. A key
|
|
29
|
+
* only ever verifies a token whose `alg` matches its own, so an ES256 public
|
|
30
|
+
* key can never be pressed into service as HMAC key material (the specific
|
|
31
|
+
* confusion attack that asymmetric-alongside-symmetric invites).
|
|
11
32
|
*/
|
|
12
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
33
|
+
import { createHmac, createSign, createVerify, timingSafeEqual } from "node:crypto";
|
|
34
|
+
/** True for algorithms whose verification material is not signing material. */
|
|
35
|
+
export function isAsymmetricAlg(alg) {
|
|
36
|
+
return alg === "ES256";
|
|
37
|
+
}
|
|
13
38
|
export class JsonWebTokenError extends Error {
|
|
14
39
|
constructor(message) {
|
|
15
40
|
super(message);
|
|
@@ -32,6 +57,18 @@ export class NotBeforeError extends JsonWebTokenError {
|
|
|
32
57
|
this.date = date;
|
|
33
58
|
}
|
|
34
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Raised when a token names a `kid` no configured key provides. Declared here
|
|
62
|
+
* (after `JsonWebTokenError`) because `extends` is evaluated in source order.
|
|
63
|
+
*/
|
|
64
|
+
export class UnknownKeyIdError extends JsonWebTokenError {
|
|
65
|
+
kid;
|
|
66
|
+
constructor(kid) {
|
|
67
|
+
super("unknown key id");
|
|
68
|
+
this.name = "UnknownKeyIdError";
|
|
69
|
+
this.kid = kid;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
35
72
|
function b64urlEncode(input) {
|
|
36
73
|
const buf = typeof input === "string" ? Buffer.from(input, "utf8") : input;
|
|
37
74
|
return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
@@ -68,14 +105,38 @@ function parseDurationSeconds(input) {
|
|
|
68
105
|
return Math.floor(n);
|
|
69
106
|
}
|
|
70
107
|
function hmacForAlg(alg) {
|
|
71
|
-
|
|
108
|
+
// Explicit rather than `=== "HS256" ? sha256 : sha512`: with ES256 in the
|
|
109
|
+
// union that fallback would silently HMAC an asymmetric key under sha512.
|
|
110
|
+
// Both call sites guard already; this makes the guard non-load-bearing.
|
|
111
|
+
if (alg === "HS256")
|
|
112
|
+
return "sha256";
|
|
113
|
+
if (alg === "HS512")
|
|
114
|
+
return "sha512";
|
|
115
|
+
throw new JsonWebTokenError(`${alg} is not an HMAC algorithm`);
|
|
72
116
|
}
|
|
73
|
-
export function sign(payload,
|
|
117
|
+
export function sign(payload,
|
|
118
|
+
// Accepts RAW key bytes as well as a passphrase. Callers that resolve a key
|
|
119
|
+
// through the keyring pass a Buffer, so they sign with the DECODED key rather
|
|
120
|
+
// than whatever string `JWT_SECRET` happens to hold — under a JWKS that string
|
|
121
|
+
// is the JSON document, and signing with it produces tokens nothing verifies.
|
|
122
|
+
// For ES256 the caller passes the private `KeyObject`; a Buffer is rejected,
|
|
123
|
+
// since raw bytes cannot be an EC private key here.
|
|
124
|
+
secret, options) {
|
|
74
125
|
const alg = options?.algorithm ?? "HS256";
|
|
75
|
-
if (alg !== "HS256" && alg !== "HS512") {
|
|
126
|
+
if (alg !== "HS256" && alg !== "HS512" && alg !== "ES256") {
|
|
76
127
|
throw new JsonWebTokenError(`Unsupported algorithm: ${alg}`);
|
|
77
128
|
}
|
|
78
|
-
|
|
129
|
+
const isKeyObject = typeof secret === "object" && secret !== null && !Buffer.isBuffer(secret);
|
|
130
|
+
if (alg === "ES256") {
|
|
131
|
+
if (!isKeyObject) {
|
|
132
|
+
throw new JsonWebTokenError("ES256 requires a private KeyObject");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (isKeyObject) {
|
|
136
|
+
throw new JsonWebTokenError(`${alg} requires raw key material, not a KeyObject`);
|
|
137
|
+
}
|
|
138
|
+
const isBuffer = Buffer.isBuffer(secret);
|
|
139
|
+
if (!isKeyObject && ((!isBuffer && typeof secret !== "string") || secret.length === 0)) {
|
|
79
140
|
throw new JsonWebTokenError("secretOrPrivateKey must be provided");
|
|
80
141
|
}
|
|
81
142
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
@@ -94,21 +155,48 @@ export function sign(payload, secret, options) {
|
|
|
94
155
|
const iatRef = typeof claims.iat === "number" ? claims.iat : Math.floor(Date.now() / 1000);
|
|
95
156
|
claims.exp = iatRef + offset;
|
|
96
157
|
}
|
|
97
|
-
|
|
158
|
+
// `kid` is omitted entirely when unset so legacy issuance keeps producing
|
|
159
|
+
// byte-identical bare `{alg,typ}` headers.
|
|
160
|
+
const header = options?.kid === undefined
|
|
161
|
+
? { alg, typ: "JWT" }
|
|
162
|
+
: { alg, typ: "JWT", kid: options.kid };
|
|
98
163
|
const headerB64 = b64urlEncode(JSON.stringify(header));
|
|
99
164
|
const payloadB64 = b64urlEncode(JSON.stringify(claims));
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
165
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
166
|
+
const sig = alg === "ES256"
|
|
167
|
+
// JWS requires the raw R||S pair, NOT the DER encoding node emits by
|
|
168
|
+
// default. Getting this wrong produces a signature every verifier rejects.
|
|
169
|
+
? createSign("sha256")
|
|
170
|
+
.update(signingInput)
|
|
171
|
+
.sign({ key: secret, dsaEncoding: "ieee-p1363" })
|
|
172
|
+
: createHmac(hmacForAlg(alg), secret)
|
|
173
|
+
.update(signingInput)
|
|
174
|
+
.digest();
|
|
175
|
+
return `${signingInput}.${b64urlEncode(sig)}`;
|
|
104
176
|
}
|
|
105
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Verify and report WHICH key matched.
|
|
179
|
+
*
|
|
180
|
+
* Key selection (mirrors the shipped gateway policy, and is deliberately
|
|
181
|
+
* stricter than PostgREST v12.2.3, which ignores `kid` entirely):
|
|
182
|
+
* - `kid` present and known -> verify against THAT key alone; a signature
|
|
183
|
+
* mismatch is an error, never a fallback.
|
|
184
|
+
* - `kid` present but unknown -> reject immediately, no HMAC work.
|
|
185
|
+
* - `kid` absent -> try only keys marked `legacy`.
|
|
186
|
+
*
|
|
187
|
+
* A bare-string `secret` keeps the legacy single-key behavior exactly.
|
|
188
|
+
*/
|
|
189
|
+
export function verifyWithKey(token, secretOrKeys, options) {
|
|
106
190
|
if (typeof token !== "string" || token.length === 0) {
|
|
107
191
|
throw new JsonWebTokenError("jwt must be provided");
|
|
108
192
|
}
|
|
109
|
-
|
|
193
|
+
const keys = typeof secretOrKeys === "string"
|
|
194
|
+
? (secretOrKeys.length === 0
|
|
195
|
+
? (() => { throw new JsonWebTokenError("secret must be provided"); })()
|
|
196
|
+
: [{ key: Buffer.from(secretOrKeys, "utf8"), alg: "HS256", legacy: true }])
|
|
197
|
+
: secretOrKeys;
|
|
198
|
+
if (keys.length === 0)
|
|
110
199
|
throw new JsonWebTokenError("secret must be provided");
|
|
111
|
-
}
|
|
112
200
|
const parts = token.split(".");
|
|
113
201
|
if (parts.length !== 3)
|
|
114
202
|
throw new JsonWebTokenError("jwt malformed");
|
|
@@ -124,12 +212,25 @@ export function verify(token, secret, options) {
|
|
|
124
212
|
if (typeof header.alg !== "string" || !allowed.includes(header.alg)) {
|
|
125
213
|
throw new JsonWebTokenError("invalid algorithm");
|
|
126
214
|
}
|
|
127
|
-
if (header.alg !== "HS256" && header.alg !== "HS512") {
|
|
215
|
+
if (header.alg !== "HS256" && header.alg !== "HS512" && header.alg !== "ES256") {
|
|
128
216
|
throw new JsonWebTokenError("invalid algorithm");
|
|
129
217
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
218
|
+
const alg = header.alg;
|
|
219
|
+
// Select the candidate set BEFORE doing any HMAC work.
|
|
220
|
+
let candidates;
|
|
221
|
+
if (typeof header.kid === "string") {
|
|
222
|
+
const named = keys.filter((k) => k.kid === header.kid);
|
|
223
|
+
if (named.length === 0)
|
|
224
|
+
throw new UnknownKeyIdError(header.kid);
|
|
225
|
+
candidates = named;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// A bare string secret is inherently the legacy key; an explicit keyset
|
|
229
|
+
// must mark exactly which key may verify kid-less tokens.
|
|
230
|
+
candidates = keys.filter((k) => k.legacy === true);
|
|
231
|
+
if (candidates.length === 0)
|
|
232
|
+
throw new JsonWebTokenError("invalid key id");
|
|
233
|
+
}
|
|
133
234
|
let got;
|
|
134
235
|
try {
|
|
135
236
|
got = b64urlDecodeToBuffer(sigB64);
|
|
@@ -137,9 +238,35 @@ export function verify(token, secret, options) {
|
|
|
137
238
|
catch {
|
|
138
239
|
throw new JsonWebTokenError("invalid signature");
|
|
139
240
|
}
|
|
140
|
-
|
|
141
|
-
|
|
241
|
+
let matched;
|
|
242
|
+
for (const candidate of candidates) {
|
|
243
|
+
// A key only verifies its OWN algorithm. This is what stops an ES256
|
|
244
|
+
// public key from being used as HMAC material (algorithm confusion) now
|
|
245
|
+
// that both kinds can sit in one keyset.
|
|
246
|
+
if (candidate.alg !== alg)
|
|
247
|
+
continue;
|
|
248
|
+
if (alg === "ES256") {
|
|
249
|
+
if (!candidate.publicKey)
|
|
250
|
+
continue;
|
|
251
|
+
const ok = createVerify("sha256")
|
|
252
|
+
.update(`${headerB64}.${payloadB64}`)
|
|
253
|
+
.verify({ key: candidate.publicKey, dsaEncoding: "ieee-p1363" }, got);
|
|
254
|
+
if (ok) {
|
|
255
|
+
matched = candidate;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const expected = createHmac(hmacForAlg(alg), candidate.key)
|
|
261
|
+
.update(`${headerB64}.${payloadB64}`)
|
|
262
|
+
.digest();
|
|
263
|
+
if (got.length === expected.length && timingSafeEqual(got, expected)) {
|
|
264
|
+
matched = candidate;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
142
267
|
}
|
|
268
|
+
if (!matched)
|
|
269
|
+
throw new JsonWebTokenError("invalid signature");
|
|
143
270
|
let payload;
|
|
144
271
|
try {
|
|
145
272
|
payload = JSON.parse(b64urlDecodeToBuffer(payloadB64).toString("utf8"));
|
|
@@ -172,7 +299,15 @@ export function verify(token, secret, options) {
|
|
|
172
299
|
throw new JsonWebTokenError("jwt audience invalid");
|
|
173
300
|
}
|
|
174
301
|
}
|
|
175
|
-
return payload;
|
|
302
|
+
return { payload: payload, kid: matched.kid };
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Verify a token, returning only the payload. Accepts a legacy passphrase or a
|
|
306
|
+
* keyset; use `verifyWithKey` when the caller needs to know which key matched
|
|
307
|
+
* (legacy-usage telemetry during a rotation).
|
|
308
|
+
*/
|
|
309
|
+
export function verify(token, secretOrKeys, options) {
|
|
310
|
+
return verifyWithKey(token, secretOrKeys, options).payload;
|
|
176
311
|
}
|
|
177
312
|
export function decode(token) {
|
|
178
313
|
if (typeof token !== "string")
|
|
@@ -190,6 +325,6 @@ export function decode(token) {
|
|
|
190
325
|
return null;
|
|
191
326
|
}
|
|
192
327
|
}
|
|
193
|
-
const jwt = { sign, verify, decode };
|
|
328
|
+
const jwt = { sign, verify, verifyWithKey, decode };
|
|
194
329
|
export default jwt;
|
|
195
330
|
//# sourceMappingURL=jwt.js.map
|
package/dist/lib/jwt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../src/lib/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA4B1D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,iBAAiB;IACtD,SAAS,CAAO;IAChB,YAAY,OAAe,EAAE,SAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,iBAAiB;IACnD,IAAI,CAAO;IACX,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,SAAS,YAAY,CAAC,KA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,OAAO,CAAC,CAAC,OAAO,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,MAAM,CAAiB,KAAa;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAY,CAAC;QACvF,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QAC3F,OAAO,OAAY,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AACpD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project-JWT verification keyset, fetched from the gateway at cold start.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS. Until now the runtime read `RUN402_JWT_SECRET` — the
|
|
5
|
+
* PLATFORM signing key — straight out of the Lambda environment. That key is
|
|
6
|
+
* symmetric, so verification material IS signing material: every one of the
|
|
7
|
+
* fleet's tenant Lambdas held the ability to forge `anon_key`/`service_key`
|
|
8
|
+
* for EVERY project on the platform, and those carry no expiry. It also made
|
|
9
|
+
* rotation impossible, because the key arrived at deploy time and could only
|
|
10
|
+
* change by redeploying someone else's code.
|
|
11
|
+
*
|
|
12
|
+
* Fetching a PUBLIC keyset instead fixes both at once: there is nothing here
|
|
13
|
+
* that can sign, and a rotated key reaches the fleet at the next cold start
|
|
14
|
+
* with no redeployment at all.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately mirrors `lib/actor-context-verify.ts`, which established this
|
|
17
|
+
* pattern for the actor-context key — same lazy single-flight fetch, same
|
|
18
|
+
* service-key auth, same "failures are non-fatal, the next request retries".
|
|
19
|
+
*
|
|
20
|
+
* TRANSITION FALLBACK. While `RUN402_JWT_SECRET` is still injected, it is kept
|
|
21
|
+
* as a SECOND verification key, tried after the fetched keyset. This is
|
|
22
|
+
* temporary scaffolding with a defined removal point, and it is load-bearing
|
|
23
|
+
* for exactly one window: after the fleet carries this runtime but BEFORE the
|
|
24
|
+
* gateway's signing key becomes asymmetric, the gateway is still minting HS256
|
|
25
|
+
* tokens that the (asymmetric-only) fetched keyset cannot verify. Removing the
|
|
26
|
+
* fallback before then would break `getUser()` on every project at once.
|
|
27
|
+
* See `openspec/changes/functions-runtime-key-decoupling/design.md`.
|
|
28
|
+
*/
|
|
29
|
+
import type { VerificationKey } from "./jwt.js";
|
|
30
|
+
/**
|
|
31
|
+
* The keys `getUser()` should verify against, most-trusted first.
|
|
32
|
+
*
|
|
33
|
+
* Returns the fetched public keyset followed by the env-injected legacy key
|
|
34
|
+
* when one is present. Order matters only for which key is TRIED first — a
|
|
35
|
+
* token verifies against exactly one key either way, since `verifyWithKey`
|
|
36
|
+
* selects on `kid` and refuses to fall back on a signature mismatch.
|
|
37
|
+
*/
|
|
38
|
+
export declare function projectJwtVerificationKeys(): VerificationKey[];
|
|
39
|
+
/**
|
|
40
|
+
* Ensure the keyset is loaded before a synchronous verify.
|
|
41
|
+
*
|
|
42
|
+
* Single-flight: concurrent invocations in the same execution environment
|
|
43
|
+
* share one fetch. Cached for the life of the environment, so a warm Lambda
|
|
44
|
+
* pays nothing. Never throws — a failed fetch leaves whatever keys are
|
|
45
|
+
* available (possibly just the env fallback) and the next request retries.
|
|
46
|
+
*/
|
|
47
|
+
export declare function ensureProjectJwtKeysLoaded(): Promise<void>;
|
|
48
|
+
/** True when verification has no key at all — the caller must fail CLOSED
|
|
49
|
+
* rather than treat the request as anonymous-but-fine. */
|
|
50
|
+
export declare function projectJwtKeysUnavailable(): boolean;
|
|
51
|
+
/** Test injection. NEVER call from production code. */
|
|
52
|
+
export declare function _setProjectJwtKeysForTest(keys: VerificationKey[] | null): void;
|
|
53
|
+
/**
|
|
54
|
+
* The header carrying the gateway-minted actor token.
|
|
55
|
+
*
|
|
56
|
+
* The runtime FORWARDS this rather than minting its own. Kept here beside the
|
|
57
|
+
* keyset because the two are halves of one contract: the gateway signs both
|
|
58
|
+
* the tokens this runtime verifies and the one it forwards, and the runtime
|
|
59
|
+
* holds nothing that can produce either.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DATA_PLANE_ACTOR_TOKEN_HEADER = "x-run402-actor-token";
|
|
62
|
+
/** Read a header from either shape, case-insensitively. */
|
|
63
|
+
export declare function readHeader(headers: unknown, name: string): string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The gateway-minted actor bearer for this request, if present.
|
|
66
|
+
*
|
|
67
|
+
* Returns the `Authorization`-ready value. Absent for anonymous requests, and
|
|
68
|
+
* absent on older gateways — callers must fall through to their previous
|
|
69
|
+
* behaviour rather than failing, so a new runtime on an old gateway degrades
|
|
70
|
+
* instead of breaking.
|
|
71
|
+
*/
|
|
72
|
+
export declare function forwardedActorAuthorization(headers: unknown): string | undefined;
|
|
73
|
+
//# sourceMappingURL=project-jwt-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-jwt-keys.d.ts","sourceRoot":"","sources":["../../src/lib/project-jwt-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAchD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,IAAI,eAAe,EAAE,CAK9D;AAeD;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAehE;AAED;2DAC2D;AAC3D,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAsCD,uDAAuD;AACvD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,IAAI,GAAG,IAAI,CAG9E;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AAQpE,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS7E;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGhF"}
|