cursedauth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/account/AccountMenu.d.ts +153 -0
- package/dist/account/AccountMenu.d.ts.map +1 -0
- package/dist/account/AccountMenu.js +388 -0
- package/dist/account/AccountMenu.js.map +1 -0
- package/dist/account/AccountNotice.d.ts +35 -0
- package/dist/account/AccountNotice.d.ts.map +1 -0
- package/dist/account/AccountNotice.js +133 -0
- package/dist/account/AccountNotice.js.map +1 -0
- package/dist/account/accountNotice.state.d.ts +20 -0
- package/dist/account/accountNotice.state.d.ts.map +1 -0
- package/dist/account/accountNotice.state.js +55 -0
- package/dist/account/accountNotice.state.js.map +1 -0
- package/dist/account/avatar.d.ts +37 -0
- package/dist/account/avatar.d.ts.map +1 -0
- package/dist/account/avatar.js +47 -0
- package/dist/account/avatar.js.map +1 -0
- package/dist/accountSlot.client.d.ts +113 -0
- package/dist/accountSlot.client.d.ts.map +1 -0
- package/dist/accountSlot.client.js +330 -0
- package/dist/accountSlot.client.js.map +1 -0
- package/dist/accountSlots.d.ts +192 -0
- package/dist/accountSlots.d.ts.map +1 -0
- package/dist/accountSlots.js +274 -0
- package/dist/accountSlots.js.map +1 -0
- package/dist/auth.d.ts +167 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +310 -0
- package/dist/auth.js.map +1 -0
- package/dist/auth.server.d.ts +35 -0
- package/dist/auth.server.d.ts.map +1 -0
- package/dist/auth.server.js +67 -0
- package/dist/auth.server.js.map +1 -0
- package/dist/clientDescription.d.ts +186 -0
- package/dist/clientDescription.d.ts.map +1 -0
- package/dist/clientDescription.js +278 -0
- package/dist/clientDescription.js.map +1 -0
- package/dist/constantTime.d.ts +35 -0
- package/dist/constantTime.d.ts.map +1 -0
- package/dist/constantTime.js +46 -0
- package/dist/constantTime.js.map +1 -0
- package/dist/contentCensus.d.ts +59 -0
- package/dist/contentCensus.d.ts.map +1 -0
- package/dist/contentCensus.js +55 -0
- package/dist/contentCensus.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/mountGatedApp.d.ts +128 -0
- package/dist/mountGatedApp.d.ts.map +1 -0
- package/dist/mountGatedApp.js +107 -0
- package/dist/mountGatedApp.js.map +1 -0
- package/dist/runtimeMode.d.ts +28 -0
- package/dist/runtimeMode.d.ts.map +1 -0
- package/dist/runtimeMode.js +37 -0
- package/dist/runtimeMode.js.map +1 -0
- package/dist/secureRequest.d.ts +22 -0
- package/dist/secureRequest.d.ts.map +1 -0
- package/dist/secureRequest.js +27 -0
- package/dist/secureRequest.js.map +1 -0
- package/dist/sso.d.ts +373 -0
- package/dist/sso.d.ts.map +1 -0
- package/dist/sso.js +420 -0
- package/dist/sso.js.map +1 -0
- package/dist/ssoAutoSignIn.d.ts +272 -0
- package/dist/ssoAutoSignIn.d.ts.map +1 -0
- package/dist/ssoAutoSignIn.js +431 -0
- package/dist/ssoAutoSignIn.js.map +1 -0
- package/dist/ssoConsumer.server.d.ts +295 -0
- package/dist/ssoConsumer.server.d.ts.map +1 -0
- package/dist/ssoConsumer.server.js +972 -0
- package/dist/ssoConsumer.server.js.map +1 -0
- package/dist/stageIdentity.d.ts +72 -0
- package/dist/stageIdentity.d.ts.map +1 -0
- package/dist/stageIdentity.js +74 -0
- package/dist/stageIdentity.js.map +1 -0
- package/dist/ui/popover.d.ts +190 -0
- package/dist/ui/popover.d.ts.map +1 -0
- package/dist/ui/popover.js +351 -0
- package/dist/ui/popover.js.map +1 -0
- package/dist/userSessions.d.ts +205 -0
- package/dist/userSessions.d.ts.map +1 -0
- package/dist/userSessions.js +419 -0
- package/dist/userSessions.js.map +1 -0
- package/package.json +115 -0
- package/src/account/AccountMenu.tsx +729 -0
- package/src/account/AccountNotice.tsx +223 -0
- package/src/account/accountNotice.state.ts +66 -0
- package/src/account/avatar.ts +50 -0
- package/src/accountSlot.client.ts +362 -0
- package/src/accountSlots.ts +305 -0
- package/src/auth.server.ts +89 -0
- package/src/auth.ts +515 -0
- package/src/clientDescription.ts +366 -0
- package/src/constantTime.ts +45 -0
- package/src/contentCensus.ts +106 -0
- package/src/index.ts +58 -0
- package/src/mountGatedApp.ts +240 -0
- package/src/runtimeMode.ts +37 -0
- package/src/secureRequest.ts +25 -0
- package/src/sso.ts +767 -0
- package/src/ssoAutoSignIn.ts +544 -0
- package/src/ssoConsumer.server.ts +1260 -0
- package/src/stageIdentity.ts +76 -0
- package/src/ui/popover.ts +390 -0
- package/src/userSessions.ts +678 -0
package/dist/sso.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SSO grant — the wire credential between `apps/auth` (the accounts
|
|
3
|
+
* satellite) and every satellite that shares its user set.
|
|
4
|
+
*
|
|
5
|
+
* ── The model (2026-07-28) ──────────────────────────────────────────────────
|
|
6
|
+
* One satellite (`apps/auth`) owns the user registry: passwords, reset emails,
|
|
7
|
+
* the admin page. A satellite that wants a signed-in user redirects the browser
|
|
8
|
+
* to auth's `/sso/authorize`; auth answers with a GRANT — a short-lived,
|
|
9
|
+
* single-audience, Ed25519-signed statement "this user, for that app, right
|
|
10
|
+
* now" — and the satellite trades it for its OWN per-app session cookie and
|
|
11
|
+
* never sees a password. Auth built once; every future private satellite
|
|
12
|
+
* integrates by mounting the consumer (`cursedauth/sso-consumer`).
|
|
13
|
+
*
|
|
14
|
+
* ── Why Ed25519 and not an HMAC shared secret ───────────────────────────────
|
|
15
|
+
* A shared secret would let ANY satellite mint grants for every other one — the
|
|
16
|
+
* blast radius of one compromised app becomes the whole fleet. With a keypair,
|
|
17
|
+
* satellites hold only the PUBLIC key; compromising one leaks nothing that can
|
|
18
|
+
* sign. Ed25519 over RSA/ECDSA: built into node:crypto, no parameters to get
|
|
19
|
+
* wrong, 64-byte signatures.
|
|
20
|
+
*
|
|
21
|
+
* ── Why grants are single-use and 60 seconds ────────────────────────────────
|
|
22
|
+
* The grant rides a redirect URL, and URLs leak — proxy logs, referrer headers,
|
|
23
|
+
* a pasted link. A leaked grant must therefore be worth as little as possible:
|
|
24
|
+
* it expires in seconds, names exactly one consumer app (`aud`), and the
|
|
25
|
+
* consumer refuses to accept the same nonce twice (`createNonceGuard`). This is
|
|
26
|
+
* the OAuth authorization-code posture without the second server-to-server
|
|
27
|
+
* round trip — the signature already proves the issuer, so there is nothing a
|
|
28
|
+
* code exchange would add here but a runtime dependency on auth being up.
|
|
29
|
+
*
|
|
30
|
+
* The payload deliberately carries the user snapshot (email, name, admin) so a
|
|
31
|
+
* consumer can answer "who is this?" without ever calling auth at request time.
|
|
32
|
+
* Auth being down means new LOGINS fail; every existing session keeps working.
|
|
33
|
+
*/
|
|
34
|
+
import { createHash, generateKeyPairSync, createPrivateKey, createPublicKey, sign as edSign, verify as edVerify, } from "node:crypto";
|
|
35
|
+
/** How long a grant is valid. Long enough for one redirect hop on a slow
|
|
36
|
+
* connection, short enough that a logged URL is stale before anyone reads
|
|
37
|
+
* the log. */
|
|
38
|
+
export const GRANT_TTL_MS = 60 * 1000;
|
|
39
|
+
export const kidOfPublicKeyPem = (publicKeyPem) => {
|
|
40
|
+
const der = createPublicKey(publicKeyPem).export({ type: "spki", format: "der" });
|
|
41
|
+
return createHash("sha256").update(der).digest("hex").slice(0, 16);
|
|
42
|
+
};
|
|
43
|
+
export function generateSsoKeyPair() {
|
|
44
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
45
|
+
const privateKeyPem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
|
46
|
+
const publicKeyPem = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
47
|
+
return { privateKeyPem, publicKeyPem, kid: kidOfPublicKeyPem(publicKeyPem) };
|
|
48
|
+
}
|
|
49
|
+
const b64url = (buf) => buf.toString("base64url");
|
|
50
|
+
/** `base64url(payload JSON).base64url(signature)` — no header, because the
|
|
51
|
+
* algorithm is pinned (Ed25519) and the kid lives in the payload. Not a JWT on
|
|
52
|
+
* purpose: nothing here should ever be handed to a general JWT library with
|
|
53
|
+
* its algorithm-confusion surface. */
|
|
54
|
+
export function mintGrant(options) {
|
|
55
|
+
const now = options.now?.() ?? Date.now();
|
|
56
|
+
const claims = {
|
|
57
|
+
...options.user,
|
|
58
|
+
aud: options.aud,
|
|
59
|
+
iat: now,
|
|
60
|
+
exp: now + (options.ttlMs ?? GRANT_TTL_MS),
|
|
61
|
+
nonce: b64url(Buffer.from(crypto.getRandomValues(new Uint8Array(16)))),
|
|
62
|
+
kid: options.kid,
|
|
63
|
+
v: 1,
|
|
64
|
+
};
|
|
65
|
+
const payload = b64url(Buffer.from(JSON.stringify(claims), "utf8"));
|
|
66
|
+
const key = createPrivateKey(options.privateKeyPem);
|
|
67
|
+
const signature = edSign(null, Buffer.from(payload, "utf8"), key);
|
|
68
|
+
return `${payload}.${b64url(signature)}`;
|
|
69
|
+
}
|
|
70
|
+
// ── Revocation tickets (2026-08-01) ─────────────────────────────────────────
|
|
71
|
+
// A grant says "let this person in"; a ticket says "throw this person out". The
|
|
72
|
+
// cascade exists because a consumer NEVER calls auth at request time — that is
|
|
73
|
+
// the design's whole point (auth down breaks new logins and nothing else) — and
|
|
74
|
+
// the cost of it is that disabling or deleting an account at auth left every
|
|
75
|
+
// already-minted per-app cookie (roms_session, hobbies_session…) working until
|
|
76
|
+
// it expired. So auth pushes instead: one signed, single-audience, 60-second
|
|
77
|
+
// ticket per registered consumer.
|
|
78
|
+
//
|
|
79
|
+
// It rides the SAME Ed25519 keypair as grants, and is deliberately impossible
|
|
80
|
+
// to confuse with one in either direction: `k` ("kind") is checked before
|
|
81
|
+
// anything else in each verifier, so a grant handed to the revoke endpoint is
|
|
82
|
+
// refused, and a ticket replayed at a callback is refused. Sharing the keypair
|
|
83
|
+
// is the point — a consumer that can verify grants can verify revocations with
|
|
84
|
+
// no new key to distribute, and the private half still never leaves auth.
|
|
85
|
+
/** How long a revocation ticket is valid — same posture as a grant. */
|
|
86
|
+
export const REVOCATION_TTL_MS = 60 * 1000;
|
|
87
|
+
export function mintRevocation(options) {
|
|
88
|
+
const now = options.now?.() ?? Date.now();
|
|
89
|
+
if (options.sid && options.action !== "revoke") {
|
|
90
|
+
// Thrown at the MINT, not left for the consumer to refuse: a caller that
|
|
91
|
+
// built this ticket has a bug in its own logic, and finding out at the far
|
|
92
|
+
// end (as a 401 from another app) is how that becomes a mystery.
|
|
93
|
+
throw new Error(`a ${options.action} ticket cannot name a single session`);
|
|
94
|
+
}
|
|
95
|
+
const claims = {
|
|
96
|
+
k: "revoke",
|
|
97
|
+
aud: options.aud,
|
|
98
|
+
sub: options.sub,
|
|
99
|
+
action: options.action,
|
|
100
|
+
...(options.sid ? { sid: options.sid } : {}),
|
|
101
|
+
iat: now,
|
|
102
|
+
exp: now + (options.ttlMs ?? REVOCATION_TTL_MS),
|
|
103
|
+
nonce: b64url(Buffer.from(crypto.getRandomValues(new Uint8Array(16)))),
|
|
104
|
+
kid: options.kid,
|
|
105
|
+
v: 1,
|
|
106
|
+
};
|
|
107
|
+
const payload = b64url(Buffer.from(JSON.stringify(claims), "utf8"));
|
|
108
|
+
const key = createPrivateKey(options.privateKeyPem);
|
|
109
|
+
const signature = edSign(null, Buffer.from(payload, "utf8"), key);
|
|
110
|
+
return `${payload}.${b64url(signature)}`;
|
|
111
|
+
}
|
|
112
|
+
export function verifyRevocation(ticket, options) {
|
|
113
|
+
const parts = ticket.split(".");
|
|
114
|
+
if (parts.length !== 2)
|
|
115
|
+
return { ok: false, reason: "malformed ticket" };
|
|
116
|
+
const [payload, signature] = parts;
|
|
117
|
+
let claims;
|
|
118
|
+
try {
|
|
119
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return { ok: false, reason: "malformed payload" };
|
|
123
|
+
}
|
|
124
|
+
// The kind check comes before every other semantic check: a GRANT presented
|
|
125
|
+
// here must be refused as a grant, not fall through to some field test that
|
|
126
|
+
// happens to pass.
|
|
127
|
+
if (claims?.k !== "revoke")
|
|
128
|
+
return { ok: false, reason: "not a revocation ticket" };
|
|
129
|
+
if (claims.v !== 1)
|
|
130
|
+
return { ok: false, reason: "unsupported ticket version" };
|
|
131
|
+
if (!strField(claims.aud) ||
|
|
132
|
+
!strField(claims.sub) ||
|
|
133
|
+
!strField(claims.nonce) ||
|
|
134
|
+
!strField(claims.kid) ||
|
|
135
|
+
(claims.action !== "revoke" && claims.action !== "delete") ||
|
|
136
|
+
typeof claims.iat !== "number" ||
|
|
137
|
+
typeof claims.exp !== "number" ||
|
|
138
|
+
// Optional, but when present it must be a real handle — and never on a
|
|
139
|
+
// `delete`, which has no one-session meaning. Refused rather than ignored:
|
|
140
|
+
// a ticket that says something the verifier does not act on is a ticket
|
|
141
|
+
// whose author believes something untrue about what it will do.
|
|
142
|
+
(claims.sid !== undefined && !strField(claims.sid)) ||
|
|
143
|
+
(claims.sid !== undefined && claims.action !== "revoke")) {
|
|
144
|
+
return { ok: false, reason: "malformed claims" };
|
|
145
|
+
}
|
|
146
|
+
// Signature BEFORE semantics — same ordering and same reason as verifyGrant.
|
|
147
|
+
const key = options.keyOf(claims.kid);
|
|
148
|
+
if (!key)
|
|
149
|
+
return { ok: false, reason: `unknown signing key ${claims.kid}` };
|
|
150
|
+
const valid = edVerify(null, Buffer.from(payload, "utf8"), key, Buffer.from(signature, "base64url"));
|
|
151
|
+
if (!valid)
|
|
152
|
+
return { ok: false, reason: "bad signature" };
|
|
153
|
+
if (claims.aud !== options.aud) {
|
|
154
|
+
return { ok: false, reason: `ticket is for "${claims.aud}", not "${options.aud}"` };
|
|
155
|
+
}
|
|
156
|
+
const now = options.now?.() ?? Date.now();
|
|
157
|
+
if (now >= claims.exp)
|
|
158
|
+
return { ok: false, reason: "ticket expired" };
|
|
159
|
+
if (claims.iat > now + 30_000)
|
|
160
|
+
return { ok: false, reason: "ticket issued in the future" };
|
|
161
|
+
return { ok: true, claims };
|
|
162
|
+
}
|
|
163
|
+
// ── Content-census tickets (2026-08-10) ─────────────────────────────────────
|
|
164
|
+
// The third statement auth can make to a consumer, and the only one that ASKS
|
|
165
|
+
// rather than tells: "before I take these accounts' access away, how much of
|
|
166
|
+
// what is in you did they make?"
|
|
167
|
+
//
|
|
168
|
+
// It exists because taking access away and destroying access to data are
|
|
169
|
+
// different acts that look identical on an admin page. Closing ROMs to a
|
|
170
|
+
// household member strands their save states; closing an app whose library is
|
|
171
|
+
// shared strands nothing. Auth cannot tell those apart — it holds no app data
|
|
172
|
+
// by design — so it asks the app, at the moment the owner is deciding, and puts
|
|
173
|
+
// the answer in the confirmation dialog.
|
|
174
|
+
//
|
|
175
|
+
// Same keypair, same single-audience posture, same 60-second life as a
|
|
176
|
+
// revocation, and the same `k` discriminator checked first in every verifier. It
|
|
177
|
+
// is READ-ONLY by construction: a consumer that answers a census changes
|
|
178
|
+
// nothing, so the worst a replayed ticket can do is make the app count rows
|
|
179
|
+
// twice.
|
|
180
|
+
/** How long a census ticket is valid — same posture as a grant. */
|
|
181
|
+
export const CENSUS_TTL_MS = 60 * 1000;
|
|
182
|
+
/** How many accounts one ticket may ask about. The admin dialog asks about the
|
|
183
|
+
* people a single change moves, which is a household; a bound is here so a
|
|
184
|
+
* malformed caller cannot turn one request into a table scan per user. */
|
|
185
|
+
export const CENSUS_MAX_SUBJECTS = 200;
|
|
186
|
+
export function mintCensus(options) {
|
|
187
|
+
const now = options.now?.() ?? Date.now();
|
|
188
|
+
const claims = {
|
|
189
|
+
k: "census",
|
|
190
|
+
aud: options.aud,
|
|
191
|
+
subs: [...options.subs],
|
|
192
|
+
iat: now,
|
|
193
|
+
exp: now + (options.ttlMs ?? CENSUS_TTL_MS),
|
|
194
|
+
nonce: b64url(Buffer.from(crypto.getRandomValues(new Uint8Array(16)))),
|
|
195
|
+
kid: options.kid,
|
|
196
|
+
v: 1,
|
|
197
|
+
};
|
|
198
|
+
const payload = b64url(Buffer.from(JSON.stringify(claims), "utf8"));
|
|
199
|
+
const key = createPrivateKey(options.privateKeyPem);
|
|
200
|
+
const signature = edSign(null, Buffer.from(payload, "utf8"), key);
|
|
201
|
+
return `${payload}.${b64url(signature)}`;
|
|
202
|
+
}
|
|
203
|
+
export function verifyCensus(ticket, options) {
|
|
204
|
+
const parts = ticket.split(".");
|
|
205
|
+
if (parts.length !== 2)
|
|
206
|
+
return { ok: false, reason: "malformed ticket" };
|
|
207
|
+
const [payload, signature] = parts;
|
|
208
|
+
let claims;
|
|
209
|
+
try {
|
|
210
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return { ok: false, reason: "malformed payload" };
|
|
214
|
+
}
|
|
215
|
+
// Kind first, same ordering and same reason as the other two verifiers: a
|
|
216
|
+
// grant presented here must be refused AS a grant, never fall through to a
|
|
217
|
+
// field test that happens to pass.
|
|
218
|
+
if (claims?.k !== "census")
|
|
219
|
+
return { ok: false, reason: "not a census ticket" };
|
|
220
|
+
if (claims.v !== 1)
|
|
221
|
+
return { ok: false, reason: "unsupported ticket version" };
|
|
222
|
+
if (!strField(claims.aud) ||
|
|
223
|
+
!strField(claims.nonce) ||
|
|
224
|
+
!strField(claims.kid) ||
|
|
225
|
+
!Array.isArray(claims.subs) ||
|
|
226
|
+
claims.subs.length === 0 ||
|
|
227
|
+
claims.subs.length > CENSUS_MAX_SUBJECTS ||
|
|
228
|
+
!claims.subs.every((sub) => strField(sub)) ||
|
|
229
|
+
typeof claims.iat !== "number" ||
|
|
230
|
+
typeof claims.exp !== "number") {
|
|
231
|
+
return { ok: false, reason: "malformed claims" };
|
|
232
|
+
}
|
|
233
|
+
// Signature BEFORE semantics — same ordering and same reason as verifyGrant.
|
|
234
|
+
const key = options.keyOf(claims.kid);
|
|
235
|
+
if (!key)
|
|
236
|
+
return { ok: false, reason: `unknown signing key ${claims.kid}` };
|
|
237
|
+
const valid = edVerify(null, Buffer.from(payload, "utf8"), key, Buffer.from(signature, "base64url"));
|
|
238
|
+
if (!valid)
|
|
239
|
+
return { ok: false, reason: "bad signature" };
|
|
240
|
+
if (claims.aud !== options.aud) {
|
|
241
|
+
return { ok: false, reason: `ticket is for "${claims.aud}", not "${options.aud}"` };
|
|
242
|
+
}
|
|
243
|
+
const now = options.now?.() ?? Date.now();
|
|
244
|
+
if (now >= claims.exp)
|
|
245
|
+
return { ok: false, reason: "ticket expired" };
|
|
246
|
+
if (claims.iat > now + 30_000)
|
|
247
|
+
return { ok: false, reason: "ticket issued in the future" };
|
|
248
|
+
return { ok: true, claims };
|
|
249
|
+
}
|
|
250
|
+
// ── Session-list tickets (2026-08-12) ───────────────────────────────────────
|
|
251
|
+
// The fourth statement auth can make to a consumer, and the second that asks
|
|
252
|
+
// rather than tells: "which sessions of this account are alive in you, and what
|
|
253
|
+
// do they look like?"
|
|
254
|
+
//
|
|
255
|
+
// It exists because the fleet could sign somebody out of everything and could
|
|
256
|
+
// not show anybody what "everything" was. A session you did not open is only
|
|
257
|
+
// discoverable by being LISTED, so the list is the security control and the
|
|
258
|
+
// revoke button is what it enables — which is why this ticket is read-only and
|
|
259
|
+
// the ending of a session stays on the revocation ticket above, narrowed by
|
|
260
|
+
// `sid`. One revocation path, one place it can be wrong.
|
|
261
|
+
//
|
|
262
|
+
// Same keypair, same single-audience posture, same 60-second life, same `k`
|
|
263
|
+
// discriminator checked first in every verifier.
|
|
264
|
+
/** How long a session-list ticket is valid — same posture as a grant. */
|
|
265
|
+
export const SESSIONS_TTL_MS = 60 * 1000;
|
|
266
|
+
/**
|
|
267
|
+
* How many sessions one app may report for one account.
|
|
268
|
+
*
|
|
269
|
+
* A person has a handful of devices; a bound is here so a compromised or
|
|
270
|
+
* confused consumer cannot turn one question into an unbounded response auth
|
|
271
|
+
* has to hold in memory and render.
|
|
272
|
+
*/
|
|
273
|
+
export const SESSIONS_MAX_PER_APP = 200;
|
|
274
|
+
export function mintSessionsRequest(options) {
|
|
275
|
+
const now = options.now?.() ?? Date.now();
|
|
276
|
+
const claims = {
|
|
277
|
+
k: "sessions",
|
|
278
|
+
aud: options.aud,
|
|
279
|
+
sub: options.sub,
|
|
280
|
+
iat: now,
|
|
281
|
+
exp: now + (options.ttlMs ?? SESSIONS_TTL_MS),
|
|
282
|
+
nonce: b64url(Buffer.from(crypto.getRandomValues(new Uint8Array(16)))),
|
|
283
|
+
kid: options.kid,
|
|
284
|
+
v: 1,
|
|
285
|
+
};
|
|
286
|
+
const payload = b64url(Buffer.from(JSON.stringify(claims), "utf8"));
|
|
287
|
+
const key = createPrivateKey(options.privateKeyPem);
|
|
288
|
+
const signature = edSign(null, Buffer.from(payload, "utf8"), key);
|
|
289
|
+
return `${payload}.${b64url(signature)}`;
|
|
290
|
+
}
|
|
291
|
+
export function verifySessionsRequest(ticket, options) {
|
|
292
|
+
const parts = ticket.split(".");
|
|
293
|
+
if (parts.length !== 2)
|
|
294
|
+
return { ok: false, reason: "malformed ticket" };
|
|
295
|
+
const [payload, signature] = parts;
|
|
296
|
+
let claims;
|
|
297
|
+
try {
|
|
298
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return { ok: false, reason: "malformed payload" };
|
|
302
|
+
}
|
|
303
|
+
// Kind first, same ordering and same reason as the other three verifiers.
|
|
304
|
+
if (claims?.k !== "sessions")
|
|
305
|
+
return { ok: false, reason: "not a session-list ticket" };
|
|
306
|
+
if (claims.v !== 1)
|
|
307
|
+
return { ok: false, reason: "unsupported ticket version" };
|
|
308
|
+
if (!strField(claims.aud) ||
|
|
309
|
+
!strField(claims.sub) ||
|
|
310
|
+
!strField(claims.nonce) ||
|
|
311
|
+
!strField(claims.kid) ||
|
|
312
|
+
typeof claims.iat !== "number" ||
|
|
313
|
+
typeof claims.exp !== "number") {
|
|
314
|
+
return { ok: false, reason: "malformed claims" };
|
|
315
|
+
}
|
|
316
|
+
// Signature BEFORE semantics — same ordering and same reason as verifyGrant.
|
|
317
|
+
const key = options.keyOf(claims.kid);
|
|
318
|
+
if (!key)
|
|
319
|
+
return { ok: false, reason: `unknown signing key ${claims.kid}` };
|
|
320
|
+
const valid = edVerify(null, Buffer.from(payload, "utf8"), key, Buffer.from(signature, "base64url"));
|
|
321
|
+
if (!valid)
|
|
322
|
+
return { ok: false, reason: "bad signature" };
|
|
323
|
+
if (claims.aud !== options.aud) {
|
|
324
|
+
return { ok: false, reason: `ticket is for "${claims.aud}", not "${options.aud}"` };
|
|
325
|
+
}
|
|
326
|
+
const now = options.now?.() ?? Date.now();
|
|
327
|
+
if (now >= claims.exp)
|
|
328
|
+
return { ok: false, reason: "ticket expired" };
|
|
329
|
+
if (claims.iat > now + 30_000)
|
|
330
|
+
return { ok: false, reason: "ticket issued in the future" };
|
|
331
|
+
return { ok: true, claims };
|
|
332
|
+
}
|
|
333
|
+
const strField = (v) => typeof v === "string" && v.length > 0;
|
|
334
|
+
/** An optional boolean claim: absent is fine, present must be a real boolean.
|
|
335
|
+
* Never coerce — the whole point is that a string cannot pass as `true`. */
|
|
336
|
+
const optionalBool = (v) => v === undefined || typeof v === "boolean";
|
|
337
|
+
export function verifyGrant(grant, options) {
|
|
338
|
+
const parts = grant.split(".");
|
|
339
|
+
if (parts.length !== 2)
|
|
340
|
+
return { ok: false, reason: "malformed grant" };
|
|
341
|
+
const [payload, signature] = parts;
|
|
342
|
+
let claims;
|
|
343
|
+
try {
|
|
344
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return { ok: false, reason: "malformed payload" };
|
|
348
|
+
}
|
|
349
|
+
// Every non-grant statement this key signs carries a `k`; a grant carries
|
|
350
|
+
// none. So the guard is "any kind at all", not a list of the kinds that
|
|
351
|
+
// exist today — a third one (`census`, 2026-08-10) must be refused by the
|
|
352
|
+
// rule that already existed rather than by remembering to extend it here.
|
|
353
|
+
// Refused BY NAME, too, rather than falling through to the field checks and
|
|
354
|
+
// coming back as a vague "malformed claims".
|
|
355
|
+
const kind = claims.k;
|
|
356
|
+
if (kind !== undefined) {
|
|
357
|
+
return {
|
|
358
|
+
ok: false,
|
|
359
|
+
reason: kind === "revoke"
|
|
360
|
+
? "revocation ticket presented as a grant"
|
|
361
|
+
: `${String(kind)} ticket presented as a grant`,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
if (claims?.v !== 1)
|
|
365
|
+
return { ok: false, reason: "unsupported grant version" };
|
|
366
|
+
if (!strField(claims.id) ||
|
|
367
|
+
!strField(claims.email) ||
|
|
368
|
+
typeof claims.name !== "string" ||
|
|
369
|
+
typeof claims.admin !== "boolean" ||
|
|
370
|
+
!strField(claims.aud) ||
|
|
371
|
+
!strField(claims.nonce) ||
|
|
372
|
+
!strField(claims.kid) ||
|
|
373
|
+
typeof claims.iat !== "number" ||
|
|
374
|
+
typeof claims.exp !== "number" ||
|
|
375
|
+
// Optional (deploy skew — see SsoGrantUser), but when PRESENT they must be
|
|
376
|
+
// booleans. A truthy string would otherwise hand somebody the owner's
|
|
377
|
+
// localhost map through a field that was never meant to carry it.
|
|
378
|
+
!optionalBool(claims.owner) ||
|
|
379
|
+
!optionalBool(claims.granted)) {
|
|
380
|
+
return { ok: false, reason: "malformed claims" };
|
|
381
|
+
}
|
|
382
|
+
// Signature BEFORE semantics: an unsigned payload's contents mean nothing,
|
|
383
|
+
// and the checks below must not become an oracle over forged input.
|
|
384
|
+
const key = options.keyOf(claims.kid);
|
|
385
|
+
if (!key)
|
|
386
|
+
return { ok: false, reason: `unknown signing key ${claims.kid}` };
|
|
387
|
+
const valid = edVerify(null, Buffer.from(payload, "utf8"), key, Buffer.from(signature, "base64url"));
|
|
388
|
+
if (!valid)
|
|
389
|
+
return { ok: false, reason: "bad signature" };
|
|
390
|
+
if (claims.aud !== options.aud) {
|
|
391
|
+
return { ok: false, reason: `grant is for "${claims.aud}", not "${options.aud}"` };
|
|
392
|
+
}
|
|
393
|
+
const now = options.now?.() ?? Date.now();
|
|
394
|
+
if (now >= claims.exp)
|
|
395
|
+
return { ok: false, reason: "grant expired" };
|
|
396
|
+
// Clock-skew guard: an iat meaningfully in the future means someone's clock
|
|
397
|
+
// is wrong enough that "expires in 60s" no longer means anything.
|
|
398
|
+
if (claims.iat > now + 30_000)
|
|
399
|
+
return { ok: false, reason: "grant issued in the future" };
|
|
400
|
+
return { ok: true, claims };
|
|
401
|
+
}
|
|
402
|
+
export function createNonceGuard(now = Date.now) {
|
|
403
|
+
const seen = new Map();
|
|
404
|
+
return {
|
|
405
|
+
consume(nonce, expiresAt) {
|
|
406
|
+
const at = now();
|
|
407
|
+
// Sweep on write: the map only grows while grants are being consumed,
|
|
408
|
+
// which is exactly when sweeping is cheap and worthwhile.
|
|
409
|
+
for (const [key, exp] of seen) {
|
|
410
|
+
if (exp <= at)
|
|
411
|
+
seen.delete(key);
|
|
412
|
+
}
|
|
413
|
+
if (seen.has(nonce))
|
|
414
|
+
return false;
|
|
415
|
+
seen.set(nonce, expiresAt);
|
|
416
|
+
return true;
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=sso.js.map
|
package/dist/sso.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sso.js","sourceRoot":"","sources":["../src/sso.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EACN,UAAU,EACV,mBAAmB,EAEnB,gBAAgB,EAChB,eAAe,EACf,IAAI,IAAI,MAAM,EACd,MAAM,IAAI,QAAQ,GAClB,MAAM,aAAa,CAAC;AAErB;;eAEe;AACf,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC;AAgEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,YAAoB,EAAU,EAAE;IACjE,MAAM,GAAG,GAAG,eAA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