cursedauth 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/d1Stores.d.ts +172 -0
- package/dist/d1Stores.d.ts.map +1 -0
- package/dist/d1Stores.js +306 -0
- package/dist/d1Stores.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/ssoConsumer.server.d.ts +40 -4
- package/dist/ssoConsumer.server.d.ts.map +1 -1
- package/dist/ssoConsumer.server.js +107 -70
- package/dist/ssoConsumer.server.js.map +1 -1
- package/dist/ssoUsers.d.ts +122 -0
- package/dist/ssoUsers.d.ts.map +1 -0
- package/dist/ssoUsers.js +119 -0
- package/dist/ssoUsers.js.map +1 -0
- package/dist/userSessions.core.d.ts +284 -0
- package/dist/userSessions.core.d.ts.map +1 -0
- package/dist/userSessions.core.js +389 -0
- package/dist/userSessions.core.js.map +1 -0
- package/dist/userSessions.d.ts +16 -198
- package/dist/userSessions.d.ts.map +1 -1
- package/dist/userSessions.js +77 -355
- package/dist/userSessions.js.map +1 -1
- package/package.json +20 -1
- package/src/d1Stores.ts +455 -0
- package/src/index.ts +20 -0
- package/src/ssoConsumer.server.ts +128 -101
- package/src/ssoUsers.ts +243 -0
- package/src/userSessions.core.ts +685 -0
- package/src/userSessions.ts +122 -601
package/dist/userSessions.js
CHANGED
|
@@ -1,115 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* a user through a server-side row.
|
|
2
|
+
* The session store on `bun:sqlite` — its own file, opened from a path.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
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.
|
|
4
|
+
* ## 🔴 This file is now the ADAPTER, and `userSessions.core.ts` is the store
|
|
15
5
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
6
|
+
* Everything this module used to do it still does, from the same entry point, with the
|
|
7
|
+
* same options and against the same `sessions.sqlite` file: {@link createUserSessionStore}
|
|
8
|
+
* opens the database, builds the {@link SessionRows} implementation below, and hands it to
|
|
9
|
+
* {@link createUserSessionStoreOver}. **Six apps import this and none of them changes.**
|
|
22
10
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
11
|
+
* The split exists because `workerd` has no `bun:sqlite` and the store's nineteen members
|
|
12
|
+
* are synchronous by publication, so neither "make it async" nor "run it as it is" was
|
|
13
|
+
* available. The seam is at the ROWS — `userSessions.core.ts`'s header carries the whole
|
|
14
|
+
* argument, and `cursedauth/d1-stores` is the other implementation.
|
|
27
15
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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.
|
|
16
|
+
* 🔴 This module is the ONLY leaf in the package that constructs a `Database`, which is
|
|
17
|
+
* what `subpathsReachNoBunBuiltin.test.ts`'s `MAY_NEED_BUN` allowlist records. Keep it
|
|
18
|
+
* that way: anything that belongs to the STORE rather than to the FILE goes in the core.
|
|
35
19
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* channel the revocation cascade uses.
|
|
20
|
+
* Sessions live in their OWN sqlite file (`sessions.sqlite`), not in the app db — the
|
|
21
|
+
* split roms made, and for the same reason: a credential surface should not share a
|
|
22
|
+
* `Database` handle with app data.
|
|
40
23
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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.
|
|
24
|
+
* Extracted from `apps/hobbies` (2026-07-28; that app retired 2026-08-25) when `apps/auth`
|
|
25
|
+
* became the second app to need it — cookie NAME is the only thing an app says for itself,
|
|
26
|
+
* because sibling subdomains sharing one cookie name invites the belief that a session in
|
|
27
|
+
* one means something in another (the repo's standing rule).
|
|
66
28
|
*/
|
|
67
|
-
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
68
29
|
import { mkdirSync } from "node:fs";
|
|
69
30
|
import path from "node:path";
|
|
70
31
|
import { Database } from "bun:sqlite";
|
|
71
|
-
import {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
32
|
+
import { createUserSessionStoreOver, } from "./userSessions.core";
|
|
33
|
+
export { createUserSessionStoreOver, SESSIONS_DDL, } from "./userSessions.core";
|
|
34
|
+
const normalize = (row) => ({
|
|
35
|
+
id: row.id,
|
|
36
|
+
user_id: row.user_id,
|
|
37
|
+
expires_at: row.expires_at,
|
|
38
|
+
user_agent: row.user_agent ?? "",
|
|
39
|
+
ip: row.ip ?? "",
|
|
40
|
+
created_at: row.created_at ?? 0,
|
|
41
|
+
last_seen_at: row.last_seen_at ?? 0,
|
|
42
|
+
place: row.place ?? "",
|
|
43
|
+
});
|
|
44
|
+
const COLUMNS = "id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place";
|
|
82
45
|
/**
|
|
83
|
-
*
|
|
46
|
+
* The `sessions` table on `bun:sqlite`, in the shape the store reads it.
|
|
84
47
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* session still being used, or is it a laptop I left at the office?"), and it
|
|
89
|
-
* turns a per-request write into roughly one per minute per active session.
|
|
90
|
-
*/
|
|
91
|
-
const TOUCH_THROTTLE_MS = 60_000;
|
|
92
|
-
/**
|
|
93
|
-
* The public name of a session: one-way, so it can be printed and posted
|
|
94
|
-
* without ever being usable as the id it came from.
|
|
48
|
+
* Exported so a Bun-hosted app that already owns a `Database` can build the store over it
|
|
49
|
+
* — and so `sessionRows.sameShape.test.ts` can drive this implementation and the D1 one
|
|
50
|
+
* through exactly the same scenarios.
|
|
95
51
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
52
|
+
* 🔴 The schema is still built as a three-column `CREATE` plus five `ALTER`s rather than
|
|
53
|
+
* from `SESSIONS_DDL`, deliberately. Every deployed satellite already has this table with
|
|
54
|
+
* live sessions in it, and a one-statement `CREATE TABLE IF NOT EXISTS` would silently do
|
|
55
|
+
* nothing to those files — leaving the store reading five columns that are not there. The
|
|
56
|
+
* `ALTER` sequence is the migration; `SESSIONS_DDL` is the same schema stated for a host
|
|
57
|
+
* that starts empty, and the sameShape spec is what proves the two agree.
|
|
100
58
|
*/
|
|
101
|
-
|
|
102
|
-
export function createUserSessionStore(options) {
|
|
103
|
-
// Resolved once per store rather than per sign-in. `null` and unset are the
|
|
104
|
-
// same thing — see `placeLookup` on the options for why there is no default.
|
|
105
|
-
const placeLookup = options.placeLookup ?? undefined;
|
|
106
|
-
const now = options.now ?? Date.now;
|
|
107
|
-
if (options.dbPath !== ":memory:")
|
|
108
|
-
mkdirSync(path.dirname(options.dbPath), { recursive: true });
|
|
109
|
-
const db = new Database(options.dbPath, { create: true });
|
|
110
|
-
// busy_timeout FIRST — journal_mode takes a lock. scripts/sqliteBusyTimeout.test.ts
|
|
111
|
-
db.exec("PRAGMA busy_timeout = 5000;");
|
|
112
|
-
db.exec("PRAGMA journal_mode = WAL;");
|
|
59
|
+
export function createSqliteSessionRows(db) {
|
|
113
60
|
db.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
114
61
|
id TEXT PRIMARY KEY,
|
|
115
62
|
user_id TEXT NOT NULL,
|
|
@@ -124,8 +71,8 @@ export function createUserSessionStore(options) {
|
|
|
124
71
|
// blank device would read as "no device" rather than "not recorded".
|
|
125
72
|
//
|
|
126
73
|
// `created_at`/`last_seen_at` default to 0 in SQL and are read through
|
|
127
|
-
// `
|
|
128
|
-
// the epoch — the column cannot express "unknown" and the reader can.
|
|
74
|
+
// `startOf` in the core, which falls back to the expiry-derived start rather
|
|
75
|
+
// than to the epoch — the column cannot express "unknown" and the reader can.
|
|
129
76
|
for (const column of [
|
|
130
77
|
"user_agent TEXT NOT NULL DEFAULT ''",
|
|
131
78
|
"ip TEXT NOT NULL DEFAULT ''",
|
|
@@ -143,275 +90,50 @@ export function createUserSessionStore(options) {
|
|
|
143
90
|
// this can throw — the same shape `sso_users` uses.
|
|
144
91
|
}
|
|
145
92
|
}
|
|
146
|
-
const sign = (payload) => createHmac("sha256", options.sessionSecret).update(payload).digest("base64url");
|
|
147
|
-
const cookieAttributes = (req, maxAge) => [
|
|
148
|
-
"Path=/",
|
|
149
|
-
"HttpOnly",
|
|
150
|
-
// Lax, not Strict: the SSO callback ARRIVES as a cross-site top-level
|
|
151
|
-
// navigation (auth redirects the browser back with the grant), and the
|
|
152
|
-
// very next request must already carry the fresh cookie. Lax sends it on
|
|
153
|
-
// top-level GETs while still refusing cross-site POSTs and subresources,
|
|
154
|
-
// which is the CSRF posture the state-changing routes rely on (all are
|
|
155
|
-
// POST/PATCH/DELETE).
|
|
156
|
-
"SameSite=Lax",
|
|
157
|
-
...(isSecureRequest(req) ? ["Secure"] : []),
|
|
158
|
-
`Max-Age=${maxAge}`,
|
|
159
|
-
].join("; ");
|
|
160
|
-
/**
|
|
161
|
-
* Which account this request is acting as — see `accountSlots.ts`.
|
|
162
|
-
*
|
|
163
|
-
* URL first, header second. The URL is the one a full page load, a bookmark
|
|
164
|
-
* and an `<img src>` can carry, so it has to be authoritative; the header is
|
|
165
|
-
* how an SPA's `fetch` calls say the same thing without every route constant
|
|
166
|
-
* in the app growing a query param.
|
|
167
|
-
*/
|
|
168
|
-
const slotOf = (req) => {
|
|
169
|
-
const fromUrl = slotFromUrl(req.url);
|
|
170
|
-
if (fromUrl !== null)
|
|
171
|
-
return fromUrl;
|
|
172
|
-
const header = req.headers.get(ACCOUNT_SLOT_HEADER);
|
|
173
|
-
return header === null ? 0 : normalizeSlot(header);
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Who the CLIENT said it was rendering for, or null if it did not say.
|
|
177
|
-
*
|
|
178
|
-
* 🔴 This is never identity and can never be read as any. It exists so a
|
|
179
|
-
* guard can notice that the account behind this browser's slot has been
|
|
180
|
-
* replaced since the page was drawn — see `accountSlots.ts` for the failure
|
|
181
|
-
* and `isAccountDrift` for the one rule that decides it. Bounded, because it
|
|
182
|
-
* is attacker-supplied and only ever compared to a string we already hold.
|
|
183
|
-
*/
|
|
184
|
-
const expectedUserOf = (req) => {
|
|
185
|
-
const raw = req.headers.get(ACCOUNT_USER_HEADER);
|
|
186
|
-
if (raw === null)
|
|
187
|
-
return null;
|
|
188
|
-
const value = raw.trim();
|
|
189
|
-
return value.length > 0 && value.length <= 200 ? value : null;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Signature first, expiry second — an unsigned value proves nothing.
|
|
193
|
-
*
|
|
194
|
-
* `slot` names WHICH cookie to read. It defaults to the one the request
|
|
195
|
-
* asked for, so every existing caller keeps reading the bare cookie name.
|
|
196
|
-
*/
|
|
197
|
-
const parse = (req, slot) => {
|
|
198
|
-
const cookie = req.headers.get("cookie");
|
|
199
|
-
if (!cookie)
|
|
200
|
-
return null;
|
|
201
|
-
const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
|
|
202
|
-
const match = new RegExp(`(?:^|;\\s*)${name}=([^;]+)`).exec(cookie);
|
|
203
|
-
const value = match?.[1];
|
|
204
|
-
if (!value)
|
|
205
|
-
return null;
|
|
206
|
-
const parts = value.split(".");
|
|
207
|
-
if (parts.length !== 3)
|
|
208
|
-
return null;
|
|
209
|
-
const [expiry, id, signature] = parts;
|
|
210
|
-
if (!expiry || !id || !signature)
|
|
211
|
-
return null;
|
|
212
|
-
if (!constantTimeEqual(signature, sign(`${expiry}.${id}`)))
|
|
213
|
-
return null;
|
|
214
|
-
const expiresAt = Number(expiry);
|
|
215
|
-
if (!Number.isFinite(expiresAt) || expiresAt <= now())
|
|
216
|
-
return null;
|
|
217
|
-
return { id };
|
|
218
|
-
};
|
|
219
|
-
/** The live user at one slot, or null. One query, used by three methods. */
|
|
220
|
-
const userAt = (req, slot) => {
|
|
221
|
-
const session = parse(req, slot);
|
|
222
|
-
if (!session)
|
|
223
|
-
return null;
|
|
224
|
-
const row = db
|
|
225
|
-
.query("SELECT user_id, expires_at FROM sessions WHERE id = ?")
|
|
226
|
-
.get(session.id);
|
|
227
|
-
return row && row.expires_at > now() ? row.user_id : null;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* The seconds a cookie for `value` should live, from the value's own expiry.
|
|
231
|
-
*
|
|
232
|
-
* Deriving it rather than passing it is what keeps a remember-me cookie and
|
|
233
|
-
* its row in agreement — there is one number and both read it. A value this
|
|
234
|
-
* cannot read falls back to the store default, deliberately erring SHORT:
|
|
235
|
-
* too short costs a sign-in, too long leaves a dead cookie riding every
|
|
236
|
-
* request until the browser gives up on it.
|
|
237
|
-
*/
|
|
238
|
-
const cookieLifetimeOf = (value) => {
|
|
239
|
-
const expiresAt = Number(value.split(".")[0]);
|
|
240
|
-
if (!Number.isFinite(expiresAt))
|
|
241
|
-
return options.sessionTtlSeconds;
|
|
242
|
-
const seconds = Math.ceil((expiresAt - now()) / 1000);
|
|
243
|
-
return seconds > 0 ? seconds : options.sessionTtlSeconds;
|
|
244
|
-
};
|
|
245
|
-
/** Opportunistic, on writes: rare, cheap, and exactly when the table grew. */
|
|
246
|
-
const sweep = () => {
|
|
247
|
-
db.query("DELETE FROM sessions WHERE expires_at <= ?").run(now());
|
|
248
|
-
};
|
|
249
|
-
/** A session minted before `created_at` existed still has a real start: its
|
|
250
|
-
* expiry minus the TTL. Better than 0, which renders as 1970. */
|
|
251
|
-
const startOf = (row) => row.created_at && row.created_at > 0
|
|
252
|
-
? row.created_at
|
|
253
|
-
: row.expires_at - options.sessionTtlSeconds * 1000;
|
|
254
|
-
// 🔴 These three are plain closures rather than methods called through
|
|
255
|
-
// `this` on the returned object, because call sites in this repo destructure
|
|
256
|
-
// stores (`const { userIdOf } = sessions`) and a `this`-dependent method
|
|
257
|
-
// would throw the moment one of them did.
|
|
258
|
-
const create = (userId, req, signInOptions) => {
|
|
259
|
-
const at = now();
|
|
260
|
-
const ttl = signInOptions?.ttlSeconds ?? options.sessionTtlSeconds;
|
|
261
|
-
const expiresAt = at + ttl * 1000;
|
|
262
|
-
const id = randomBytes(16).toString("base64url");
|
|
263
|
-
db.query(`INSERT INTO sessions (id, user_id, expires_at, user_agent, ip, created_at, last_seen_at, place)
|
|
264
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(id, userId, expiresAt, req ? clientUserAgentOf(req) : "", req ? clientAddressOf(req) : "", at, at,
|
|
265
|
-
// The place is resolved HERE, not read back later: `describePlace` of
|
|
266
|
-
// the edge headers merged with this machine's snapshot is a fact about
|
|
267
|
-
// the moment of sign-in, and the snapshot is refreshed monthly.
|
|
268
|
-
req ? describePlace(clientFactsOf(req, { lookup: placeLookup })) : "");
|
|
269
|
-
sweep();
|
|
270
|
-
const payload = `${expiresAt}.${id}`;
|
|
271
|
-
return `${payload}.${sign(payload)}`;
|
|
272
|
-
};
|
|
273
|
-
const sessionCookie = (value, req, slot) => {
|
|
274
|
-
const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
|
|
275
|
-
return `${name}=${value}; ${cookieAttributes(req, cookieLifetimeOf(value))}`;
|
|
276
|
-
};
|
|
277
|
-
const revokeAt = (req, slot) => {
|
|
278
|
-
const session = parse(req, slot);
|
|
279
|
-
if (!session)
|
|
280
|
-
return false;
|
|
281
|
-
db.query("DELETE FROM sessions WHERE id = ?").run(session.id);
|
|
282
|
-
return true;
|
|
283
|
-
};
|
|
284
|
-
const signedInSlots = (req) => {
|
|
285
|
-
const occupants = [];
|
|
286
|
-
for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
|
|
287
|
-
const userId = userAt(req, slot);
|
|
288
|
-
if (userId)
|
|
289
|
-
occupants.push({ slot, userId });
|
|
290
|
-
}
|
|
291
|
-
return occupants;
|
|
292
|
-
};
|
|
293
93
|
return {
|
|
294
|
-
|
|
295
|
-
slotOf,
|
|
296
|
-
expectedUserOf,
|
|
297
|
-
create,
|
|
298
|
-
signedInSlots,
|
|
299
|
-
signIn(userId, req, signInOptions) {
|
|
300
|
-
const slot = normalizeSlot(signInOptions?.slot ?? slotOf(req));
|
|
301
|
-
const value = create(userId, req, signInOptions);
|
|
302
|
-
return {
|
|
303
|
-
cookie: sessionCookie(value, req, slot),
|
|
304
|
-
slot,
|
|
305
|
-
expiresAt: Number(value.split(".")[0]),
|
|
306
|
-
};
|
|
307
|
-
},
|
|
308
|
-
slotForUser(req, userId) {
|
|
309
|
-
return signedInSlots(req).find((entry) => entry.userId === userId)?.slot ?? null;
|
|
310
|
-
},
|
|
311
|
-
slotToAdd(req, userId) {
|
|
312
|
-
const occupied = signedInSlots(req);
|
|
313
|
-
// Already here → their slot. Signing in twice must never take a second
|
|
314
|
-
// one; see the interface for why that exhausts the switcher.
|
|
315
|
-
const mine = occupied.find((entry) => entry.userId === userId);
|
|
316
|
-
if (mine)
|
|
317
|
-
return mine.slot;
|
|
318
|
-
const taken = new Set(occupied.map((entry) => entry.slot));
|
|
319
|
-
for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
|
|
320
|
-
if (!taken.has(slot))
|
|
321
|
-
return slot;
|
|
322
|
-
}
|
|
323
|
-
// Full. The caller says so; nothing is evicted to make room.
|
|
324
|
-
return null;
|
|
325
|
-
},
|
|
326
|
-
userIdOf(req) {
|
|
327
|
-
const session = parse(req);
|
|
328
|
-
if (!session)
|
|
329
|
-
return null;
|
|
94
|
+
byId(id) {
|
|
330
95
|
const row = db
|
|
331
|
-
.query(
|
|
332
|
-
.get(
|
|
333
|
-
|
|
334
|
-
return null;
|
|
335
|
-
// "Last seen" is maintained HERE because this is the one call every
|
|
336
|
-
// satellite makes on every authenticated request — the alternative is a
|
|
337
|
-
// per-app middleware that eighteen apps have to remember, which is the
|
|
338
|
-
// same as not having it. Throttled; see TOUCH_THROTTLE_MS.
|
|
339
|
-
const at = now();
|
|
340
|
-
if (at - (row.last_seen_at ?? 0) >= TOUCH_THROTTLE_MS) {
|
|
341
|
-
db.query("UPDATE sessions SET last_seen_at = ? WHERE id = ?").run(at, session.id);
|
|
342
|
-
}
|
|
343
|
-
return row.user_id;
|
|
96
|
+
.query(`SELECT ${COLUMNS} FROM sessions WHERE id = ?`)
|
|
97
|
+
.get(id);
|
|
98
|
+
return row ? normalize(row) : null;
|
|
344
99
|
},
|
|
345
|
-
|
|
346
|
-
const currentId = req ? (parse(req)?.id ?? null) : null;
|
|
100
|
+
forUser(userId, liveAfter) {
|
|
347
101
|
const rows = db
|
|
348
|
-
.query(`SELECT
|
|
349
|
-
FROM sessions WHERE user_id = ? AND expires_at > ?
|
|
102
|
+
.query(`SELECT ${COLUMNS} FROM sessions WHERE user_id = ? AND expires_at > ?
|
|
350
103
|
ORDER BY last_seen_at DESC, expires_at DESC`)
|
|
351
|
-
.all(userId,
|
|
352
|
-
return rows.map(
|
|
353
|
-
handle: handleOf(row.id),
|
|
354
|
-
userId: row.user_id,
|
|
355
|
-
createdAt: startOf(row),
|
|
356
|
-
lastSeenAt: row.last_seen_at && row.last_seen_at > 0 ? row.last_seen_at : startOf(row),
|
|
357
|
-
expiresAt: row.expires_at,
|
|
358
|
-
userAgent: row.user_agent ?? "",
|
|
359
|
-
ip: row.ip ?? "",
|
|
360
|
-
place: row.place ?? "",
|
|
361
|
-
current: currentId !== null && row.id === currentId,
|
|
362
|
-
}));
|
|
104
|
+
.all(userId, liveAfter);
|
|
105
|
+
return rows.map(normalize);
|
|
363
106
|
},
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return false;
|
|
367
|
-
// Matched in JS against this user's own rows rather than in SQL,
|
|
368
|
-
// because the handle is a hash and sqlite cannot compute one. The scan
|
|
369
|
-
// is over one account's live sessions — single digits — and it is the
|
|
370
|
-
// same bound the list above already pays.
|
|
371
|
-
const rows = db
|
|
372
|
-
.query("SELECT id FROM sessions WHERE user_id = ? AND expires_at > ?")
|
|
373
|
-
.all(userId, now());
|
|
374
|
-
const match = rows.find((row) => handleOf(row.id) === handle);
|
|
375
|
-
if (!match)
|
|
376
|
-
return false;
|
|
377
|
-
db.query("DELETE FROM sessions WHERE id = ? AND user_id = ?").run(match.id, userId);
|
|
378
|
-
return true;
|
|
107
|
+
insert(row) {
|
|
108
|
+
db.query(`INSERT INTO sessions (${COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(row.id, row.user_id, row.expires_at, row.user_agent, row.ip, row.created_at, row.last_seen_at, row.place);
|
|
379
109
|
},
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (!session)
|
|
383
|
-
return;
|
|
384
|
-
db.query("DELETE FROM sessions WHERE id = ?").run(session.id);
|
|
385
|
-
sweep();
|
|
110
|
+
touch(id, at) {
|
|
111
|
+
db.query("UPDATE sessions SET last_seen_at = ? WHERE id = ?").run(at, id);
|
|
386
112
|
},
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const cleared = [];
|
|
390
|
-
for (let slot = 0; slot < MAX_ACCOUNT_SLOTS; slot++) {
|
|
391
|
-
if (revokeAt(req, slot))
|
|
392
|
-
cleared.push(slot);
|
|
393
|
-
}
|
|
394
|
-
if (cleared.length > 0)
|
|
395
|
-
sweep();
|
|
396
|
-
return cleared;
|
|
113
|
+
deleteById(id) {
|
|
114
|
+
db.query("DELETE FROM sessions WHERE id = ?").run(id);
|
|
397
115
|
},
|
|
398
|
-
|
|
116
|
+
deleteByIdForUser(id, userId) {
|
|
117
|
+
db.query("DELETE FROM sessions WHERE id = ? AND user_id = ?").run(id, userId);
|
|
118
|
+
},
|
|
119
|
+
deleteForUser(userId) {
|
|
399
120
|
db.query("DELETE FROM sessions WHERE user_id = ?").run(userId);
|
|
400
121
|
},
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (session) {
|
|
404
|
-
db.query("DELETE FROM sessions WHERE user_id = ? AND id != ?").run(userId, session.id);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
db.query("DELETE FROM sessions WHERE user_id = ?").run(userId);
|
|
408
|
-
}
|
|
122
|
+
deleteOthersForUser(userId, keepId) {
|
|
123
|
+
db.query("DELETE FROM sessions WHERE user_id = ? AND id != ?").run(userId, keepId);
|
|
409
124
|
},
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const name = slotCookieName(options.cookieName, slot ?? slotOf(req));
|
|
413
|
-
return `${name}=; ${cookieAttributes(req, 0)}`;
|
|
125
|
+
deleteExpired(at) {
|
|
126
|
+
db.query("DELETE FROM sessions WHERE expires_at <= ?").run(at);
|
|
414
127
|
},
|
|
415
128
|
};
|
|
416
129
|
}
|
|
130
|
+
export function createUserSessionStore(options) {
|
|
131
|
+
if (options.dbPath !== ":memory:")
|
|
132
|
+
mkdirSync(path.dirname(options.dbPath), { recursive: true });
|
|
133
|
+
const db = new Database(options.dbPath, { create: true });
|
|
134
|
+
// busy_timeout FIRST — journal_mode takes a lock. scripts/sqliteBusyTimeout.test.ts
|
|
135
|
+
db.exec("PRAGMA busy_timeout = 5000;");
|
|
136
|
+
db.exec("PRAGMA journal_mode = WAL;");
|
|
137
|
+
return createUserSessionStoreOver(createSqliteSessionRows(db), options);
|
|
138
|
+
}
|
|
417
139
|
//# sourceMappingURL=userSessions.js.map
|
package/dist/userSessions.js.map
CHANGED
|
@@ -1 +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,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EA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EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IACtC,OAAO,0BAA0B,CAAC,uBAAuB,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedauth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The app side of fleet SSO — 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
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,24 @@
|
|
|
23
23
|
"source": "./src/userSessions.ts",
|
|
24
24
|
"import": "./dist/userSessions.js"
|
|
25
25
|
},
|
|
26
|
+
"./user-sessions-core": {
|
|
27
|
+
"types": "./dist/userSessions.core.d.ts",
|
|
28
|
+
"bun": "./src/userSessions.core.ts",
|
|
29
|
+
"source": "./src/userSessions.core.ts",
|
|
30
|
+
"import": "./dist/userSessions.core.js"
|
|
31
|
+
},
|
|
32
|
+
"./sso-user-store": {
|
|
33
|
+
"types": "./dist/ssoUsers.d.ts",
|
|
34
|
+
"bun": "./src/ssoUsers.ts",
|
|
35
|
+
"source": "./src/ssoUsers.ts",
|
|
36
|
+
"import": "./dist/ssoUsers.js"
|
|
37
|
+
},
|
|
38
|
+
"./d1-stores": {
|
|
39
|
+
"types": "./dist/d1Stores.d.ts",
|
|
40
|
+
"bun": "./src/d1Stores.ts",
|
|
41
|
+
"source": "./src/d1Stores.ts",
|
|
42
|
+
"import": "./dist/d1Stores.js"
|
|
43
|
+
},
|
|
26
44
|
"./mount-gated": {
|
|
27
45
|
"types": "./dist/mountGatedApp.d.ts",
|
|
28
46
|
"bun": "./src/mountGatedApp.ts",
|
|
@@ -134,6 +152,7 @@
|
|
|
134
152
|
"@types/bun": "latest",
|
|
135
153
|
"@types/react": "^19.2.18",
|
|
136
154
|
"@types/react-dom": "^19.2.5",
|
|
155
|
+
"cursedbelt-server": "^4.9.0",
|
|
137
156
|
"hono": "^4.13.5",
|
|
138
157
|
"react": "^19.2.8",
|
|
139
158
|
"react-dom": "^19.2.8",
|