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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -0
  3. package/dist/account/AccountMenu.d.ts +153 -0
  4. package/dist/account/AccountMenu.d.ts.map +1 -0
  5. package/dist/account/AccountMenu.js +388 -0
  6. package/dist/account/AccountMenu.js.map +1 -0
  7. package/dist/account/AccountNotice.d.ts +35 -0
  8. package/dist/account/AccountNotice.d.ts.map +1 -0
  9. package/dist/account/AccountNotice.js +133 -0
  10. package/dist/account/AccountNotice.js.map +1 -0
  11. package/dist/account/accountNotice.state.d.ts +20 -0
  12. package/dist/account/accountNotice.state.d.ts.map +1 -0
  13. package/dist/account/accountNotice.state.js +55 -0
  14. package/dist/account/accountNotice.state.js.map +1 -0
  15. package/dist/account/avatar.d.ts +37 -0
  16. package/dist/account/avatar.d.ts.map +1 -0
  17. package/dist/account/avatar.js +47 -0
  18. package/dist/account/avatar.js.map +1 -0
  19. package/dist/accountSlot.client.d.ts +113 -0
  20. package/dist/accountSlot.client.d.ts.map +1 -0
  21. package/dist/accountSlot.client.js +330 -0
  22. package/dist/accountSlot.client.js.map +1 -0
  23. package/dist/accountSlots.d.ts +192 -0
  24. package/dist/accountSlots.d.ts.map +1 -0
  25. package/dist/accountSlots.js +274 -0
  26. package/dist/accountSlots.js.map +1 -0
  27. package/dist/auth.d.ts +167 -0
  28. package/dist/auth.d.ts.map +1 -0
  29. package/dist/auth.js +310 -0
  30. package/dist/auth.js.map +1 -0
  31. package/dist/auth.server.d.ts +35 -0
  32. package/dist/auth.server.d.ts.map +1 -0
  33. package/dist/auth.server.js +67 -0
  34. package/dist/auth.server.js.map +1 -0
  35. package/dist/clientDescription.d.ts +186 -0
  36. package/dist/clientDescription.d.ts.map +1 -0
  37. package/dist/clientDescription.js +278 -0
  38. package/dist/clientDescription.js.map +1 -0
  39. package/dist/constantTime.d.ts +35 -0
  40. package/dist/constantTime.d.ts.map +1 -0
  41. package/dist/constantTime.js +46 -0
  42. package/dist/constantTime.js.map +1 -0
  43. package/dist/contentCensus.d.ts +59 -0
  44. package/dist/contentCensus.d.ts.map +1 -0
  45. package/dist/contentCensus.js +55 -0
  46. package/dist/contentCensus.js.map +1 -0
  47. package/dist/index.d.ts +25 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +24 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/mountGatedApp.d.ts +128 -0
  52. package/dist/mountGatedApp.d.ts.map +1 -0
  53. package/dist/mountGatedApp.js +107 -0
  54. package/dist/mountGatedApp.js.map +1 -0
  55. package/dist/runtimeMode.d.ts +28 -0
  56. package/dist/runtimeMode.d.ts.map +1 -0
  57. package/dist/runtimeMode.js +37 -0
  58. package/dist/runtimeMode.js.map +1 -0
  59. package/dist/secureRequest.d.ts +22 -0
  60. package/dist/secureRequest.d.ts.map +1 -0
  61. package/dist/secureRequest.js +27 -0
  62. package/dist/secureRequest.js.map +1 -0
  63. package/dist/sso.d.ts +373 -0
  64. package/dist/sso.d.ts.map +1 -0
  65. package/dist/sso.js +420 -0
  66. package/dist/sso.js.map +1 -0
  67. package/dist/ssoAutoSignIn.d.ts +272 -0
  68. package/dist/ssoAutoSignIn.d.ts.map +1 -0
  69. package/dist/ssoAutoSignIn.js +431 -0
  70. package/dist/ssoAutoSignIn.js.map +1 -0
  71. package/dist/ssoConsumer.server.d.ts +295 -0
  72. package/dist/ssoConsumer.server.d.ts.map +1 -0
  73. package/dist/ssoConsumer.server.js +972 -0
  74. package/dist/ssoConsumer.server.js.map +1 -0
  75. package/dist/stageIdentity.d.ts +72 -0
  76. package/dist/stageIdentity.d.ts.map +1 -0
  77. package/dist/stageIdentity.js +74 -0
  78. package/dist/stageIdentity.js.map +1 -0
  79. package/dist/ui/popover.d.ts +190 -0
  80. package/dist/ui/popover.d.ts.map +1 -0
  81. package/dist/ui/popover.js +351 -0
  82. package/dist/ui/popover.js.map +1 -0
  83. package/dist/userSessions.d.ts +205 -0
  84. package/dist/userSessions.d.ts.map +1 -0
  85. package/dist/userSessions.js +419 -0
  86. package/dist/userSessions.js.map +1 -0
  87. package/package.json +115 -0
  88. package/src/account/AccountMenu.tsx +729 -0
  89. package/src/account/AccountNotice.tsx +223 -0
  90. package/src/account/accountNotice.state.ts +66 -0
  91. package/src/account/avatar.ts +50 -0
  92. package/src/accountSlot.client.ts +362 -0
  93. package/src/accountSlots.ts +305 -0
  94. package/src/auth.server.ts +89 -0
  95. package/src/auth.ts +515 -0
  96. package/src/clientDescription.ts +366 -0
  97. package/src/constantTime.ts +45 -0
  98. package/src/contentCensus.ts +106 -0
  99. package/src/index.ts +58 -0
  100. package/src/mountGatedApp.ts +240 -0
  101. package/src/runtimeMode.ts +37 -0
  102. package/src/secureRequest.ts +25 -0
  103. package/src/sso.ts +767 -0
  104. package/src/ssoAutoSignIn.ts +544 -0
  105. package/src/ssoConsumer.server.ts +1260 -0
  106. package/src/stageIdentity.ts +76 -0
  107. package/src/ui/popover.ts +390 -0
  108. package/src/userSessions.ts +678 -0
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Multi-user sessions: an HMAC-signed cookie carrying a random id, resolved to
3
+ * a user through a server-side row.
4
+ *
5
+ * ── Why a session TABLE, when the kit's owner-auth deliberately has none ────
6
+ * `cursedauth`'s `secureRequest` serves apps with exactly ONE principal, so its
7
+ * cookie only has to prove "the owner signed in" and a table would be surface
8
+ * without purpose. Here the cookie must answer "WHICH user", and admin actions
9
+ * must end sessions the server never got handed back (delete a user, issue a
10
+ * temp password, change a password on every other device). A row per session
11
+ * answers all of that with one primitive: login inserts, lookup joins, admin
12
+ * deletes. The revocation-store/valid-from machinery owner-auth grew for the
13
+ * same needs would have to be duplicated per-user here — the table IS the
14
+ * simpler design at N > 1.
15
+ *
16
+ * The cookie value is `<expiry>.<id>.<sig>` — same shape, same constant-time
17
+ * verification, same TLS-aware attributes as owner-auth; the signature keeps
18
+ * every request from being a blind db probe, and the row keeps the cookie
19
+ * revocable. Sessions live in their OWN sqlite file (`sessions.sqlite`), not in
20
+ * the app db — the split roms made, and for the same reason: a credential
21
+ * surface should not share a Database handle with app data.
22
+ *
23
+ * Extracted from `apps/hobbies` (2026-07-28; that app retired 2026-08-25) when `apps/auth` became the second
24
+ * app to need it — cookie NAME is the only thing an app says for itself,
25
+ * because sibling subdomains sharing one cookie name invites the belief that a
26
+ * session in one means something in another (the repo's standing rule).
27
+ *
28
+ * ── Sessions are LISTABLE and individually revocable (2026-08-12) ───────────
29
+ * A row per session was always what made "sign everybody out" possible. What it
30
+ * could not do was answer "signed in WHERE, from what, since when" — the row
31
+ * held an id, a user and an expiry and nothing a person could recognise. ca's
32
+ * admin console had that page; this fleet did not, and it is a security control
33
+ * rather than a convenience: the only way to notice a session you did not open
34
+ * is to be shown the list.
35
+ *
36
+ * So every row now carries a device, an address, a creation time and a
37
+ * last-seen time, every satellite gets it from this one store with no per-app
38
+ * wiring, and `apps/auth` collects them across the fleet over the same signed
39
+ * channel the revocation cascade uses.
40
+ *
41
+ * 🔴 **The row id never leaves this module.** It is the secret half of the
42
+ * cookie (`<expiry>.<id>.<sig>`), and while a signature is still required to
43
+ * use one, a list API that printed session ids would be publishing a credential
44
+ * component to a screen, a log and a JSON body between two apps. What leaves is
45
+ * a HANDLE — `sha256(id)`, truncated — which is stable, comparable, useless
46
+ * without the id, and needs no column of its own (so no migration, and no
47
+ * second thing that can disagree with the first).
48
+ *
49
+ * ── Several accounts at once, in one browser (2026-08-12) ───────────────────
50
+ * The table never needed changing for this: a row per session already allowed
51
+ * one person to be signed in from five places, and nothing in it says "one per
52
+ * browser". The single-account limit lived entirely in the COOKIE — one name,
53
+ * one value, one session reachable per origin.
54
+ *
55
+ * So the cookie became N cookies, one per SLOT (`accountSlots.ts` holds the
56
+ * vocabulary and the reasoning), and every method that used to mean "the
57
+ * session" now means "the session in the slot this request named". Slot 0 is
58
+ * the bare cookie name and the default for every caller that says nothing, so
59
+ * this is additive in the strictest sense — no migration, no expired sessions,
60
+ * and an app that never opens a second account is byte-identical to before.
61
+ *
62
+ * 🔴 The slot is chosen by the REQUEST and is attacker-writable. It selects
63
+ * among this browser's own cookies and can never conjure one: an empty slot
64
+ * resolves to null and the request is anonymous. Never treat a slot number as
65
+ * identity — resolve it here, every time.
66
+ */
67
+ import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
68
+ import { mkdirSync } from "node:fs";
69
+ import path from "node:path";
70
+ import { Database } from "bun:sqlite";
71
+ import { ACCOUNT_SLOT_HEADER, ACCOUNT_USER_HEADER, MAX_ACCOUNT_SLOTS, normalizeSlot, slotCookieName, slotFromUrl, } from "./accountSlots";
72
+ import { clientAddressOf, clientFactsOf, clientUserAgentOf, describePlace, } from "./clientDescription";
73
+ import { isSecureRequest } from "./secureRequest";
74
+ /**
75
+ * How stale `last_seen_at` may get before a request writes it.
76
+ *
77
+ * `userIdOf` runs on EVERY request, and a write per request is a write per
78
+ * image, poll and asset probe on a database that exists to hold credentials.
79
+ * A minute of resolution is far finer than the question this answers ("is that
80
+ * session still being used, or is it a laptop I left at the office?"), and it
81
+ * turns a per-request write into roughly one per minute per active session.
82
+ */
83
+ const TOUCH_THROTTLE_MS = 60_000;
84
+ /**
85
+ * The public name of a session: one-way, so it can be printed and posted
86
+ * without ever being usable as the id it came from.
87
+ *
88
+ * Derived rather than stored, so a deployment that predates the session list
89
+ * gets correct handles for the sessions it is already holding — a migration
90
+ * could not have backfilled them (sqlite has no sha256), and rows without one
91
+ * would have been sessions the owner could see and not revoke.
92
+ */
93
+ const handleOf = (id) => createHash("sha256").update(id).digest("hex").slice(0, 24);
94
+ function constantTimeEqual(a, b) {
95
+ const ab = Buffer.from(a, "utf8");
96
+ const bb = Buffer.from(b, "utf8");
97
+ const len = Math.max(ab.length, bb.length);
98
+ const pa = Buffer.alloc(len);
99
+ const pb = Buffer.alloc(len);
100
+ ab.copy(pa);
101
+ bb.copy(pb);
102
+ return timingSafeEqual(pa, pb) && ab.length === bb.length;
103
+ }
104
+ export function createUserSessionStore(options) {
105
+ // Resolved once per store rather than per sign-in. `null` and unset are the
106
+ // same thing — see `placeLookup` on the options for why there is no default.
107
+ const placeLookup = options.placeLookup ?? undefined;
108
+ const now = options.now ?? Date.now;
109
+ if (options.dbPath !== ":memory:")
110
+ mkdirSync(path.dirname(options.dbPath), { recursive: true });
111
+ const db = new Database(options.dbPath, { create: true });
112
+ // busy_timeout FIRST — journal_mode takes a lock. scripts/sqliteBusyTimeout.test.ts
113
+ db.exec("PRAGMA busy_timeout = 5000;");
114
+ db.exec("PRAGMA journal_mode = WAL;");
115
+ db.exec(`CREATE TABLE IF NOT EXISTS sessions (
116
+ id TEXT PRIMARY KEY,
117
+ user_id TEXT NOT NULL,
118
+ expires_at INTEGER NOT NULL
119
+ );
120
+ CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);`);
121
+ // The session-list columns (2026-08-12), added by ALTER because every
122
+ // satellite already has this table with live sessions in it. All four default
123
+ // to a value that reads as "we do not know", never as a fabricated one: a
124
+ // session minted before the upgrade shows an unknown device and an unknown
125
+ // address, which is honest, where a zero timestamp would render as 1970 and a
126
+ // blank device would read as "no device" rather than "not recorded".
127
+ //
128
+ // `created_at`/`last_seen_at` default to 0 in SQL and are read through
129
+ // `orZero` below, which falls back to the expiry-derived start rather than to
130
+ // the epoch — the column cannot express "unknown" and the reader can.
131
+ for (const column of [
132
+ "user_agent TEXT NOT NULL DEFAULT ''",
133
+ "ip TEXT NOT NULL DEFAULT ''",
134
+ "created_at INTEGER NOT NULL DEFAULT 0",
135
+ "last_seen_at INTEGER NOT NULL DEFAULT 0",
136
+ // 2026-08-25, same ALTER-because-it-is-live reasoning as the four above.
137
+ "place TEXT NOT NULL DEFAULT ''",
138
+ ]) {
139
+ try {
140
+ db.exec(`ALTER TABLE sessions ADD COLUMN ${column}`);
141
+ }
142
+ catch {
143
+ // Already there. sqlite has no ADD COLUMN IF NOT EXISTS, and reading
144
+ // pragma table_info to decide costs more than catching the one error
145
+ // this can throw — the same shape `sso_users` uses.
146
+ }
147
+ }
148
+ const sign = (payload) => createHmac("sha256", options.sessionSecret).update(payload).digest("base64url");
149
+ const cookieAttributes = (req, maxAge) => [
150
+ "Path=/",
151
+ "HttpOnly",
152
+ // Lax, not Strict: the SSO callback ARRIVES as a cross-site top-level
153
+ // navigation (auth redirects the browser back with the grant), and the
154
+ // very next request must already carry the fresh cookie. Lax sends it on
155
+ // top-level GETs while still refusing cross-site POSTs and subresources,
156
+ // which is the CSRF posture the state-changing routes rely on (all are
157
+ // POST/PATCH/DELETE).
158
+ "SameSite=Lax",
159
+ ...(isSecureRequest(req) ? ["Secure"] : []),
160
+ `Max-Age=${maxAge}`,
161
+ ].join("; ");
162
+ /**
163
+ * Which account this request is acting as — see `accountSlots.ts`.
164
+ *
165
+ * URL first, header second. The URL is the one a full page load, a bookmark
166
+ * and an `<img src>` can carry, so it has to be authoritative; the header is
167
+ * how an SPA's `fetch` calls say the same thing without every route constant
168
+ * in the app growing a query param.
169
+ */
170
+ const slotOf = (req) => {
171
+ const fromUrl = slotFromUrl(req.url);
172
+ if (fromUrl !== null)
173
+ return fromUrl;
174
+ const header = req.headers.get(ACCOUNT_SLOT_HEADER);
175
+ return header === null ? 0 : normalizeSlot(header);
176
+ };
177
+ /**
178
+ * Who the CLIENT said it was rendering for, or null if it did not say.
179
+ *
180
+ * 🔴 This is never identity and can never be read as any. It exists so a
181
+ * guard can notice that the account behind this browser's slot has been
182
+ * replaced since the page was drawn — see `accountSlots.ts` for the failure
183
+ * and `isAccountDrift` for the one rule that decides it. Bounded, because it
184
+ * is attacker-supplied and only ever compared to a string we already hold.
185
+ */
186
+ const expectedUserOf = (req) => {
187
+ const raw = req.headers.get(ACCOUNT_USER_HEADER);
188
+ if (raw === null)
189
+ return null;
190
+ const value = raw.trim();
191
+ return value.length > 0 && value.length <= 200 ? value : null;
192
+ };
193
+ /**
194
+ * Signature first, expiry second — an unsigned value proves nothing.
195
+ *
196
+ * `slot` names WHICH cookie to read. It defaults to the one the request
197
+ * asked for, so every existing caller keeps reading the bare cookie name.
198
+ */
199
+ const parse = (req, slot) => {
200
+ const cookie = req.headers.get("cookie");
201
+ if (!cookie)
202
+ return null;
203
+ const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
204
+ const match = new RegExp(`(?:^|;\\s*)${name}=([^;]+)`).exec(cookie);
205
+ const value = match?.[1];
206
+ if (!value)
207
+ return null;
208
+ const parts = value.split(".");
209
+ if (parts.length !== 3)
210
+ return null;
211
+ const [expiry, id, signature] = parts;
212
+ if (!expiry || !id || !signature)
213
+ return null;
214
+ if (!constantTimeEqual(signature, sign(`${expiry}.${id}`)))
215
+ return null;
216
+ const expiresAt = Number(expiry);
217
+ if (!Number.isFinite(expiresAt) || expiresAt <= now())
218
+ return null;
219
+ return { id };
220
+ };
221
+ /** The live user at one slot, or null. One query, used by three methods. */
222
+ const userAt = (req, slot) => {
223
+ const session = parse(req, slot);
224
+ if (!session)
225
+ return null;
226
+ const row = db
227
+ .query("SELECT user_id, expires_at FROM sessions WHERE id = ?")
228
+ .get(session.id);
229
+ return row && row.expires_at > now() ? row.user_id : null;
230
+ };
231
+ /**
232
+ * The seconds a cookie for `value` should live, from the value's own expiry.
233
+ *
234
+ * Deriving it rather than passing it is what keeps a remember-me cookie and
235
+ * its row in agreement — there is one number and both read it. A value this
236
+ * cannot read falls back to the store default, deliberately erring SHORT:
237
+ * too short costs a sign-in, too long leaves a dead cookie riding every
238
+ * request until the browser gives up on it.
239
+ */
240
+ const cookieLifetimeOf = (value) => {
241
+ const expiresAt = Number(value.split(".")[0]);
242
+ if (!Number.isFinite(expiresAt))
243
+ return options.sessionTtlSeconds;
244
+ const seconds = Math.ceil((expiresAt - now()) / 1000);
245
+ return seconds > 0 ? seconds : options.sessionTtlSeconds;
246
+ };
247
+ /** Opportunistic, on writes: rare, cheap, and exactly when the table grew. */
248
+ const sweep = () => {
249
+ db.query("DELETE FROM sessions WHERE expires_at <= ?").run(now());
250
+ };
251
+ /** A session minted before `created_at` existed still has a real start: its
252
+ * expiry minus the TTL. Better than 0, which renders as 1970. */
253
+ const startOf = (row) => row.created_at && row.created_at > 0
254
+ ? row.created_at
255
+ : row.expires_at - options.sessionTtlSeconds * 1000;
256
+ // 🔴 These three are plain closures rather than methods called through
257
+ // `this` on the returned object, because call sites in this repo destructure
258
+ // stores (`const { userIdOf } = sessions`) and a `this`-dependent method
259
+ // would throw the moment one of them did.
260
+ const create = (userId, req, signInOptions) => {
261
+ const at = now();
262
+ const ttl = signInOptions?.ttlSeconds ?? options.sessionTtlSeconds;
263
+ const expiresAt = at + ttl * 1000;
264
+ const id = randomBytes(16).toString("base64url");
265
+ db.query(`INSERT INTO sessions (id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place)
266
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(id, userId, expiresAt, req ? clientUserAgentOf(req) : "", req ? clientAddressOf(req) : "", at, at,
267
+ // The place is resolved HERE, not read back later: `describePlace` of
268
+ // the edge headers merged with this machine's snapshot is a fact about
269
+ // the moment of sign-in, and the snapshot is refreshed monthly.
270
+ req ? describePlace(clientFactsOf(req, { lookup: placeLookup })) : "");
271
+ sweep();
272
+ const payload = `${expiresAt}.${id}`;
273
+ return `${payload}.${sign(payload)}`;
274
+ };
275
+ const sessionCookie = (value, req, slot) => {
276
+ const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
277
+ return `${name}=${value}; ${cookieAttributes(req, cookieLifetimeOf(value))}`;
278
+ };
279
+ const revokeAt = (req, slot) => {
280
+ const session = parse(req, slot);
281
+ if (!session)
282
+ return false;
283
+ db.query("DELETE FROM sessions WHERE id = ?").run(session.id);
284
+ return true;
285
+ };
286
+ const signedInSlots = (req) => {
287
+ const occupants = [];
288
+ for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
289
+ const userId = userAt(req, slot);
290
+ if (userId)
291
+ occupants.push({ slot, userId });
292
+ }
293
+ return occupants;
294
+ };
295
+ return {
296
+ cookieName: options.cookieName,
297
+ slotOf,
298
+ expectedUserOf,
299
+ create,
300
+ signedInSlots,
301
+ signIn(userId, req, signInOptions) {
302
+ const slot = normalizeSlot(signInOptions?.slot ?? slotOf(req));
303
+ const value = create(userId, req, signInOptions);
304
+ return {
305
+ cookie: sessionCookie(value, req, slot),
306
+ slot,
307
+ expiresAt: Number(value.split(".")[0]),
308
+ };
309
+ },
310
+ slotForUser(req, userId) {
311
+ return signedInSlots(req).find((entry) => entry.userId === userId)?.slot ?? null;
312
+ },
313
+ slotToAdd(req, userId) {
314
+ const occupied = signedInSlots(req);
315
+ // Already here → their slot. Signing in twice must never take a second
316
+ // one; see the interface for why that exhausts the switcher.
317
+ const mine = occupied.find((entry) => entry.userId === userId);
318
+ if (mine)
319
+ return mine.slot;
320
+ const taken = new Set(occupied.map((entry) => entry.slot));
321
+ for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
322
+ if (!taken.has(slot))
323
+ return slot;
324
+ }
325
+ // Full. The caller says so; nothing is evicted to make room.
326
+ return null;
327
+ },
328
+ userIdOf(req) {
329
+ const session = parse(req);
330
+ if (!session)
331
+ return null;
332
+ const row = db
333
+ .query("SELECT user_id, expires_at, last_seen_at FROM sessions WHERE id = ?")
334
+ .get(session.id);
335
+ if (!row || row.expires_at <= now())
336
+ return null;
337
+ // "Last seen" is maintained HERE because this is the one call every
338
+ // satellite makes on every authenticated request — the alternative is a
339
+ // per-app middleware that eighteen apps have to remember, which is the
340
+ // same as not having it. Throttled; see TOUCH_THROTTLE_MS.
341
+ const at = now();
342
+ if (at - (row.last_seen_at ?? 0) >= TOUCH_THROTTLE_MS) {
343
+ db.query("UPDATE sessions SET last_seen_at = ? WHERE id = ?").run(at, session.id);
344
+ }
345
+ return row.user_id;
346
+ },
347
+ listForUser(userId, req) {
348
+ const currentId = req ? (parse(req)?.id ?? null) : null;
349
+ const rows = db
350
+ .query(`SELECT id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place
351
+ FROM sessions WHERE user_id = ? AND expires_at > ?
352
+ ORDER BY last_seen_at DESC, expires_at DESC`)
353
+ .all(userId, now());
354
+ return rows.map((row) => ({
355
+ handle: handleOf(row.id),
356
+ userId: row.user_id,
357
+ createdAt: startOf(row),
358
+ lastSeenAt: row.last_seen_at && row.last_seen_at > 0 ? row.last_seen_at : startOf(row),
359
+ expiresAt: row.expires_at,
360
+ userAgent: row.user_agent ?? "",
361
+ ip: row.ip ?? "",
362
+ place: row.place ?? "",
363
+ current: currentId !== null && row.id === currentId,
364
+ }));
365
+ },
366
+ revokeByHandle(userId, handle) {
367
+ if (!handle)
368
+ return false;
369
+ // Matched in JS against this user's own rows rather than in SQL,
370
+ // because the handle is a hash and sqlite cannot compute one. The scan
371
+ // is over one account's live sessions — single digits — and it is the
372
+ // same bound the list above already pays.
373
+ const rows = db
374
+ .query("SELECT id FROM sessions WHERE user_id = ? AND expires_at > ?")
375
+ .all(userId, now());
376
+ const match = rows.find((row) => handleOf(row.id) === handle);
377
+ if (!match)
378
+ return false;
379
+ db.query("DELETE FROM sessions WHERE id = ? AND user_id = ?").run(match.id, userId);
380
+ return true;
381
+ },
382
+ revoke(req) {
383
+ const session = parse(req);
384
+ if (!session)
385
+ return;
386
+ db.query("DELETE FROM sessions WHERE id = ?").run(session.id);
387
+ sweep();
388
+ },
389
+ revokeAt,
390
+ revokeEverySlot(req) {
391
+ const cleared = [];
392
+ for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
393
+ if (revokeAt(req, slot))
394
+ cleared.push(slot);
395
+ }
396
+ if (cleared.length > 0)
397
+ sweep();
398
+ return cleared;
399
+ },
400
+ revokeAllForUser(userId) {
401
+ db.query("DELETE FROM sessions WHERE user_id = ?").run(userId);
402
+ },
403
+ revokeOthersForUser(userId, req) {
404
+ const session = parse(req);
405
+ if (session) {
406
+ db.query("DELETE FROM sessions WHERE user_id = ? AND id != ?").run(userId, session.id);
407
+ }
408
+ else {
409
+ db.query("DELETE FROM sessions WHERE user_id = ?").run(userId);
410
+ }
411
+ },
412
+ sessionCookie,
413
+ clearedCookie(req, slot) {
414
+ const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
415
+ return `${name}=; ${cookieAttributes(req, 0)}`;
416
+ },
417
+ };
418
+ }
419
+ //# sourceMappingURL=userSessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userSessions.js","sourceRoot":"","sources":["../src/userSessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,WAAW,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,GAEb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAkNlD;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAEpG,SAAS,iBAAiB,CAAC,CAAS,EAAE,CAAS;IAC9C,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MA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AAU,EAAE,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACrE,OAAO,GAAG,IAAI,MAAM,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;QAChD,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,115 @@
1
+ {
2
+ "name": "cursedauth",
3
+ "version": "0.1.0",
4
+ "description": "The app side of fleet SSO \u2014 sign in through the accounts service, keep a local snapshot of who signed in, and gate the app on it. Bun + Hono + React, one SQLite file per app.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "bun": "./src/index.ts",
11
+ "source": "./src/index.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./sso-consumer": {
15
+ "types": "./dist/ssoConsumer.server.d.ts",
16
+ "bun": "./src/ssoConsumer.server.ts",
17
+ "source": "./src/ssoConsumer.server.ts",
18
+ "import": "./dist/ssoConsumer.server.js"
19
+ },
20
+ "./user-sessions": {
21
+ "types": "./dist/userSessions.d.ts",
22
+ "bun": "./src/userSessions.ts",
23
+ "source": "./src/userSessions.ts",
24
+ "import": "./dist/userSessions.js"
25
+ },
26
+ "./mount-gated": {
27
+ "types": "./dist/mountGatedApp.d.ts",
28
+ "bun": "./src/mountGatedApp.ts",
29
+ "source": "./src/mountGatedApp.ts",
30
+ "import": "./dist/mountGatedApp.js"
31
+ },
32
+ "./content-census": {
33
+ "types": "./dist/contentCensus.d.ts",
34
+ "bun": "./src/contentCensus.ts",
35
+ "source": "./src/contentCensus.ts",
36
+ "import": "./dist/contentCensus.js"
37
+ },
38
+ "./account-slots": {
39
+ "types": "./dist/accountSlots.d.ts",
40
+ "bun": "./src/accountSlots.ts",
41
+ "source": "./src/accountSlots.ts",
42
+ "import": "./dist/accountSlots.js"
43
+ },
44
+ "./auth": {
45
+ "types": "./dist/auth.d.ts",
46
+ "bun": "./src/auth.ts",
47
+ "source": "./src/auth.ts",
48
+ "import": "./dist/auth.js"
49
+ },
50
+ "./account-ui": {
51
+ "types": "./dist/account/AccountMenu.d.ts",
52
+ "bun": "./src/account/AccountMenu.tsx",
53
+ "source": "./src/account/AccountMenu.tsx",
54
+ "import": "./dist/account/AccountMenu.js"
55
+ },
56
+ "./account-slot-client": {
57
+ "types": "./dist/accountSlot.client.d.ts",
58
+ "bun": "./src/accountSlot.client.ts",
59
+ "source": "./src/accountSlot.client.ts",
60
+ "import": "./dist/accountSlot.client.js"
61
+ },
62
+ "./package.json": "./package.json"
63
+ },
64
+ "files": [
65
+ "dist",
66
+ "src",
67
+ "!src/**/*.test.ts",
68
+ "!src/**/*.test.tsx",
69
+ "README.md",
70
+ "LICENSE"
71
+ ],
72
+ "scripts": {
73
+ "paths": "bun ../../tools/check-paths.ts .",
74
+ "typecheck": "tsc -p tsconfig.json --noEmit",
75
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
76
+ "test": "bun test src",
77
+ "verify": "bun run paths && bun run typecheck && bun run build && bun run test",
78
+ "prepublishOnly": "bun run verify"
79
+ },
80
+ "keywords": [
81
+ "sso",
82
+ "auth",
83
+ "sessions",
84
+ "hono",
85
+ "bun",
86
+ "react",
87
+ "sqlite"
88
+ ],
89
+ "peerDependencies": {
90
+ "hono": ">=4",
91
+ "react": "^19",
92
+ "react-dom": "^19"
93
+ },
94
+ "peerDependenciesMeta": {
95
+ "react": {
96
+ "optional": true
97
+ },
98
+ "react-dom": {
99
+ "optional": true
100
+ }
101
+ },
102
+ "devDependencies": {
103
+ "@happy-dom/global-registrator": "^20.0.0",
104
+ "@types/bun": "latest",
105
+ "@types/react": "^19.2.18",
106
+ "@types/react-dom": "^19.2.5",
107
+ "hono": "^4.13.5",
108
+ "react": "^19.2.8",
109
+ "react-dom": "^19.2.8",
110
+ "typescript": "^5.7.2"
111
+ },
112
+ "publishConfig": {
113
+ "access": "public"
114
+ }
115
+ }