@softistx/alxia-clavix 0.2.0 → 0.3.1
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 +39 -2
- package/dist/clavix.d.ts +10 -4
- package/dist/clavix.d.ts.map +1 -1
- package/dist/dpop/htu.d.ts +11 -0
- package/dist/dpop/htu.d.ts.map +1 -0
- package/dist/dpop/index.d.ts +6 -0
- package/dist/dpop/index.d.ts.map +1 -0
- package/dist/dpop/jwk.d.ts +20 -0
- package/dist/dpop/jwk.d.ts.map +1 -0
- package/dist/dpop/nonce.d.ts +29 -0
- package/dist/dpop/nonce.d.ts.map +1 -0
- package/dist/dpop/options.d.ts +33 -0
- package/dist/dpop/options.d.ts.map +1 -0
- package/dist/dpop/proof.d.ts +32 -0
- package/dist/dpop/proof.d.ts.map +1 -0
- package/dist/dpop/replay-store.d.ts +24 -0
- package/dist/dpop/replay-store.d.ts.map +1 -0
- package/dist/guard.d.ts +19 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +350 -18
- package/dist/index.js.map +11 -4
- package/docs/guide/principal-and-scopes.md +5 -1
- package/docs/guide/security.md +89 -3
- package/docs/roadmap.md +7 -0
- package/docs/troubleshooting.md +88 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,9 +1,338 @@
|
|
|
1
1
|
// src/clavix.ts
|
|
2
2
|
import {
|
|
3
|
-
bearer,
|
|
4
3
|
createJwt
|
|
5
4
|
} from "@softistx/alxia-jwt";
|
|
6
5
|
|
|
6
|
+
// src/dpop/jwk.ts
|
|
7
|
+
var encoder = new TextEncoder;
|
|
8
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
function decode(part) {
|
|
10
|
+
try {
|
|
11
|
+
const value = JSON.parse(Buffer.from(part, "base64url").toString("utf8"));
|
|
12
|
+
return isObject(value) ? value : undefined;
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function publicKey(jwk, alg) {
|
|
18
|
+
if (jwk.d !== undefined)
|
|
19
|
+
return;
|
|
20
|
+
const text = (name) => {
|
|
21
|
+
const value = jwk[name];
|
|
22
|
+
return typeof value === "string" ? value : undefined;
|
|
23
|
+
};
|
|
24
|
+
const [kty, crv, x, y] = [text("kty"), text("crv"), text("x"), text("y")];
|
|
25
|
+
if (alg === "ES256") {
|
|
26
|
+
if (kty !== "EC" || crv !== "P-256" || !x || !y)
|
|
27
|
+
return;
|
|
28
|
+
return {
|
|
29
|
+
jwk: { kty, crv, x, y },
|
|
30
|
+
params: { name: "ECDSA", namedCurve: "P-256" }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (kty !== "OKP" || crv !== "Ed25519" || !x)
|
|
34
|
+
return;
|
|
35
|
+
return { jwk: { kty, crv, x }, params: { name: "Ed25519" } };
|
|
36
|
+
}
|
|
37
|
+
async function jwkThumbprint(jwk) {
|
|
38
|
+
const members = jwk.kty === "EC" ? { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y } : { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
39
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(JSON.stringify(members)));
|
|
40
|
+
return Buffer.from(digest).toString("base64url");
|
|
41
|
+
}
|
|
42
|
+
// src/dpop/nonce.ts
|
|
43
|
+
var encoder2 = new TextEncoder;
|
|
44
|
+
function timingSafeEqual(a, b) {
|
|
45
|
+
const x = encoder2.encode(a);
|
|
46
|
+
const y = encoder2.encode(b);
|
|
47
|
+
if (x.length !== y.length)
|
|
48
|
+
return false;
|
|
49
|
+
let diff = 0;
|
|
50
|
+
for (let i = 0;i < x.length; i++) {
|
|
51
|
+
diff |= x[i] ^ y[i];
|
|
52
|
+
}
|
|
53
|
+
return diff === 0;
|
|
54
|
+
}
|
|
55
|
+
function hmacDpopNonce(options) {
|
|
56
|
+
const ttlMs = options.ttlMs ?? 300000;
|
|
57
|
+
if (!(Number.isFinite(ttlMs) && ttlMs > 0)) {
|
|
58
|
+
throw new TypeError("clavix: the dpop nonce ttlMs must be a finite number above 0");
|
|
59
|
+
}
|
|
60
|
+
if (typeof options.secret !== "string" || options.secret.length < 16) {
|
|
61
|
+
throw new TypeError("clavix: the dpop nonce secret needs 16 characters");
|
|
62
|
+
}
|
|
63
|
+
const hmac = (raw) => crypto.subtle.importKey("raw", raw, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
64
|
+
const key = (async () => {
|
|
65
|
+
const master = await hmac(encoder2.encode(options.secret));
|
|
66
|
+
const derived = await crypto.subtle.sign("HMAC", master, encoder2.encode("@softistx/alxia-clavix dpop nonce v1"));
|
|
67
|
+
return hmac(derived);
|
|
68
|
+
})();
|
|
69
|
+
const mac = async (stamp) => Buffer.from(await crypto.subtle.sign("HMAC", await key, encoder2.encode(stamp))).toString("base64url");
|
|
70
|
+
const issue = async () => {
|
|
71
|
+
const stamp = String(Date.now());
|
|
72
|
+
return `${stamp}.${await mac(stamp)}`;
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
issue,
|
|
76
|
+
async accepts(nonce) {
|
|
77
|
+
const [stamp, signature, ...rest] = nonce.split(".");
|
|
78
|
+
if (stamp === undefined || signature === undefined || rest.length > 0) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!/^\d{1,16}$/.test(stamp))
|
|
82
|
+
return false;
|
|
83
|
+
const age = Date.now() - Number(stamp);
|
|
84
|
+
if (age < -1000 || age > ttlMs)
|
|
85
|
+
return false;
|
|
86
|
+
return timingSafeEqual(signature, await mac(stamp));
|
|
87
|
+
},
|
|
88
|
+
async renew(nonce) {
|
|
89
|
+
const age = Date.now() - Number(nonce.split(".")[0]);
|
|
90
|
+
return age > ttlMs / 2 ? await issue() : undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// src/dpop/options.ts
|
|
95
|
+
function resolveDpop(options) {
|
|
96
|
+
let origin;
|
|
97
|
+
try {
|
|
98
|
+
const url = new URL(options.origin);
|
|
99
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || url.pathname !== "/" || url.search !== "" || url.hash !== "" || url.username !== "" || url.password !== "") {
|
|
100
|
+
throw new Error("not an origin");
|
|
101
|
+
}
|
|
102
|
+
origin = url.origin;
|
|
103
|
+
} catch {
|
|
104
|
+
throw new TypeError(`clavix: dpop.origin must be an origin such as "https://api.example.com", got ${JSON.stringify(options.origin)}`);
|
|
105
|
+
}
|
|
106
|
+
if (typeof options.replay?.claim !== "function") {
|
|
107
|
+
throw new TypeError("clavix: dpop.replay is required");
|
|
108
|
+
}
|
|
109
|
+
const algorithms = options.algorithms ?? ["ES256", "EdDSA"];
|
|
110
|
+
if (algorithms.length === 0 || !algorithms.every((a) => a === "ES256" || a === "EdDSA")) {
|
|
111
|
+
throw new TypeError("clavix: dpop.algorithms takes ES256, EdDSA or both");
|
|
112
|
+
}
|
|
113
|
+
const maxAgeSec = options.maxAgeSec ?? 60;
|
|
114
|
+
const clockSkewSec = options.clockSkewSec ?? 5;
|
|
115
|
+
if (!(Number.isFinite(maxAgeSec) && maxAgeSec > 0)) {
|
|
116
|
+
throw new TypeError("clavix: dpop.maxAgeSec must be a finite number above 0");
|
|
117
|
+
}
|
|
118
|
+
if (!(Number.isFinite(clockSkewSec) && clockSkewSec >= 0)) {
|
|
119
|
+
throw new TypeError("clavix: dpop.clockSkewSec must be a finite number, 0 or more");
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
origin,
|
|
123
|
+
replay: options.replay,
|
|
124
|
+
algorithms,
|
|
125
|
+
maxAgeSec,
|
|
126
|
+
clockSkewSec,
|
|
127
|
+
nonce: options.nonce
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
// src/dpop/htu.ts
|
|
131
|
+
function sameUrl(htu, origin, path) {
|
|
132
|
+
try {
|
|
133
|
+
const claimed = new URL(htu);
|
|
134
|
+
if (claimed.username !== "" || claimed.password !== "")
|
|
135
|
+
return false;
|
|
136
|
+
return claimed.origin === origin && claimed.pathname === path;
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/dpop/proof.ts
|
|
143
|
+
var MAX_JTI = 256;
|
|
144
|
+
var REMEMBER_MARGIN_MS = 5000;
|
|
145
|
+
var fail = (reason) => ({ ok: false, reason });
|
|
146
|
+
function parse(proof) {
|
|
147
|
+
const parts = proof.split(".");
|
|
148
|
+
if (parts.length !== 3)
|
|
149
|
+
return "dpop_proof_malformed";
|
|
150
|
+
const [head, body, signature] = parts;
|
|
151
|
+
const header = decode(head);
|
|
152
|
+
const claims = decode(body);
|
|
153
|
+
if (header === undefined || claims === undefined || "crit" in header) {
|
|
154
|
+
return "dpop_proof_malformed";
|
|
155
|
+
}
|
|
156
|
+
return { head, body, signature, header, claims };
|
|
157
|
+
}
|
|
158
|
+
async function verifySignature(parsed, algorithms) {
|
|
159
|
+
const { header } = parsed;
|
|
160
|
+
if (header.typ !== "dpop+jwt")
|
|
161
|
+
return "dpop_proof_type";
|
|
162
|
+
const alg = algorithms.find((a) => a === header.alg);
|
|
163
|
+
if (alg === undefined)
|
|
164
|
+
return "dpop_proof_algorithm";
|
|
165
|
+
if (!isObject(header.jwk))
|
|
166
|
+
return "dpop_proof_key";
|
|
167
|
+
const key = publicKey(header.jwk, alg);
|
|
168
|
+
if (key === undefined)
|
|
169
|
+
return "dpop_proof_key";
|
|
170
|
+
try {
|
|
171
|
+
const valid = await crypto.subtle.verify(alg === "ES256" ? { name: "ECDSA", hash: "SHA-256" } : { name: "Ed25519" }, await crypto.subtle.importKey("jwk", key.jwk, key.params, false, [
|
|
172
|
+
"verify"
|
|
173
|
+
]), Buffer.from(parsed.signature, "base64url"), encoder.encode(`${parsed.head}.${parsed.body}`));
|
|
174
|
+
return valid ? key : "dpop_proof_signature";
|
|
175
|
+
} catch {
|
|
176
|
+
return "dpop_proof_signature";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function checkClaims(claims, input, options, key) {
|
|
180
|
+
if (claims.htm !== input.method)
|
|
181
|
+
return "dpop_proof_method";
|
|
182
|
+
if (typeof claims.htu !== "string" || !sameUrl(claims.htu, options.origin, input.path)) {
|
|
183
|
+
return "dpop_proof_url";
|
|
184
|
+
}
|
|
185
|
+
const nowSec = Date.now() / 1000;
|
|
186
|
+
const { iat, jti } = claims;
|
|
187
|
+
if (typeof iat !== "number" || !Number.isFinite(iat) || iat < nowSec - options.maxAgeSec || iat > nowSec + options.clockSkewSec) {
|
|
188
|
+
return "dpop_proof_iat";
|
|
189
|
+
}
|
|
190
|
+
if (typeof jti !== "string" || jti === "" || jti.length > MAX_JTI) {
|
|
191
|
+
return "dpop_proof_jti";
|
|
192
|
+
}
|
|
193
|
+
const hash = await crypto.subtle.digest("SHA-256", encoder.encode(input.accessToken));
|
|
194
|
+
if (typeof claims.ath !== "string" || !timingSafeEqual(claims.ath, Buffer.from(hash).toString("base64url"))) {
|
|
195
|
+
return "dpop_proof_ath";
|
|
196
|
+
}
|
|
197
|
+
if (!timingSafeEqual(await jwkThumbprint(key.jwk), input.jkt)) {
|
|
198
|
+
return "dpop_proof_thumbprint";
|
|
199
|
+
}
|
|
200
|
+
return { jti };
|
|
201
|
+
}
|
|
202
|
+
async function verifyProof(input, options) {
|
|
203
|
+
if (input.proof === null || input.proof === "") {
|
|
204
|
+
return fail("dpop_proof_missing");
|
|
205
|
+
}
|
|
206
|
+
const parsed = parse(input.proof);
|
|
207
|
+
if (typeof parsed === "string")
|
|
208
|
+
return fail(parsed);
|
|
209
|
+
const key = await verifySignature(parsed, options.algorithms);
|
|
210
|
+
if (typeof key === "string")
|
|
211
|
+
return fail(key);
|
|
212
|
+
const checked = await checkClaims(parsed.claims, input, options, key);
|
|
213
|
+
if (typeof checked === "string")
|
|
214
|
+
return fail(checked);
|
|
215
|
+
let renewed;
|
|
216
|
+
if (options.nonce !== undefined) {
|
|
217
|
+
const { nonce } = parsed.claims;
|
|
218
|
+
if (typeof nonce === "string" && await options.nonce.accepts(nonce)) {
|
|
219
|
+
renewed = await options.nonce.renew?.(nonce);
|
|
220
|
+
} else {
|
|
221
|
+
return {
|
|
222
|
+
ok: false,
|
|
223
|
+
reason: "dpop_nonce",
|
|
224
|
+
nonce: await options.nonce.issue()
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const ttlMs = (options.maxAgeSec + options.clockSkewSec) * 1000 + REMEMBER_MARGIN_MS;
|
|
229
|
+
const first = await options.replay.claim(`${input.jkt}:${checked.jti}`, ttlMs);
|
|
230
|
+
if (!first)
|
|
231
|
+
return fail("dpop_proof_replay");
|
|
232
|
+
return renewed === undefined ? { ok: true } : { ok: true, nonce: renewed };
|
|
233
|
+
}
|
|
234
|
+
// src/dpop/replay-store.ts
|
|
235
|
+
function memoryDpopReplayStore(options = {}) {
|
|
236
|
+
const max = options.maxEntries ?? 1e4;
|
|
237
|
+
const seen = new Map;
|
|
238
|
+
return {
|
|
239
|
+
async claim(key, ttlMs) {
|
|
240
|
+
const now = Date.now();
|
|
241
|
+
const until = seen.get(key);
|
|
242
|
+
if (until !== undefined && until > now)
|
|
243
|
+
return false;
|
|
244
|
+
if (seen.size >= max) {
|
|
245
|
+
for (const [stored, expiry] of seen) {
|
|
246
|
+
if (expiry <= now)
|
|
247
|
+
seen.delete(stored);
|
|
248
|
+
}
|
|
249
|
+
if (seen.size >= max) {
|
|
250
|
+
throw new Error("memoryDpopReplayStore: full (use a shared store)");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
seen.set(key, now + ttlMs);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
// src/guard.ts
|
|
259
|
+
import {
|
|
260
|
+
bearer
|
|
261
|
+
} from "@softistx/alxia-jwt";
|
|
262
|
+
function boundKey(claims) {
|
|
263
|
+
const { cnf } = claims;
|
|
264
|
+
if (cnf === undefined)
|
|
265
|
+
return;
|
|
266
|
+
if (typeof cnf !== "object" || cnf === null || Array.isArray(cnf)) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
if (!("jkt" in cnf))
|
|
270
|
+
return;
|
|
271
|
+
return typeof cnf.jkt === "string" && cnf.jkt !== "" ? cnf.jkt : null;
|
|
272
|
+
}
|
|
273
|
+
var isProofReason = (reason) => reason.startsWith("dpop_proof_");
|
|
274
|
+
function dpopExtension(dpop) {
|
|
275
|
+
const algs = dpop?.algorithms.join(" ") ?? "";
|
|
276
|
+
const scheme = (error, description) => `DPoP error="${error}"${description === undefined ? "" : `, error_description="${description}"`}, algs="${algs}"`;
|
|
277
|
+
return {
|
|
278
|
+
schemes: ["DPoP"],
|
|
279
|
+
async bound({ request, token, scheme: used, claims }) {
|
|
280
|
+
const jkt = boundKey(claims);
|
|
281
|
+
if (jkt === null)
|
|
282
|
+
return { reason: "dpop_malformed" };
|
|
283
|
+
if (used !== "DPoP") {
|
|
284
|
+
return jkt === undefined ? undefined : { reason: "dpop_required" };
|
|
285
|
+
}
|
|
286
|
+
if (dpop === undefined)
|
|
287
|
+
return { reason: "dpop_unsupported" };
|
|
288
|
+
if (jkt === undefined)
|
|
289
|
+
return { reason: "dpop_unbound" };
|
|
290
|
+
const proof = await verifyProof({
|
|
291
|
+
proof: request.headers.get("dpop"),
|
|
292
|
+
method: request.method,
|
|
293
|
+
path: new URL(request.url).pathname,
|
|
294
|
+
accessToken: token,
|
|
295
|
+
jkt
|
|
296
|
+
}, dpop);
|
|
297
|
+
if (proof.ok) {
|
|
298
|
+
return proof.nonce === undefined ? undefined : { headers: { "dpop-nonce": proof.nonce } };
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
reason: proof.reason,
|
|
302
|
+
...proof.nonce === undefined ? {} : { headers: { "dpop-nonce": proof.nonce } }
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
challenge(reason, used) {
|
|
306
|
+
if (dpop === undefined)
|
|
307
|
+
return;
|
|
308
|
+
if (reason === "missing")
|
|
309
|
+
return `Bearer, DPoP algs="${algs}"`;
|
|
310
|
+
if (reason === "dpop_required") {
|
|
311
|
+
return scheme("invalid_token", "the token is bound to a key: use the DPoP scheme with a proof");
|
|
312
|
+
}
|
|
313
|
+
if (reason === "dpop_unbound") {
|
|
314
|
+
return scheme("invalid_token", "the token is not bound to a key: use the Bearer scheme");
|
|
315
|
+
}
|
|
316
|
+
if (reason === "dpop_nonce")
|
|
317
|
+
return scheme("use_dpop_nonce");
|
|
318
|
+
if (isProofReason(reason))
|
|
319
|
+
return scheme("invalid_dpop_proof");
|
|
320
|
+
if (used === "DPoP" && reason !== "insufficient_user_authentication") {
|
|
321
|
+
return scheme("invalid_token");
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function guard(options) {
|
|
328
|
+
return bearer({
|
|
329
|
+
jwt: options.jwt,
|
|
330
|
+
schema: options.schema,
|
|
331
|
+
...options.cookie === undefined ? {} : { cookie: options.cookie },
|
|
332
|
+
extension: dpopExtension(options.dpop)
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
7
336
|
// src/issuers.ts
|
|
8
337
|
var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
9
338
|
var LOCAL = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -134,7 +463,7 @@ function principalSchema(tenantOf) {
|
|
|
134
463
|
}
|
|
135
464
|
|
|
136
465
|
// src/unverified-issuer.ts
|
|
137
|
-
var
|
|
466
|
+
var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
138
467
|
function unverifiedIssuer(token) {
|
|
139
468
|
const parts = token.split(".");
|
|
140
469
|
const payload = parts[1];
|
|
@@ -144,7 +473,7 @@ function unverifiedIssuer(token) {
|
|
|
144
473
|
return;
|
|
145
474
|
try {
|
|
146
475
|
const claims = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.from(payload, "base64url")));
|
|
147
|
-
return
|
|
476
|
+
return isObject2(claims) && typeof claims["iss"] === "string" ? claims["iss"] : undefined;
|
|
148
477
|
} catch {
|
|
149
478
|
return;
|
|
150
479
|
}
|
|
@@ -168,29 +497,33 @@ function pick(source, keys) {
|
|
|
168
497
|
}
|
|
169
498
|
return picked;
|
|
170
499
|
}
|
|
171
|
-
function
|
|
500
|
+
function issuerRules(options) {
|
|
172
501
|
if (options.domain === undefined && options.issuers === undefined) {
|
|
173
502
|
throw new TypeError("clavix: give domain, issuers, or both");
|
|
174
503
|
}
|
|
175
504
|
if (typeof options.audience !== "string" || options.audience === "") {
|
|
176
505
|
throw new TypeError("clavix: audience is required");
|
|
177
506
|
}
|
|
178
|
-
const max = options.maxIssuers ?? 100;
|
|
179
|
-
if (!Number.isInteger(max) || max < 1) {
|
|
180
|
-
throw new TypeError("clavix: maxIssuers must be a positive integer");
|
|
181
|
-
}
|
|
182
507
|
const listed = listIssuers(options.issuers ?? []);
|
|
183
508
|
if (options.domain === undefined && listed.size === 0) {
|
|
184
509
|
throw new TypeError("clavix: give domain, issuers, or both");
|
|
185
510
|
}
|
|
186
|
-
|
|
511
|
+
return {
|
|
187
512
|
domain: options.domain === undefined ? undefined : normaliseDomain(options.domain),
|
|
188
513
|
listed
|
|
189
514
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
515
|
+
}
|
|
516
|
+
function count(name, value, fallback) {
|
|
517
|
+
const n = value ?? fallback;
|
|
518
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
519
|
+
throw new TypeError(`clavix: ${name} must be a positive integer`);
|
|
193
520
|
}
|
|
521
|
+
return n;
|
|
522
|
+
}
|
|
523
|
+
function clavix(options) {
|
|
524
|
+
const rules = issuerRules(options);
|
|
525
|
+
const max = count("maxIssuers", options.maxIssuers, 100);
|
|
526
|
+
const probationSize = count("probation", options.probation, Math.min(max, 16));
|
|
194
527
|
const passthrough = pick(options, PASSTHROUGH);
|
|
195
528
|
const create = (issuer) => createJwt({ ...passthrough, discovery: issuer, profile: "rfc9068" });
|
|
196
529
|
const pinned = new Map;
|
|
@@ -215,14 +548,11 @@ function clavix(options) {
|
|
|
215
548
|
};
|
|
216
549
|
const tenantOf = (issuer) => resolveIssuer(rules, issuer)?.tenant;
|
|
217
550
|
const schema = principalSchema(tenantOf);
|
|
551
|
+
const dpop = options.dpop === undefined ? undefined : resolveDpop(options.dpop);
|
|
218
552
|
const self = {
|
|
219
553
|
tenantOf,
|
|
220
554
|
ready: async () => (await Promise.all([...pinned.values()].map((v) => v.ready()))).every(Boolean),
|
|
221
|
-
bearer: (
|
|
222
|
-
jwt: self,
|
|
223
|
-
schema,
|
|
224
|
-
...guard?.cookie === undefined ? {} : { cookie: guard.cookie }
|
|
225
|
-
}),
|
|
555
|
+
bearer: (guardOptions) => guard({ jwt: self, schema, dpop, cookie: guardOptions?.cookie }),
|
|
226
556
|
async verify(token) {
|
|
227
557
|
const issuer = unverifiedIssuer(token);
|
|
228
558
|
if (issuer === undefined)
|
|
@@ -276,8 +606,10 @@ function requireScope(...scopes) {
|
|
|
276
606
|
markFactory(requireScope);
|
|
277
607
|
export {
|
|
278
608
|
clavix,
|
|
609
|
+
hmacDpopNonce,
|
|
610
|
+
memoryDpopReplayStore,
|
|
279
611
|
requireScope
|
|
280
612
|
};
|
|
281
613
|
|
|
282
|
-
//# debugId=
|
|
614
|
+
//# debugId=A0E8A24ACF0832D464756E2164756E21
|
|
283
615
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/clavix.ts", "../src/issuers.ts", "../src/lru.ts", "../src/principal.ts", "../src/unverified-issuer.ts", "../src/scope.ts"],
|
|
3
|
+
"sources": ["../src/clavix.ts", "../src/dpop/jwk.ts", "../src/dpop/nonce.ts", "../src/dpop/options.ts", "../src/dpop/htu.ts", "../src/dpop/proof.ts", "../src/dpop/replay-store.ts", "../src/guard.ts", "../src/issuers.ts", "../src/lru.ts", "../src/principal.ts", "../src/unverified-issuer.ts", "../src/scope.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import
|
|
5
|
+
"import {\n\tcreateJwt,\n\ttype JwksJwt,\n\ttype JwksOptions,\n\ttype Verifier,\n} from '@softistx/alxia-jwt';\nimport { type DpopOptions, resolveDpop } from './dpop';\nimport { type ClavixGuard, guard } from './guard';\nimport {\n\ttype IssuerRules,\n\tlistIssuers,\n\tnormaliseDomain,\n\tresolveIssuer,\n} from './issuers';\nimport { Lru } from './lru';\nimport { principalSchema } from './principal';\nimport { unverifiedIssuer } from './unverified-issuer';\n\nexport interface ClavixOptions\n\textends Pick<\n\t\tJwksOptions,\n\t\t| 'audience'\n\t\t| 'cacheMs'\n\t\t| 'staleMs'\n\t\t| 'refetchMs'\n\t\t| 'timeoutMs'\n\t\t| 'clockTolerance'\n\t\t| 'algorithms'\n\t> {\n\t/**\n\t * The deployment's domain: an issuer `https://<tenant>.<domain>` is\n\t * allowed, with exactly one DNS label in front of it.\n\t */\n\treadonly domain?: string;\n\t/**\n\t * Issuers allowed beside the pattern (custom domains, a test issuer): a\n\t * list, or `{ issuer: tenant }` to name the tenant each one stands for.\n\t * Compared byte for byte.\n\t */\n\treadonly issuers?: readonly string[] | Readonly<Record<string, string>>;\n\t/** The API's identifier, which a token's `aud` must contain. */\n\treadonly audience: string;\n\t/**\n\t * Issuers whose keys are kept at once, once a token from them has\n\t * verified; the least recently used is dropped past it. 100 by default.\n\t * `warm` issuers are not counted.\n\t */\n\treadonly maxIssuers?: number;\n\t/**\n\t * Issuers met but not yet proven, kept in a small cache of their own: one\n\t * moves to the `maxIssuers` cache only when a token from it verifies, so\n\t * forged issuers can only push each other out. `min(maxIssuers, 16)` by\n\t * default.\n\t */\n\treadonly probation?: number;\n\t/**\n\t * Issuers whose keys `ready` waits for, each allowed by the same rules as\n\t * a token's issuer (a TypeError otherwise). They are pinned: never\n\t * evicted, and not counted against `maxIssuers`. Left out, `ready` is\n\t * always ready.\n\t */\n\treadonly warm?: readonly string[];\n\t/**\n\t * Verifies the DPoP proof of sender-constrained tokens (RFC 9449) and\n\t * accepts the `DPoP` scheme. Left out, a token bound to a key (`cnf.jkt`)\n\t * is refused outright, as a bearer or as `DPoP`.\n\t */\n\treadonly dpop?: DpopOptions;\n}\n\nexport interface ClavixVerifier extends Verifier {\n\t/**\n\t * The tenant of an issuer the options allow: the slug of a pattern issuer,\n\t * the mapped name of a listed one. `undefined` for a refused issuer, and\n\t * for a listed issuer given without a tenant.\n\t */\n\ttenantOf(issuer: string): string | undefined;\n\t/**\n\t * A readiness check for `health({ checks: { clavix: auth.ready } })`:\n\t * resolves `true` once the keys of every `warm` issuer are loaded (a set\n\t * within `cacheMs`, or stale within `staleMs`), `false` otherwise, and\n\t * never throws. With no `warm` issuer it is always `true`: keys are then\n\t * fetched on a tenant's first token, and a probe cannot wait for tenants\n\t * it does not know.\n\t */\n\tready(): Promise<boolean>;\n\t/**\n\t * A guard, as `@softistx/alxia-jwt`'s `bearer()` (same 401s and cookie mode): the\n\t * routes after it read a `ClavixPrincipal` as `user`. A token whose claims\n\t * are malformed (no `sub`, `iss` or `client_id`, a bad `scope`, `roles`,\n\t * `permissions` or `cnf`) is a 401 `malformed`, refused by the RFC 9068\n\t * profile before the principal is built; reason `claims` is only for a\n\t * listed issuer with no tenant (give `{ issuer: tenant }`).\n\t */\n\tbearer(options?: {\n\t\t/** Reads the token from this cookie when no `Authorization` header carries one. */\n\t\treadonly cookie?: string;\n\t}): ClavixGuard;\n}\n\n/** The options handed on to `createJwt`: nothing else of `options` reaches it. */\nconst PASSTHROUGH = [\n\t'audience',\n\t'cacheMs',\n\t'staleMs',\n\t'refetchMs',\n\t'timeoutMs',\n\t'clockTolerance',\n\t'algorithms',\n] as const;\n\n/** The defined `keys` of `source`, typed as such. */\nfunction pick<T extends object, K extends keyof T>(\n\tsource: T,\n\tkeys: readonly K[],\n): Pick<T, K> {\n\tconst picked: Partial<Pick<T, K>> = {};\n\tfor (const key of keys) {\n\t\tif (source[key] !== undefined) picked[key] = source[key];\n\t}\n\treturn picked as Pick<T, K>;\n}\n\n/** The rules that say which issuers a verifier trusts, from its options (a TypeError when they give none). */\nfunction issuerRules(options: ClavixOptions): IssuerRules {\n\tif (options.domain === undefined && options.issuers === undefined) {\n\t\tthrow new TypeError('clavix: give domain, issuers, or both');\n\t}\n\tif (typeof options.audience !== 'string' || options.audience === '') {\n\t\tthrow new TypeError('clavix: audience is required');\n\t}\n\tconst listed = listIssuers(options.issuers ?? []);\n\tif (options.domain === undefined && listed.size === 0) {\n\t\tthrow new TypeError('clavix: give domain, issuers, or both');\n\t}\n\treturn {\n\t\tdomain:\n\t\t\toptions.domain === undefined\n\t\t\t\t? undefined\n\t\t\t\t: normaliseDomain(options.domain),\n\t\tlisted,\n\t};\n}\n\n/** A positive integer option, or its default. */\nfunction count(name: string, value: number | undefined, fallback: number) {\n\tconst n = value ?? fallback;\n\tif (!Number.isInteger(n) || n < 1) {\n\t\tthrow new TypeError(`clavix: ${name} must be a positive integer`);\n\t}\n\treturn n;\n}\n\n/**\n * A verifier of the access tokens Clavix issues, for any tenant: a token is\n * checked with the keys of its own issuer, but only an issuer the options\n * allow is ever fetched from.\n *\n * ```ts\n * const verifier = clavix({ domain: 'clavix.example', audience: 'https://api.example' });\n * const result = await verifier.verify(token);\n * ```\n */\nexport function clavix(options: ClavixOptions): ClavixVerifier {\n\tconst rules = issuerRules(options);\n\tconst max = count('maxIssuers', options.maxIssuers, 100);\n\tconst probationSize = count(\n\t\t'probation',\n\t\toptions.probation,\n\t\tMath.min(max, 16),\n\t);\n\tconst passthrough = pick(options, PASSTHROUGH);\n\tconst create = (issuer: string): JwksJwt =>\n\t\tcreateJwt({ ...passthrough, discovery: issuer, profile: 'rfc9068' });\n\n\t// Pinned: never evicted, not counted in `max`.\n\tconst pinned = new Map<string, JwksJwt>();\n\tfor (const issuer of options.warm ?? []) {\n\t\tif (resolveIssuer(rules, issuer) === undefined) {\n\t\t\tthrow new TypeError(`clavix: warm issuer ${issuer} is not allowed`);\n\t\t}\n\t\tpinned.set(issuer, create(issuer));\n\t}\n\t// Proven issuers, then issuers met but not yet proven by a verified token.\n\tconst proven = new Lru<JwksJwt>(max);\n\tconst probation = new Lru<JwksJwt>(probationSize);\n\tconst verifierOf = (issuer: string): JwksJwt => {\n\t\tconst known = pinned.get(issuer) ?? proven.get(issuer);\n\t\tif (known !== undefined) return known;\n\t\tlet verifier = probation.get(issuer);\n\t\tif (verifier === undefined) {\n\t\t\tverifier = create(issuer);\n\t\t\tprobation.set(issuer, verifier);\n\t\t}\n\t\treturn verifier;\n\t};\n\tconst tenantOf = (issuer: string) => resolveIssuer(rules, issuer)?.tenant;\n\tconst schema = principalSchema(tenantOf);\n\tconst dpop =\n\t\toptions.dpop === undefined ? undefined : resolveDpop(options.dpop);\n\n\tconst self: ClavixVerifier = {\n\t\ttenantOf,\n\t\tready: async () =>\n\t\t\t(await Promise.all([...pinned.values()].map((v) => v.ready()))).every(\n\t\t\t\tBoolean,\n\t\t\t),\n\t\tbearer: (guardOptions) =>\n\t\t\tguard({ jwt: self, schema, dpop, cookie: guardOptions?.cookie }),\n\t\tasync verify(token) {\n\t\t\tconst issuer = unverifiedIssuer(token);\n\t\t\tif (issuer === undefined) return { ok: false, reason: 'malformed' };\n\t\t\tif (resolveIssuer(rules, issuer) === undefined) {\n\t\t\t\treturn { ok: false, reason: 'issuer' };\n\t\t\t}\n\t\t\tconst verifier = verifierOf(issuer);\n\t\t\tconst result = await verifier.verify(token);\n\t\t\t// one verified token proves the issuer: it leaves probation\n\t\t\tif (result.ok && probation.get(issuer) === verifier) {\n\t\t\t\tprobation.delete(issuer);\n\t\t\t\tproven.set(issuer, verifier);\n\t\t\t}\n\t\t\treturn result;\n\t\t},\n\t};\n\treturn self;\n}\n",
|
|
6
|
+
"import type { DpopAlgorithm } from './options';\n\n/** The members of a proof's header, claims and key that are read. */\nexport type Fields = Partial<\n\tRecord<\n\t\t| 'typ'\n\t\t| 'alg'\n\t\t| 'jwk'\n\t\t| 'crit'\n\t\t| 'htm'\n\t\t| 'htu'\n\t\t| 'iat'\n\t\t| 'jti'\n\t\t| 'ath'\n\t\t| 'nonce'\n\t\t| 'd'\n\t\t| 'kty'\n\t\t| 'crv'\n\t\t| 'x'\n\t\t| 'y',\n\t\tunknown\n\t>\n>;\n\nexport const encoder = new TextEncoder();\n\nexport const isObject = (value: unknown): value is Fields =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** A JWT part as an object, or `undefined`. */\nexport function decode(part: string): Fields | undefined {\n\ttry {\n\t\tconst value: unknown = JSON.parse(\n\t\t\tBuffer.from(part, 'base64url').toString('utf8'),\n\t\t);\n\t\treturn isObject(value) ? value : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport interface ProofKey {\n\treadonly jwk: JsonWebKey;\n\treadonly params: EcKeyImportParams | Algorithm;\n}\n\n/**\n * The public key of a proof's header, kept to its public members, with its\n * algorithm's import parameters; `undefined` for a private key, another\n * curve, or a key that does not fit `alg`.\n */\nexport function publicKey(\n\tjwk: Fields,\n\talg: DpopAlgorithm,\n): ProofKey | undefined {\n\tif (jwk.d !== undefined) return undefined;\n\tconst text = (name: 'kty' | 'crv' | 'x' | 'y') => {\n\t\tconst value = jwk[name];\n\t\treturn typeof value === 'string' ? value : undefined;\n\t};\n\tconst [kty, crv, x, y] = [text('kty'), text('crv'), text('x'), text('y')];\n\tif (alg === 'ES256') {\n\t\tif (kty !== 'EC' || crv !== 'P-256' || !x || !y) return undefined;\n\t\treturn {\n\t\t\tjwk: { kty, crv, x, y },\n\t\t\tparams: { name: 'ECDSA', namedCurve: 'P-256' },\n\t\t};\n\t}\n\tif (kty !== 'OKP' || crv !== 'Ed25519' || !x) return undefined;\n\treturn { jwk: { kty, crv, x }, params: { name: 'Ed25519' } };\n}\n\n/** The RFC 7638 thumbprint of a public JWK made by `publicKey`. */\nexport async function jwkThumbprint(jwk: JsonWebKey): Promise<string> {\n\tconst members =\n\t\tjwk.kty === 'EC'\n\t\t\t? { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y }\n\t\t\t: { crv: jwk.crv, kty: jwk.kty, x: jwk.x };\n\tconst digest = await crypto.subtle.digest(\n\t\t'SHA-256',\n\t\tencoder.encode(JSON.stringify(members)),\n\t);\n\treturn Buffer.from(digest).toString('base64url');\n}\n",
|
|
7
|
+
"/**\n * The server nonce of RFC 9449 section 8: `issue` makes the nonce a client\n * must put in its next proof, `accepts` tells whether a nonce is still valid.\n */\nexport interface DpopNonce {\n\tissue(): string | Promise<string>;\n\taccepts(nonce: string): boolean | Promise<boolean>;\n\t/**\n\t * A fresh nonce for a client whose accepted `nonce` is near its end\n\t * (RFC 9449 section 8.2), sent as `DPoP-Nonce` on the answer so the next\n\t * proof does not meet a `use_dpop_nonce` refusal; `undefined` while it\n\t * has time left.\n\t */\n\trenew?(nonce: string): string | Promise<string | undefined> | undefined;\n}\n\nconst encoder = new TextEncoder();\n\n/** Constant-time equality of two strings. */\nexport function timingSafeEqual(a: string, b: string): boolean {\n\tconst x = encoder.encode(a);\n\tconst y = encoder.encode(b);\n\tif (x.length !== y.length) return false;\n\tlet diff = 0;\n\tfor (let i = 0; i < x.length; i++) {\n\t\tdiff |= (x[i] as number) ^ (y[i] as number);\n\t}\n\treturn diff === 0;\n}\n\n/**\n * A stateless nonce: a time stamp signed with a key derived from `secret`\n * (HMAC-SHA-256, with a label of its own, so the same secret may serve\n * elsewhere), valid for `ttlMs` (5 minutes by default). Every instance\n * sharing `secret` accepts the nonces of the others, with nothing stored.\n * The secret needs 16 characters.\n */\nexport function hmacDpopNonce(options: {\n\treadonly secret: string;\n\treadonly ttlMs?: number;\n}): DpopNonce {\n\tconst ttlMs = options.ttlMs ?? 300_000;\n\tif (!(Number.isFinite(ttlMs) && ttlMs > 0)) {\n\t\tthrow new TypeError(\n\t\t\t'clavix: the dpop nonce ttlMs must be a finite number above 0',\n\t\t);\n\t}\n\tif (typeof options.secret !== 'string' || options.secret.length < 16) {\n\t\tthrow new TypeError('clavix: the dpop nonce secret needs 16 characters');\n\t}\n\tconst hmac = (raw: BufferSource) =>\n\t\tcrypto.subtle.importKey(\n\t\t\t'raw',\n\t\t\traw,\n\t\t\t{ name: 'HMAC', hash: 'SHA-256' },\n\t\t\tfalse,\n\t\t\t['sign'],\n\t\t);\n\tconst key = (async () => {\n\t\tconst master = await hmac(encoder.encode(options.secret));\n\t\tconst derived = await crypto.subtle.sign(\n\t\t\t'HMAC',\n\t\t\tmaster,\n\t\t\tencoder.encode('@softistx/alxia-clavix dpop nonce v1'),\n\t\t);\n\t\treturn hmac(derived);\n\t})();\n\tconst mac = async (stamp: string) =>\n\t\tBuffer.from(\n\t\t\tawait crypto.subtle.sign('HMAC', await key, encoder.encode(stamp)),\n\t\t).toString('base64url');\n\tconst issue = async () => {\n\t\tconst stamp = String(Date.now());\n\t\treturn `${stamp}.${await mac(stamp)}`;\n\t};\n\treturn {\n\t\tissue,\n\t\tasync accepts(nonce) {\n\t\t\tconst [stamp, signature, ...rest] = nonce.split('.');\n\t\t\tif (stamp === undefined || signature === undefined || rest.length > 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (!/^\\d{1,16}$/.test(stamp)) return false;\n\t\t\tconst age = Date.now() - Number(stamp);\n\t\t\tif (age < -1000 || age > ttlMs) return false;\n\t\t\treturn timingSafeEqual(signature, await mac(stamp));\n\t\t},\n\t\tasync renew(nonce) {\n\t\t\tconst age = Date.now() - Number(nonce.split('.')[0]);\n\t\t\treturn age > ttlMs / 2 ? await issue() : undefined;\n\t\t},\n\t};\n}\n",
|
|
8
|
+
"import type { DpopNonce } from './nonce';\nimport type { DpopReplayStore } from './replay-store';\n\n/** The signature algorithms a DPoP proof may use (RFC 9449 section 4.2). */\nexport type DpopAlgorithm = 'ES256' | 'EdDSA';\n\nexport interface DpopOptions {\n\t/**\n\t * The origin clients use to reach the API (`https://api.example.com`), what\n\t * a proof's `htu` must start with. Behind a proxy the request's own URL is\n\t * the internal one: this is the public one, never read from a header.\n\t */\n\treadonly origin: string;\n\t/** Where the `jti` of accepted proofs are remembered: `redisDpopReplayStore` in production, `memoryDpopReplayStore()` for tests. */\n\treadonly replay: DpopReplayStore;\n\t/** Proof algorithms accepted, `['ES256', 'EdDSA']` by default. */\n\treadonly algorithms?: readonly DpopAlgorithm[];\n\t/** How old a proof's `iat` may be, in seconds. 60 by default. */\n\treadonly maxAgeSec?: number;\n\t/** How far ahead of this server's clock an `iat` may be, in seconds. 5 by default. */\n\treadonly clockSkewSec?: number;\n\t/** Asks clients for a server nonce (RFC 9449 section 8): `hmacDpopNonce({ secret })`. Off by default. */\n\treadonly nonce?: DpopNonce;\n}\n\nexport interface ResolvedDpop {\n\treadonly origin: string;\n\treadonly replay: DpopReplayStore;\n\treadonly algorithms: readonly DpopAlgorithm[];\n\treadonly maxAgeSec: number;\n\treadonly clockSkewSec: number;\n\treadonly nonce: DpopNonce | undefined;\n}\n\n/** The options, checked, with their defaults. */\nexport function resolveDpop(options: DpopOptions): ResolvedDpop {\n\tlet origin: string;\n\ttry {\n\t\tconst url = new URL(options.origin);\n\t\tif (\n\t\t\t(url.protocol !== 'https:' && url.protocol !== 'http:') ||\n\t\t\turl.pathname !== '/' ||\n\t\t\turl.search !== '' ||\n\t\t\turl.hash !== '' ||\n\t\t\turl.username !== '' ||\n\t\t\turl.password !== ''\n\t\t) {\n\t\t\tthrow new Error('not an origin');\n\t\t}\n\t\torigin = url.origin;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`clavix: dpop.origin must be an origin such as \"https://api.example.com\", got ${JSON.stringify(options.origin)}`,\n\t\t);\n\t}\n\tif (typeof options.replay?.claim !== 'function') {\n\t\tthrow new TypeError('clavix: dpop.replay is required');\n\t}\n\tconst algorithms = options.algorithms ?? ['ES256', 'EdDSA'];\n\tif (\n\t\talgorithms.length === 0 ||\n\t\t!algorithms.every((a) => a === 'ES256' || a === 'EdDSA')\n\t) {\n\t\tthrow new TypeError('clavix: dpop.algorithms takes ES256, EdDSA or both');\n\t}\n\tconst maxAgeSec = options.maxAgeSec ?? 60;\n\tconst clockSkewSec = options.clockSkewSec ?? 5;\n\tif (!(Number.isFinite(maxAgeSec) && maxAgeSec > 0)) {\n\t\tthrow new TypeError(\n\t\t\t'clavix: dpop.maxAgeSec must be a finite number above 0',\n\t\t);\n\t}\n\tif (!(Number.isFinite(clockSkewSec) && clockSkewSec >= 0)) {\n\t\tthrow new TypeError(\n\t\t\t'clavix: dpop.clockSkewSec must be a finite number, 0 or more',\n\t\t);\n\t}\n\treturn {\n\t\torigin,\n\t\treplay: options.replay,\n\t\talgorithms,\n\t\tmaxAgeSec,\n\t\tclockSkewSec,\n\t\tnonce: options.nonce,\n\t};\n}\n",
|
|
9
|
+
"/**\n * Whether a proof's `htu` names this request: the configured public origin\n * (already normalised by `resolveDpop`) and the request's path, the query and the fragment ignored (RFC 9449\n * section 4.3). The scheme and host compare without case and without a\n * default port (`:443`, `:80`) as URL parsing normalises them; the path\n * compares exactly (a trailing slash matters; percent-escapes compare as\n * written, RFC 3986 6.2.2 normalisation is not applied, which can only refuse); a `htu` with userinfo never\n * matches.\n */\nexport function sameUrl(htu: string, origin: string, path: string): boolean {\n\ttry {\n\t\tconst claimed = new URL(htu);\n\t\tif (claimed.username !== '' || claimed.password !== '') return false;\n\t\t// never `new URL(path, origin)`: a path such as `//host/x` would replace the origin\n\t\treturn claimed.origin === origin && claimed.pathname === path;\n\t} catch {\n\t\treturn false;\n\t}\n}\n",
|
|
10
|
+
"import { sameUrl } from './htu';\nimport {\n\tdecode,\n\tencoder,\n\ttype Fields,\n\tisObject,\n\tjwkThumbprint,\n\ttype ProofKey,\n\tpublicKey,\n} from './jwk';\nimport { timingSafeEqual } from './nonce';\nimport type { DpopAlgorithm, ResolvedDpop } from './options';\n\n/** Why a request's DPoP check failed. */\nexport type DpopReason =\n\t| 'dpop_required'\n\t| 'dpop_unsupported'\n\t| 'dpop_unbound'\n\t| 'dpop_proof_missing'\n\t| 'dpop_proof_malformed'\n\t| 'dpop_proof_type'\n\t| 'dpop_proof_algorithm'\n\t| 'dpop_proof_key'\n\t| 'dpop_proof_signature'\n\t| 'dpop_proof_method'\n\t| 'dpop_proof_url'\n\t| 'dpop_proof_iat'\n\t| 'dpop_proof_jti'\n\t| 'dpop_proof_ath'\n\t| 'dpop_proof_thumbprint'\n\t| 'dpop_proof_replay'\n\t| 'dpop_malformed'\n\t| 'dpop_nonce';\n\nexport type ProofResult =\n\t| {\n\t\t\treadonly ok: true;\n\t\t\t/** A fresh nonce to send as `DPoP-Nonce`: the accepted one is near its end. */\n\t\t\treadonly nonce?: string;\n\t }\n\t| {\n\t\t\treadonly ok: false;\n\t\t\treadonly reason: DpopReason;\n\t\t\t/** Set with `dpop_nonce`: the nonce the client must use. */\n\t\t\treadonly nonce?: string;\n\t };\n\nexport interface ProofInput {\n\t/** The `DPoP` header value. */\n\treadonly proof: string | null;\n\t/** The request's method. */\n\treadonly method: string;\n\t/** The request's path, as the client sent it. */\n\treadonly path: string;\n\t/** The access token the proof is bound to. */\n\treadonly accessToken: string;\n\t/** The token's `cnf.jkt`. */\n\treadonly jkt: string;\n}\n\nconst MAX_JTI = 256;\n/** A proof stays remembered a little past the end of its `iat` window. */\nconst REMEMBER_MARGIN_MS = 5000;\nconst fail = (reason: DpopReason): ProofResult => ({ ok: false, reason });\n\ninterface Parsed {\n\treadonly head: string;\n\treadonly body: string;\n\treadonly signature: string;\n\treadonly header: Fields;\n\treadonly claims: Fields;\n}\n\n/** The three parts of a proof, decoded, or the reason it is no JWT. */\nfunction parse(proof: string): Parsed | DpopReason {\n\tconst parts = proof.split('.');\n\tif (parts.length !== 3) return 'dpop_proof_malformed';\n\tconst [head, body, signature] = parts as [string, string, string];\n\tconst header = decode(head);\n\tconst claims = decode(body);\n\t// `crit` names extensions this server does not know: RFC 7515 4.1.11 refuses them\n\tif (header === undefined || claims === undefined || 'crit' in header) {\n\t\treturn 'dpop_proof_malformed';\n\t}\n\treturn { head, body, signature, header, claims };\n}\n\n/**\n * The proof's key, once its header is right (`typ` exactly `dpop+jwt`, an\n * accepted `alg`, a public `jwk`) and its signature verifies with it.\n */\nasync function verifySignature(\n\tparsed: Parsed,\n\talgorithms: readonly DpopAlgorithm[],\n): Promise<ProofKey | DpopReason> {\n\tconst { header } = parsed;\n\tif (header.typ !== 'dpop+jwt') return 'dpop_proof_type';\n\tconst alg = algorithms.find((a) => a === header.alg);\n\tif (alg === undefined) return 'dpop_proof_algorithm';\n\tif (!isObject(header.jwk)) return 'dpop_proof_key';\n\tconst key = publicKey(header.jwk, alg);\n\tif (key === undefined) return 'dpop_proof_key';\n\ttry {\n\t\tconst valid = await crypto.subtle.verify(\n\t\t\talg === 'ES256'\n\t\t\t\t? { name: 'ECDSA', hash: 'SHA-256' }\n\t\t\t\t: { name: 'Ed25519' },\n\t\t\tawait crypto.subtle.importKey('jwk', key.jwk, key.params, false, [\n\t\t\t\t'verify',\n\t\t\t]),\n\t\t\tBuffer.from(parsed.signature, 'base64url'),\n\t\t\tencoder.encode(`${parsed.head}.${parsed.body}`),\n\t\t);\n\t\treturn valid ? key : 'dpop_proof_signature';\n\t} catch {\n\t\treturn 'dpop_proof_signature';\n\t}\n}\n\n/** The claims that tie the proof to this request and this token. */\nasync function checkClaims(\n\tclaims: Fields,\n\tinput: ProofInput,\n\toptions: ResolvedDpop,\n\tkey: ProofKey,\n): Promise<DpopReason | { readonly jti: string }> {\n\tif (claims.htm !== input.method) return 'dpop_proof_method';\n\tif (\n\t\ttypeof claims.htu !== 'string' ||\n\t\t!sameUrl(claims.htu, options.origin, input.path)\n\t) {\n\t\treturn 'dpop_proof_url';\n\t}\n\tconst nowSec = Date.now() / 1000;\n\tconst { iat, jti } = claims;\n\tif (\n\t\ttypeof iat !== 'number' ||\n\t\t!Number.isFinite(iat) ||\n\t\tiat < nowSec - options.maxAgeSec ||\n\t\tiat > nowSec + options.clockSkewSec\n\t) {\n\t\treturn 'dpop_proof_iat';\n\t}\n\tif (typeof jti !== 'string' || jti === '' || jti.length > MAX_JTI) {\n\t\treturn 'dpop_proof_jti';\n\t}\n\tconst hash = await crypto.subtle.digest(\n\t\t'SHA-256',\n\t\tencoder.encode(input.accessToken),\n\t);\n\tif (\n\t\ttypeof claims.ath !== 'string' ||\n\t\t!timingSafeEqual(claims.ath, Buffer.from(hash).toString('base64url'))\n\t) {\n\t\treturn 'dpop_proof_ath';\n\t}\n\tif (!timingSafeEqual(await jwkThumbprint(key.jwk), input.jkt)) {\n\t\treturn 'dpop_proof_thumbprint';\n\t}\n\treturn { jti };\n}\n\n/**\n * Checks a DPoP proof against RFC 9449 section 4.3, in the cheap-to-costly\n * order, and remembers its `jti` last: a proof refused for anything else is\n * never recorded.\n */\nexport async function verifyProof(\n\tinput: ProofInput,\n\toptions: ResolvedDpop,\n): Promise<ProofResult> {\n\tif (input.proof === null || input.proof === '') {\n\t\treturn fail('dpop_proof_missing');\n\t}\n\tconst parsed = parse(input.proof);\n\tif (typeof parsed === 'string') return fail(parsed);\n\tconst key = await verifySignature(parsed, options.algorithms);\n\tif (typeof key === 'string') return fail(key);\n\tconst checked = await checkClaims(parsed.claims, input, options, key);\n\tif (typeof checked === 'string') return fail(checked);\n\tlet renewed: string | undefined;\n\tif (options.nonce !== undefined) {\n\t\tconst { nonce } = parsed.claims;\n\t\tif (typeof nonce === 'string' && (await options.nonce.accepts(nonce))) {\n\t\t\trenewed = await options.nonce.renew?.(nonce);\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: 'dpop_nonce',\n\t\t\t\tnonce: await options.nonce.issue(),\n\t\t\t};\n\t\t}\n\t}\n\tconst ttlMs =\n\t\t(options.maxAgeSec + options.clockSkewSec) * 1000 + REMEMBER_MARGIN_MS;\n\tconst first = await options.replay.claim(\n\t\t`${input.jkt}:${checked.jti}`,\n\t\tttlMs,\n\t);\n\tif (!first) return fail('dpop_proof_replay');\n\treturn renewed === undefined ? { ok: true } : { ok: true, nonce: renewed };\n}\n",
|
|
11
|
+
"/**\n * Remembers the `jti` of the proofs already accepted, so that a proof is\n * used once. `claim` records `key` for `ttlMs` and answers `true` the first\n * time, `false` while it is still remembered. It must be atomic across the\n * processes that serve the API (Redis `SET NX PX`), and it may throw: a store\n * that cannot answer fails the request (a 500), it never lets a proof\n * through unchecked.\n */\nexport interface DpopReplayStore {\n\tclaim(key: string, ttlMs: number): Promise<boolean>;\n}\n\n/**\n * A replay store in the memory of this process: **for tests and a single\n * instance only**. Two instances behind a load balancer each have their own\n * memory, so a proof replayed on the other one is accepted: use\n * `redisDpopReplayStore` from `@softistx/alxia-redis` there. It holds at\n * most `maxEntries` live proofs (10 000 by default) and throws past that,\n * rather than growing without bound or forgetting a proof. Once full, each\n * claim first sweeps the expired entries, which costs O(`maxEntries`).\n */\nexport function memoryDpopReplayStore(\n\toptions: { readonly maxEntries?: number } = {},\n): DpopReplayStore {\n\tconst max = options.maxEntries ?? 10_000;\n\tconst seen = new Map<string, number>();\n\treturn {\n\t\tasync claim(key, ttlMs) {\n\t\t\tconst now = Date.now();\n\t\t\tconst until = seen.get(key);\n\t\t\tif (until !== undefined && until > now) return false;\n\t\t\tif (seen.size >= max) {\n\t\t\t\tfor (const [stored, expiry] of seen) {\n\t\t\t\t\tif (expiry <= now) seen.delete(stored);\n\t\t\t\t}\n\t\t\t\tif (seen.size >= max) {\n\t\t\t\t\tthrow new Error('memoryDpopReplayStore: full (use a shared store)');\n\t\t\t\t}\n\t\t\t}\n\t\t\tseen.set(key, now + ttlMs);\n\t\t\treturn true;\n\t\t},\n\t};\n}\n",
|
|
12
|
+
"import type { StandardSchemaV1 } from '@softistx/alxia';\nimport {\n\ttype Bearer,\n\ttype BearerExtension,\n\tbearer,\n\ttype UnauthorizedBody,\n\ttype UnauthorizedProblem,\n\ttype Verifier,\n} from '@softistx/alxia-jwt';\nimport { type DpopReason, type ResolvedDpop, verifyProof } from './dpop';\nimport type { ClavixPrincipal } from './principal';\n\n/** The body of a Clavix 401: the reasons of `@softistx/alxia-jwt`'s, and the DPoP ones. */\nexport type ClavixUnauthorizedBody = UnauthorizedBody<DpopReason>;\n\n/** The 401 under `alxia({ errors: 'problem' })`. */\nexport type ClavixUnauthorizedProblem = UnauthorizedProblem<DpopReason>;\n\n/** What `clavix().bearer()` makes: a middleware that gives `user`, or answers the 401. */\nexport type ClavixGuard = Bearer<\n\tStandardSchemaV1<unknown, ClavixPrincipal>,\n\tDpopReason\n>;\n\nexport interface GuardOptions {\n\treadonly jwt: Verifier;\n\treadonly schema: StandardSchemaV1<unknown, ClavixPrincipal>;\n\treadonly cookie?: string | undefined;\n\treadonly dpop?: ResolvedDpop | undefined;\n}\n\n/**\n * The token's `cnf.jkt`: `undefined` for a token with no key binding,\n * `null` when `cnf` is present but not a plain object, or has a `jkt` that\n * is not a non-empty string (so the\n * guard does not depend on the verifier's profile to refuse it).\n */\nfunction boundKey(claims: {\n\treadonly cnf?: unknown;\n}): string | null | undefined {\n\tconst { cnf } = claims;\n\tif (cnf === undefined) return undefined;\n\tif (typeof cnf !== 'object' || cnf === null || Array.isArray(cnf)) {\n\t\treturn null;\n\t}\n\tif (!('jkt' in cnf)) return undefined;\n\treturn typeof cnf.jkt === 'string' && cnf.jkt !== '' ? cnf.jkt : null;\n}\n\nconst isProofReason = (reason: string): boolean =>\n\treason.startsWith('dpop_proof_');\n\n/** The DPoP half of the guard, as an extension of `@softistx/alxia-jwt`'s `bearer()`. */\nfunction dpopExtension(\n\tdpop: ResolvedDpop | undefined,\n): BearerExtension<DpopReason> {\n\tconst algs = dpop?.algorithms.join(' ') ?? '';\n\tconst scheme = (error: string, description?: string) =>\n\t\t`DPoP error=\"${error}\"${description === undefined ? '' : `, error_description=\"${description}\"`}, algs=\"${algs}\"`;\n\treturn {\n\t\tschemes: ['DPoP'],\n\t\tasync bound({ request, token, scheme: used, claims }) {\n\t\t\tconst jkt = boundKey(claims);\n\t\t\tif (jkt === null) return { reason: 'dpop_malformed' };\n\t\t\tif (used !== 'DPoP') {\n\t\t\t\t// a bound token as a bearer is a stolen token: no proof was given\n\t\t\t\treturn jkt === undefined ? undefined : { reason: 'dpop_required' };\n\t\t\t}\n\t\t\tif (dpop === undefined) return { reason: 'dpop_unsupported' };\n\t\t\tif (jkt === undefined) return { reason: 'dpop_unbound' };\n\t\t\tconst proof = await verifyProof(\n\t\t\t\t{\n\t\t\t\t\tproof: request.headers.get('dpop'),\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\tpath: new URL(request.url).pathname,\n\t\t\t\t\taccessToken: token,\n\t\t\t\t\tjkt,\n\t\t\t\t},\n\t\t\t\tdpop,\n\t\t\t);\n\t\t\tif (proof.ok) {\n\t\t\t\treturn proof.nonce === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { headers: { 'dpop-nonce': proof.nonce } };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\treason: proof.reason,\n\t\t\t\t...(proof.nonce === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { headers: { 'dpop-nonce': proof.nonce } }),\n\t\t\t};\n\t\t},\n\t\tchallenge(reason, used) {\n\t\t\tif (dpop === undefined) return undefined;\n\t\t\tif (reason === 'missing') return `Bearer, DPoP algs=\"${algs}\"`;\n\t\t\tif (reason === 'dpop_required') {\n\t\t\t\treturn scheme(\n\t\t\t\t\t'invalid_token',\n\t\t\t\t\t'the token is bound to a key: use the DPoP scheme with a proof',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (reason === 'dpop_unbound') {\n\t\t\t\treturn scheme(\n\t\t\t\t\t'invalid_token',\n\t\t\t\t\t'the token is not bound to a key: use the Bearer scheme',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (reason === 'dpop_nonce') return scheme('use_dpop_nonce');\n\t\t\tif (isProofReason(reason)) return scheme('invalid_dpop_proof');\n\t\t\t// a token refused under the DPoP scheme is answered in that scheme\n\t\t\tif (used === 'DPoP' && reason !== 'insufficient_user_authentication') {\n\t\t\t\treturn scheme('invalid_token');\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\n/** The guard of `clavix().bearer()`: `Bearer` and, with `dpop`, `DPoP` tokens. */\nexport function guard(options: GuardOptions): ClavixGuard {\n\treturn bearer({\n\t\tjwt: options.jwt,\n\t\tschema: options.schema,\n\t\t...(options.cookie === undefined ? {} : { cookie: options.cookie }),\n\t\textension: dpopExtension(options.dpop),\n\t});\n}\n",
|
|
6
13
|
"/** The allowed issuers of a Clavix deployment, and the tenant each one stands for. */\nexport interface IssuerRules {\n\t/** A lowercase DNS name without a dot at either end. */\n\treadonly domain: string | undefined;\n\t/** Issuer to tenant (`undefined` when the list gives none). */\n\treadonly listed: ReadonlyMap<string, string | undefined>;\n}\n\nconst LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\nconst LOCAL = new Set(['localhost', '127.0.0.1', '[::1]']);\n\n/** `domain` as a lowercase ASCII DNS name, or a `TypeError`. */\nexport function normaliseDomain(domain: string): string {\n\tconst name = domain\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/^\\./, '')\n\t\t.replace(/\\.$/, '');\n\tconst labels = name.split('.');\n\tif (\n\t\tlabels.length < 2 ||\n\t\tname.length > 253 ||\n\t\t!labels.every((label) => LABEL.test(label) && !label.startsWith('xn--'))\n\t) {\n\t\tthrow new TypeError(\n\t\t\t`clavix: domain must be an ASCII DNS name such as \"clavix.example\", got ${JSON.stringify(domain)}`,\n\t\t);\n\t}\n\treturn name;\n}\n\n/** The listed issuers as a map; an issuer must be an `https` URL, or `http` on this machine. */\nexport function listIssuers(\n\tissuers: readonly string[] | Readonly<Record<string, string>>,\n): Map<string, string | undefined> {\n\tconst map = new Map<string, string | undefined>();\n\tconst entries: [string, string | undefined][] = Array.isArray(issuers)\n\t\t? issuers.map((issuer) => [issuer, undefined])\n\t\t: Object.entries(issuers);\n\tfor (const [issuer, tenant] of entries) {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(issuer);\n\t\t} catch {\n\t\t\tthrow new TypeError(`clavix: issuer is not a URL: ${issuer}`);\n\t\t}\n\t\tif (\n\t\t\turl.protocol !== 'https:' &&\n\t\t\t!(url.protocol === 'http:' && LOCAL.has(url.hostname))\n\t\t) {\n\t\t\tthrow new TypeError(`clavix: issuer must be an https URL: ${issuer}`);\n\t\t}\n\t\tif (tenant === '') {\n\t\t\tthrow new TypeError(`clavix: the tenant of ${issuer} is empty`);\n\t\t}\n\t\tmap.set(issuer, tenant);\n\t}\n\treturn map;\n}\n\n/**\n * The slug of `https://<slug>.<domain>`, exactly: one DNS label in front of\n * the domain, lowercase ASCII (so no IDN, no `xn--` look-alike), and no port,\n * userinfo, path, query, fragment, trailing slash or trailing dot.\n */\nfunction slugOf(issuer: string, domain: string): string | undefined {\n\tconst prefix = 'https://';\n\tconst suffix = `.${domain}`;\n\tif (!issuer.startsWith(prefix) || !issuer.endsWith(suffix)) return undefined;\n\tconst label = issuer.slice(prefix.length, issuer.length - suffix.length);\n\treturn LABEL.test(label) && !label.startsWith('xn--') ? label : undefined;\n}\n\n/**\n * Whether `issuer` is allowed, and for which tenant: a listed issuer (byte\n * for byte) first, then the domain pattern. `undefined` when refused.\n */\nexport function resolveIssuer(\n\trules: IssuerRules,\n\tissuer: string,\n): { readonly tenant: string | undefined } | undefined {\n\tif (rules.listed.has(issuer)) return { tenant: rules.listed.get(issuer) };\n\tif (rules.domain === undefined) return undefined;\n\tconst slug = slugOf(issuer, rules.domain);\n\treturn slug === undefined ? undefined : { tenant: slug };\n}\n",
|
|
7
14
|
"/** A map that keeps at most `max` entries, dropping the least recently used. */\nexport class Lru<V> {\n\treadonly #entries = new Map<string, V>();\n\treadonly #max: number;\n\n\tconstructor(max: number) {\n\t\tthis.#max = max;\n\t}\n\n\tget size(): number {\n\t\treturn this.#entries.size;\n\t}\n\n\tget(key: string): V | undefined {\n\t\tconst value = this.#entries.get(key);\n\t\tif (value === undefined) return undefined;\n\t\tthis.#entries.delete(key);\n\t\tthis.#entries.set(key, value);\n\t\treturn value;\n\t}\n\n\tdelete(key: string): void {\n\t\tthis.#entries.delete(key);\n\t}\n\n\tset(key: string, value: V): void {\n\t\tthis.#entries.delete(key);\n\t\tthis.#entries.set(key, value);\n\t\tif (this.#entries.size > this.#max) {\n\t\t\tconst oldest = this.#entries.keys().next();\n\t\t\tif (!oldest.done) this.#entries.delete(oldest.value);\n\t\t}\n\t}\n}\n",
|
|
8
15
|
"import type { StandardSchemaV1 } from '@softistx/alxia';\nimport type { JwtClaims } from '@softistx/alxia-jwt';\n\n/** Who a verified Clavix access token stands for: what routes behind `bearer()` read as `user`. */\nexport interface ClavixPrincipal {\n\t/** The token's `sub`. */\n\treadonly subject: string;\n\t/** The tenant of the issuer: the slug of a pattern issuer, or the mapped name of a listed one. */\n\treadonly tenant: string;\n\t/** The token's `iss`. */\n\treadonly issuer: string;\n\t/** The client the token was issued to (`client_id`). */\n\treadonly clientId: string;\n\t/** The granted scopes: `scope` split on spaces, `[]` when absent. */\n\treadonly scopes: readonly string[];\n\t/** The subject's roles, `[]` when absent. */\n\treadonly roles: readonly string[];\n\t/** The verified claims, untouched (`permissions`, `cnf`, …). */\n\treadonly claims: JwtClaims;\n}\n\nconst isString = (value: unknown): value is string =>\n\ttypeof value === 'string' && value !== '';\n\n/**\n * The Standard Schema that maps verified claims to a principal. A claim an\n * RFC 9068 token must carry but does not is an issue, so a 401 `claims`.\n */\nexport function principalSchema(\n\ttenantOf: (issuer: string) => string | undefined,\n): StandardSchemaV1<unknown, ClavixPrincipal> {\n\treturn {\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: '@softistx/alxia-clavix',\n\t\t\tvalidate(value) {\n\t\t\t\tconst claims = value as JwtClaims;\n\t\t\t\tconst issues: { message: string; path: string[] }[] = [];\n\t\t\t\tconst need = (name: string) =>\n\t\t\t\t\tissues.push({ message: `${name} is required`, path: [name] });\n\t\t\t\tconst { iss, sub, client_id: clientId, scope, roles } = claims;\n\t\t\t\tif (!isString(iss)) need('iss');\n\t\t\t\tif (!isString(sub)) need('sub');\n\t\t\t\tif (!isString(clientId)) need('client_id');\n\t\t\t\tif (scope !== undefined && typeof scope !== 'string') {\n\t\t\t\t\tissues.push({ message: 'scope must be a string', path: ['scope'] });\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\troles !== undefined &&\n\t\t\t\t\t!(Array.isArray(roles) && roles.every((r) => typeof r === 'string'))\n\t\t\t\t) {\n\t\t\t\t\tissues.push({\n\t\t\t\t\t\tmessage: 'roles must be an array of strings',\n\t\t\t\t\t\tpath: ['roles'],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst tenant = isString(iss) ? tenantOf(iss) : undefined;\n\t\t\t\tif (isString(iss) && tenant === undefined) {\n\t\t\t\t\tissues.push({ message: 'the issuer has no tenant', path: ['iss'] });\n\t\t\t\t}\n\t\t\t\tif (issues.length > 0) return { issues };\n\t\t\t\treturn {\n\t\t\t\t\tvalue: {\n\t\t\t\t\t\tsubject: sub as string,\n\t\t\t\t\t\ttenant: tenant as string,\n\t\t\t\t\t\tissuer: iss as string,\n\t\t\t\t\t\tclientId: clientId as string,\n\t\t\t\t\t\tscopes:\n\t\t\t\t\t\t\ttypeof scope === 'string' ? scope.split(' ').filter(Boolean) : [],\n\t\t\t\t\t\troles: roles ?? [],\n\t\t\t\t\t\tclaims,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t};\n}\n",
|
|
9
16
|
"const isObject = (value: unknown): value is Record<string, unknown> =>\n\tvalue !== null && typeof value === 'object' && !Array.isArray(value);\n\n/** The `iss` of a token's payload, read WITHOUT verifying anything: it only picks whose keys to verify with. */\nexport function unverifiedIssuer(token: string): string | undefined {\n\tconst parts = token.split('.');\n\tconst payload = parts[1];\n\tif (parts.length !== 3 || payload === undefined) return undefined;\n\tif (!/^[A-Za-z0-9_-]+$/.test(payload)) return undefined;\n\ttry {\n\t\tconst claims: unknown = JSON.parse(\n\t\t\tnew TextDecoder('utf-8', { fatal: true }).decode(\n\t\t\t\tBuffer.from(payload, 'base64url'),\n\t\t\t),\n\t\t);\n\t\treturn isObject(claims) && typeof claims['iss'] === 'string'\n\t\t\t? claims['iss']\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n",
|
|
10
17
|
"import {\n\tdefineMiddleware,\n\terrorFormat,\n\ttype Middleware,\n\tmarkFactory,\n\ttype Next,\n\ttype Problem,\n\tproblem,\n\tproblemOf,\n\ttype Reply,\n} from '@softistx/alxia';\n\n/** The body of the 403. */\nexport interface InsufficientScopeBody {\n\treadonly error: 'forbidden';\n\treadonly reason: 'insufficient_scope';\n\t/** The scopes the route needs, space-separated. */\n\treadonly scope: string;\n}\n\n/** The 403 under `alxia({ errors: 'problem' })`: `reason` and `scope` are its extensions. */\nexport type InsufficientScopeProblem = Problem<\n\t403,\n\tOmit<InsufficientScopeBody, 'error'>\n>;\n\n/**\n * What `requireScope()` makes: it reads the `user` that `bearer()` gives and\n * lets the request on, or answers the 403.\n */\nexport type RequireScope = Middleware<\n\t{ user: { readonly scopes: readonly string[] } },\n\tPromise<\n\t\tReply<403, InsufficientScopeBody | InsufficientScopeProblem> | Next<object>\n\t>\n>;\n\n/**\n * A guard after `bearer()`: the token must carry every one of `scopes`, or a\n * 403 whose `WWW-Authenticate: Bearer error=\"insufficient_scope\", scope=\"…\"`\n * names them (RFC 6750 section 3.1).\n *\n * ```ts\n * app.use(auth.bearer()).get('/invoices', requireScope('invoices:read'), ({ user, reply }) => …)\n * ```\n */\nexport function requireScope(...scopes: readonly string[]): RequireScope {\n\tif (\n\t\tscopes.length === 0 ||\n\t\tscopes.some((s) => !/^[\\x21\\x23-\\x5B\\x5D-\\x7E]+$/.test(s))\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'requireScope: give scopes, each a non-empty token without spaces or quotes',\n\t\t);\n\t}\n\tconst scope = scopes.join(' ');\n\tconst challenge = {\n\t\theaders: {\n\t\t\t'www-authenticate': `Bearer error=\"insufficient_scope\", scope=\"${scope}\"`,\n\t\t},\n\t};\n\treturn defineMiddleware<{ user: { readonly scopes: readonly string[] } }>()(\n\t\tasync function requireScope(ctx, next) {\n\t\t\tif (scopes.every((s) => ctx.user.scopes.includes(s))) return next();\n\t\t\tconst why = { reason: 'insufficient_scope', scope } as const;\n\t\t\tif (errorFormat(ctx) === 'problem') {\n\t\t\t\treturn problem(\n\t\t\t\t\tproblemOf(ctx, {\n\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\tdetail: `The access token lacks the scope: ${scope}`,\n\t\t\t\t\t\t...why,\n\t\t\t\t\t}),\n\t\t\t\t\tchallenge,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ctx.reply(403, { error: 'forbidden', ...why }, challenge);\n\t\t},\n\t) as RequireScope;\n}\n\nmarkFactory(requireScope);\n"
|
|
11
18
|
],
|
|
12
|
-
"mappings": ";AACA;AAAA;AAAA;AAAA;;;ACOA,IAAM,QAAQ;AACd,IAAM,QAAQ,IAAI,IAAI,CAAC,aAAa,aAAa,OAAO,CAAC;AAGlD,SAAS,eAAe,CAAC,QAAwB;AAAA,EACvD,MAAM,OAAO,OACX,KAAK,EACL,YAAY,EACZ,QAAQ,OAAO,EAAE,EACjB,QAAQ,OAAO,EAAE;AAAA,EACnB,MAAM,SAAS,KAAK,MAAM,GAAG;AAAA,EAC7B,IACC,OAAO,SAAS,KAChB,KAAK,SAAS,OACd,CAAC,OAAO,MAAM,CAAC,UAAU,MAAM,KAAK,KAAK,KAAK,CAAC,MAAM,WAAW,MAAM,CAAC,GACtE;AAAA,IACD,MAAM,IAAI,UACT,0EAA0E,KAAK,UAAU,MAAM,GAChG;AAAA,EACD;AAAA,EACA,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K;AAAA,QACd,QAAQ;AAAA,QACR,QAAQ,qCAAqC;AAAA,WAC1C;AAAA,MACJ,CAAC,GACD,SACD;AAAA,IACD;AAAA,IACA,OAAO,IAAI,MAAM,KAAK,EAAE,OAAO,gBAAgB,IAAI,GAAG,SAAS;AAAA,GAEjE;AAAA;AAGD,YAAY,YAAY;",
|
|
20
|
+
"debugId": "A0E8A24ACF0832D464756E2164756E21",
|
|
14
21
|
"names": []
|
|
15
22
|
}
|
|
@@ -52,4 +52,8 @@ extensions. Scopes are non-empty strings without spaces or quotes; give at least
|
|
|
52
52
|
## 401 reasons
|
|
53
53
|
|
|
54
54
|
`missing` (no token), `malformed`, `issuer`, `audience`, `type`, `signature`, `algorithm`, `expired`,
|
|
55
|
-
`not_yet_valid`, `key`, `keys_unavailable`, `claims
|
|
55
|
+
`not_yet_valid`, `key`, `keys_unavailable`, `claims`, and with DPoP (RFC 9449): `dpop_required`,
|
|
56
|
+
`dpop_unsupported`, `dpop_malformed`, `dpop_unbound`, `dpop_proof_*` (the check of the proof that failed) and `dpop_nonce`.
|
|
57
|
+
The challenge follows the scheme: `Bearer error="invalid_token"` for a bearer token, `DPoP
|
|
58
|
+
error="invalid_token"`, `invalid_dpop_proof` or `use_dpop_nonce` (with `algs` and a `DPoP-Nonce`
|
|
59
|
+
header) for the DPoP ones. See [Troubleshooting](../troubleshooting.md).
|