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
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is on the other end of a request, described the way a person would
|
|
3
|
+
* describe it: what device, what browser, from where.
|
|
4
|
+
*
|
|
5
|
+
* ── Why it is here and not in `apps/auth` (2026-08-12) ──────────────────────
|
|
6
|
+
* It WAS in `apps/auth/src/server/notifications.ts`, whose header said, in as
|
|
7
|
+
* many words: *"It lives in this app rather than in a shared package because
|
|
8
|
+
* auth is its only consumer — the moment a second app needs it, it moves rather
|
|
9
|
+
* than being copied."* The session list is that second consumer, and it is not
|
|
10
|
+
* in auth: `userSessions.ts` stamps a device and an address onto every session
|
|
11
|
+
* row in every satellite, so the describer has to sit at or below the kit.
|
|
12
|
+
*
|
|
13
|
+
* cwip/cursedbelt would be the home the moment something that is NOT a
|
|
14
|
+
* satellite needs it. Today every consumer is one — the kit's own session store
|
|
15
|
+
* and the accounts app that reads it — and the kit is the lowest layer that
|
|
16
|
+
* both can see.
|
|
17
|
+
*
|
|
18
|
+
* ── The facts became STRUCTURED (2026-08-25, owner) ─────────────────────────
|
|
19
|
+
* The owner's ask: *"in the emails cursedalchemy sends about login attempts I
|
|
20
|
+
* want to be able to tell it was me more confidently — by seeing it was the
|
|
21
|
+
* expected type of device, like a Mac, the expected browser like Chrome, at the
|
|
22
|
+
* right city."* You cannot answer "is this my usual browser?" from the sentence
|
|
23
|
+
* `"Chrome on macOS · 73.12.44.9 · US"`, because comparing sentences compares
|
|
24
|
+
* the address too and every sentence is then new. So the single string became
|
|
25
|
+
* `ClientFacts` — one FIELD per thing a person recognises separately (browser,
|
|
26
|
+
* platform, city, region, country, network) — and the sentence became a
|
|
27
|
+
* rendering of it. `apps/auth/src/server/familiarity.ts` is the consumer that
|
|
28
|
+
* needed the split, and every stored row now carries the fields as well as the
|
|
29
|
+
* sentence.
|
|
30
|
+
*
|
|
31
|
+
* 🔴 **Nothing here authorizes anything.** Every value is attacker-influenced
|
|
32
|
+
* (a user-agent is whatever the client typed; the leftmost `x-forwarded-for`
|
|
33
|
+
* entry is client-supplied on any proxy that appends rather than replaces; the
|
|
34
|
+
* `cf-*` headers are Cloudflare's only for traffic that actually came through
|
|
35
|
+
* Cloudflare, and a request that reached an origin directly can send whatever
|
|
36
|
+
* it likes). They are shown to the account's OWN owner as a hint for
|
|
37
|
+
* recognising their own devices. "Possibly spoofed" is an acceptable property
|
|
38
|
+
* for that and would not be for anything else — in particular, a recognised
|
|
39
|
+
* device must never relax a check, only reassure a reader.
|
|
40
|
+
*/
|
|
41
|
+
/** How much of a user-agent is worth keeping. Long enough for the non-browser
|
|
42
|
+
* clients (curl, a smoke, a script) to still be identifiable, short enough
|
|
43
|
+
* that a hostile 8KB header cannot be stored per session row. */
|
|
44
|
+
export const MAX_USER_AGENT_BYTES = 200;
|
|
45
|
+
/** How much of any single client-supplied fact is stored. A city name is short;
|
|
46
|
+
* a header claiming to be one is whatever the sender typed. */
|
|
47
|
+
const MAX_FACT_BYTES = 64;
|
|
48
|
+
/** Control characters, which a header must never carry into a log line, a
|
|
49
|
+
* database row or a mail body. */
|
|
50
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping them from a client-supplied header is exactly the point.
|
|
51
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/g;
|
|
52
|
+
/** A trimmed, bounded, control-character-free copy of a client-supplied value. */
|
|
53
|
+
const fact = (value) => (value ?? "").replace(CONTROL_CHARACTERS, "").trim().slice(0, MAX_FACT_BYTES);
|
|
54
|
+
/**
|
|
55
|
+
* A header Cloudflare percent-encodes when the value is not ASCII (a city like
|
|
56
|
+
* `Zürich` arrives as `Z%C3%BCrich`). Decoded when it decodes, kept verbatim
|
|
57
|
+
* when it does not — a malformed escape is a value, not an exception.
|
|
58
|
+
*/
|
|
59
|
+
function decodedFact(value) {
|
|
60
|
+
const raw = fact(value);
|
|
61
|
+
if (!raw.includes("%"))
|
|
62
|
+
return raw;
|
|
63
|
+
try {
|
|
64
|
+
return fact(decodeURIComponent(raw));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return raw;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Enough of a user-agent to recognize your own laptop, and no more.
|
|
72
|
+
*
|
|
73
|
+
* Deliberately not a UA-parsing library and deliberately not exhaustive: these
|
|
74
|
+
* values exist so the owner can tell "my Mac" from "something else", and a
|
|
75
|
+
* wrong guess between two Chromium forks costs nothing.
|
|
76
|
+
*/
|
|
77
|
+
export function deviceParts(userAgent) {
|
|
78
|
+
const ua = (userAgent ?? "").trim();
|
|
79
|
+
if (!ua)
|
|
80
|
+
return { browser: "", platform: "", form: "unknown" };
|
|
81
|
+
const browser = /\bEdg\//.test(ua)
|
|
82
|
+
? "Edge"
|
|
83
|
+
: /\bOPR\//.test(ua)
|
|
84
|
+
? "Opera"
|
|
85
|
+
: /\bFirefox\//.test(ua)
|
|
86
|
+
? "Firefox"
|
|
87
|
+
: /\bChrome\//.test(ua)
|
|
88
|
+
? "Chrome"
|
|
89
|
+
: // Safari LAST: every Chromium UA also claims to be Safari.
|
|
90
|
+
/\bSafari\//.test(ua)
|
|
91
|
+
? "Safari"
|
|
92
|
+
: "";
|
|
93
|
+
const platform = /\biPhone\b/.test(ua)
|
|
94
|
+
? "iPhone"
|
|
95
|
+
: /\biPad\b/.test(ua)
|
|
96
|
+
? "iPad"
|
|
97
|
+
: /\bAndroid\b/.test(ua)
|
|
98
|
+
? "Android"
|
|
99
|
+
: /\bMac OS X\b|\bMacintosh\b/.test(ua)
|
|
100
|
+
? "macOS"
|
|
101
|
+
: /\bWindows\b/.test(ua)
|
|
102
|
+
? "Windows"
|
|
103
|
+
: /\bLinux\b/.test(ua)
|
|
104
|
+
? "Linux"
|
|
105
|
+
: "";
|
|
106
|
+
// A crawler that says so is worth naming: it is the single most common
|
|
107
|
+
// non-person on a public satellite, and reading "an unknown device" for it
|
|
108
|
+
// costs the reader the one glance that would have explained the row.
|
|
109
|
+
const robot = /\bbot\b|crawler|spider|curl\/|wget\/|python-requests|Bun\//i.test(ua);
|
|
110
|
+
const form = robot
|
|
111
|
+
? "bot"
|
|
112
|
+
: platform === "iPhone" || (platform === "Android" && /\bMobile\b/.test(ua))
|
|
113
|
+
? "phone"
|
|
114
|
+
: platform === "iPad"
|
|
115
|
+
? "tablet"
|
|
116
|
+
: platform
|
|
117
|
+
? "computer"
|
|
118
|
+
: "unknown";
|
|
119
|
+
return { browser, platform, form };
|
|
120
|
+
}
|
|
121
|
+
/** `browser` and `platform` as the phrase a person would say. */
|
|
122
|
+
export function describeDeviceParts(parts, fallback = "") {
|
|
123
|
+
if (parts.browser && parts.platform)
|
|
124
|
+
return `${parts.browser} on ${parts.platform}`;
|
|
125
|
+
if (parts.browser)
|
|
126
|
+
return parts.browser;
|
|
127
|
+
if (parts.platform)
|
|
128
|
+
return parts.platform;
|
|
129
|
+
// A non-browser client (curl, a smoke, a script) — say so plainly rather
|
|
130
|
+
// than dressing it up as a device.
|
|
131
|
+
return fallback.slice(0, 60) || "an unknown device";
|
|
132
|
+
}
|
|
133
|
+
/** Enough of a user-agent to recognize your own laptop, as one phrase. */
|
|
134
|
+
export function describeDevice(userAgent) {
|
|
135
|
+
const ua = (userAgent ?? "").trim();
|
|
136
|
+
if (!ua)
|
|
137
|
+
return "an unknown device";
|
|
138
|
+
return describeDeviceParts(deviceParts(ua), ua);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Where Cloudflare says the request came from.
|
|
142
|
+
*
|
|
143
|
+
* `cf-ipcountry` is sent on every proxied request by default. The rest require
|
|
144
|
+
* the zone's *Add visitor location headers* managed transform; until it is on
|
|
145
|
+
* they are simply absent, which is why every field is independently optional
|
|
146
|
+
* and why `clientFactsOf` takes an origin-side lookup as the second source.
|
|
147
|
+
*/
|
|
148
|
+
export function clientPlaceOf(request) {
|
|
149
|
+
const header = (name) => request?.headers.get(name);
|
|
150
|
+
return {
|
|
151
|
+
// A country is two letters and a continent is two; bounded far tighter
|
|
152
|
+
// than a place name, because a 64-character "country" in a row or a mail
|
|
153
|
+
// body is nothing but a sender's padding.
|
|
154
|
+
country: fact(header("cf-ipcountry")).slice(0, 8).toUpperCase(),
|
|
155
|
+
region: decodedFact(header("cf-region")),
|
|
156
|
+
city: decodedFact(header("cf-ipcity")),
|
|
157
|
+
postalCode: fact(header("cf-postal-code")),
|
|
158
|
+
timezone: fact(header("cf-timezone")),
|
|
159
|
+
continent: fact(header("cf-ipcontinent")).slice(0, 4).toUpperCase(),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** An empty place — the honest answer for a request nothing is known about. */
|
|
163
|
+
export const UNKNOWN_PLACE = {
|
|
164
|
+
country: "",
|
|
165
|
+
region: "",
|
|
166
|
+
city: "",
|
|
167
|
+
postalCode: "",
|
|
168
|
+
timezone: "",
|
|
169
|
+
continent: "",
|
|
170
|
+
};
|
|
171
|
+
/** Is anything at all known about where this came from? */
|
|
172
|
+
export const placeIsKnown = (place) => Boolean(place.city || place.region || place.country);
|
|
173
|
+
/**
|
|
174
|
+
* A place as a person would name it — "Austin, Texas, US".
|
|
175
|
+
*
|
|
176
|
+
* Degrades by dropping fields rather than by printing placeholders: a request
|
|
177
|
+
* we only have a country for reads "US", and one we know nothing about reads
|
|
178
|
+
* "" so the caller can choose its own words for absence.
|
|
179
|
+
*/
|
|
180
|
+
export function describePlace(place) {
|
|
181
|
+
// `ZZ` is the dataset's "no country" marker and what Cloudflare sends for a
|
|
182
|
+
// client it cannot place; printing it would be printing a bug.
|
|
183
|
+
const country = place.country === "ZZ" || place.country === "XX" ? "" : place.country;
|
|
184
|
+
// A region that repeats the city ("Singapore, Singapore") is noise.
|
|
185
|
+
const region = place.region && place.region.toLowerCase() !== place.city.toLowerCase() ? place.region : "";
|
|
186
|
+
return [place.city, region, country].filter(Boolean).join(", ");
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The caller's address as far as this box can tell, or `""` when nothing said.
|
|
190
|
+
*
|
|
191
|
+
* `x-forwarded-for` is the FIRST hop, because nginx appends and a client may
|
|
192
|
+
* send its own header — so the leftmost entry is attacker-controlled but is
|
|
193
|
+
* also the only one that means anything on a correctly-configured proxy.
|
|
194
|
+
*
|
|
195
|
+
* Empty string rather than a phrase, because this is the STORAGE shape: a row
|
|
196
|
+
* that says nothing must be distinguishable from one that says "unknown", and
|
|
197
|
+
* only the rendering half should be choosing English. `describeClient` is the
|
|
198
|
+
* rendering half.
|
|
199
|
+
*/
|
|
200
|
+
export function clientAddressOf(request) {
|
|
201
|
+
const forwarded = request.headers.get("x-forwarded-for") ?? "";
|
|
202
|
+
const first = (forwarded.split(",")[0] ?? "").trim();
|
|
203
|
+
const ip = first || request.headers.get("cf-connecting-ip") || "";
|
|
204
|
+
// Bounded for the same reason the user-agent is: it lands in a database row
|
|
205
|
+
// and a header is whatever the client sent.
|
|
206
|
+
return ip.slice(0, 60);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The address with its host part dropped — the unit "my usual network" is
|
|
210
|
+
* measured in. See `ClientFacts.network` for why an exact address is the wrong
|
|
211
|
+
* comparison.
|
|
212
|
+
*
|
|
213
|
+
* IPv4 keeps three octets (/24); IPv6 keeps three hextets (/48), which is the
|
|
214
|
+
* smallest block a residential customer is normally delegated whole.
|
|
215
|
+
*/
|
|
216
|
+
export function ipNetworkOf(ip) {
|
|
217
|
+
const address = (ip ?? "").trim();
|
|
218
|
+
if (!address)
|
|
219
|
+
return "";
|
|
220
|
+
if (address.includes(":")) {
|
|
221
|
+
const hextets = address.split(":");
|
|
222
|
+
// `::` collapses zero groups, so a short address is already its own
|
|
223
|
+
// prefix — expanding it here would invent digits the client never sent.
|
|
224
|
+
const kept = hextets.slice(0, 3).filter((part) => part !== "");
|
|
225
|
+
return kept.length ? `${kept.join(":")}::x` : address;
|
|
226
|
+
}
|
|
227
|
+
const octets = address.split(".");
|
|
228
|
+
if (octets.length !== 4)
|
|
229
|
+
return address;
|
|
230
|
+
return `${octets.slice(0, 3).join(".")}.x`;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Everything one request says about its client.
|
|
234
|
+
*
|
|
235
|
+
* 🔴 The edge WINS over the lookup, field by field. Cloudflare places the
|
|
236
|
+
* address it actually terminated the connection from, against data it refreshes
|
|
237
|
+
* continuously; a local table is a monthly snapshot of somebody else's
|
|
238
|
+
* measurement. Merging per-field rather than choosing one source whole is what
|
|
239
|
+
* lets a zone with only `cf-ipcountry` still get a city.
|
|
240
|
+
*/
|
|
241
|
+
export function clientFactsOf(request, options = {}) {
|
|
242
|
+
const ip = request ? clientAddressOf(request) : "";
|
|
243
|
+
const userAgent = request ? clientUserAgentOf(request) : "";
|
|
244
|
+
const parts = deviceParts(userAgent);
|
|
245
|
+
const edge = clientPlaceOf(request);
|
|
246
|
+
const local = ip && options.lookup ? (options.lookup(ip) ?? UNKNOWN_PLACE) : UNKNOWN_PLACE;
|
|
247
|
+
const place = {
|
|
248
|
+
country: edge.country || local.country,
|
|
249
|
+
region: edge.region || local.region,
|
|
250
|
+
city: edge.city || local.city,
|
|
251
|
+
postalCode: edge.postalCode || local.postalCode,
|
|
252
|
+
timezone: edge.timezone || local.timezone,
|
|
253
|
+
continent: edge.continent || local.continent,
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
ip,
|
|
257
|
+
network: ipNetworkOf(ip),
|
|
258
|
+
userAgent,
|
|
259
|
+
device: describeDeviceParts(parts, userAgent),
|
|
260
|
+
...parts,
|
|
261
|
+
...place,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** The whole client as one sentence — address, place, device. */
|
|
265
|
+
export function describeClientFacts(facts) {
|
|
266
|
+
const place = describePlace(facts);
|
|
267
|
+
return [facts.ip || "an unknown address", place, facts.device].filter(Boolean).join(" · ");
|
|
268
|
+
}
|
|
269
|
+
/** The user-agent as it should be STORED — verbatim, bounded, never parsed. */
|
|
270
|
+
export const clientUserAgentOf = (request) => (request.headers.get("user-agent") ?? "").slice(0, MAX_USER_AGENT_BYTES);
|
|
271
|
+
/** Both halves, rendered for a human. */
|
|
272
|
+
export function describeClient(request) {
|
|
273
|
+
return {
|
|
274
|
+
ip: clientAddressOf(request) || "an unknown address",
|
|
275
|
+
device: describeDevice(request.headers.get("user-agent")),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=clientDescription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientDescription.js","sourceRoot":"","sources":["../src/clientDescription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAQH;;kEAEkE;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC;gEACgE;AAChE,MAAM,cAAc,GAAG,EAAE,CAAC;AA+D1B;mCACmC;AACnC,8HAA8H;AAC9H,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAEpD,kFAAkF;AAClF,MAAM,IAAI,GAAG,CAAC,KAAgC,EAAU,EAAE,CACzD,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;AAE/E;;;;GAIG;AACH,SAAS,WAAW,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AAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAE1E,yCAAyC;AACzC,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC9C,OAAO;QACN,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,oBAAoB;QACpD,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;KACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing two secrets without leaking how far the comparison got.
|
|
3
|
+
*
|
|
4
|
+
* ## Why this module exists (2026-08-07)
|
|
5
|
+
*
|
|
6
|
+
* There were **two** implementations of this in the platform this was cut from — one in
|
|
7
|
+
* `ownerAuth.server.ts` (node `timingSafeEqual`, padding both sides to a common
|
|
8
|
+
* length) and one in the roms<->hobbies bridge, deleted 2026-08-25 (a pure-JS accumulator). Both were
|
|
9
|
+
* correct; neither knew about the other. Adding roms' manifest-sync token would
|
|
10
|
+
* have made three, and three copies of a primitive whose failure mode is
|
|
11
|
+
* *silent* — a version that returns early still passes every functional test and
|
|
12
|
+
* is simply a timing oracle — is how the fleet ends up with one good one and two
|
|
13
|
+
* that quietly rotted.
|
|
14
|
+
*
|
|
15
|
+
* ## Why the pure-JS form is canonical rather than `crypto.timingSafeEqual`
|
|
16
|
+
*
|
|
17
|
+
* `timingSafeEqual` **throws** on unequal lengths, so every caller has to
|
|
18
|
+
* remember to pad first — and a caller that forgets has converted a comparison
|
|
19
|
+
* into an exception whose presence is itself the oracle. This form has no such
|
|
20
|
+
* trap: the length difference is folded into the accumulator, the loop always
|
|
21
|
+
* runs the longer of the two, and there is no input that makes it exit early. It
|
|
22
|
+
* also carries no node-builtin dependency, so the contract modules that both a
|
|
23
|
+
* server and a browser bundle can reach may use it.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* True when `a` and `b` are the same string, in time that does not depend on
|
|
27
|
+
* where they first differ.
|
|
28
|
+
*
|
|
29
|
+
* Note the honest limit, so nobody expects more than it gives: the *lengths* are
|
|
30
|
+
* still observable through the loop count. That is fine for the things this is
|
|
31
|
+
* used on — tokens and signatures of fixed length — and no constant-time compare
|
|
32
|
+
* of variable-length inputs can do better without hashing first.
|
|
33
|
+
*/
|
|
34
|
+
export declare function constantTimeEqual(a: string, b: string): boolean;
|
|
35
|
+
//# sourceMappingURL=constantTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constantTime.d.ts","sourceRoot":"","sources":["../src/constantTime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAU/D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing two secrets without leaking how far the comparison got.
|
|
3
|
+
*
|
|
4
|
+
* ## Why this module exists (2026-08-07)
|
|
5
|
+
*
|
|
6
|
+
* There were **two** implementations of this in the platform this was cut from — one in
|
|
7
|
+
* `ownerAuth.server.ts` (node `timingSafeEqual`, padding both sides to a common
|
|
8
|
+
* length) and one in the roms<->hobbies bridge, deleted 2026-08-25 (a pure-JS accumulator). Both were
|
|
9
|
+
* correct; neither knew about the other. Adding roms' manifest-sync token would
|
|
10
|
+
* have made three, and three copies of a primitive whose failure mode is
|
|
11
|
+
* *silent* — a version that returns early still passes every functional test and
|
|
12
|
+
* is simply a timing oracle — is how the fleet ends up with one good one and two
|
|
13
|
+
* that quietly rotted.
|
|
14
|
+
*
|
|
15
|
+
* ## Why the pure-JS form is canonical rather than `crypto.timingSafeEqual`
|
|
16
|
+
*
|
|
17
|
+
* `timingSafeEqual` **throws** on unequal lengths, so every caller has to
|
|
18
|
+
* remember to pad first — and a caller that forgets has converted a comparison
|
|
19
|
+
* into an exception whose presence is itself the oracle. This form has no such
|
|
20
|
+
* trap: the length difference is folded into the accumulator, the loop always
|
|
21
|
+
* runs the longer of the two, and there is no input that makes it exit early. It
|
|
22
|
+
* also carries no node-builtin dependency, so the contract modules that both a
|
|
23
|
+
* server and a browser bundle can reach may use it.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* True when `a` and `b` are the same string, in time that does not depend on
|
|
27
|
+
* where they first differ.
|
|
28
|
+
*
|
|
29
|
+
* Note the honest limit, so nobody expects more than it gives: the *lengths* are
|
|
30
|
+
* still observable through the loop count. That is fine for the things this is
|
|
31
|
+
* used on — tokens and signatures of fixed length — and no constant-time compare
|
|
32
|
+
* of variable-length inputs can do better without hashing first.
|
|
33
|
+
*/
|
|
34
|
+
export function constantTimeEqual(a, b) {
|
|
35
|
+
const encoder = new TextEncoder();
|
|
36
|
+
const ab = encoder.encode(a);
|
|
37
|
+
const bb = encoder.encode(b);
|
|
38
|
+
// Fold the length difference INTO the accumulator instead of early-returning,
|
|
39
|
+
// so a wrong-length token is not distinguishable by timing from a wrong one.
|
|
40
|
+
let diff = ab.length ^ bb.length;
|
|
41
|
+
const len = Math.max(ab.length, bb.length);
|
|
42
|
+
for (let i = 0; i < len; i++)
|
|
43
|
+
diff |= (ab[i] ?? 0) ^ (bb[i] ?? 0);
|
|
44
|
+
return diff === 0;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=constantTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constantTime.js","sourceRoot":"","sources":["../src/constantTime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAS,EAAE,CAAS;IACrD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,8EAA8E;IAC9E,6EAA6E;IAC7E,IAAI,IAAI,GAAG,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,OAAO,IAAI,KAAK,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consumer side of the content census — how an app answers "what has this
|
|
3
|
+
* account made in you?" without hand-writing a counting loop per satellite.
|
|
4
|
+
*
|
|
5
|
+
* ── Why a helper and not five lines per app ─────────────────────────────────
|
|
6
|
+
* Every implementation is the same shape: a list of tables keyed on the auth
|
|
7
|
+
* user id, one `COUNT(*)` each. Five apps hand-writing that means five places
|
|
8
|
+
* to interpolate a table name into SQL, five places to forget that a table is
|
|
9
|
+
* created lazily and does not exist in a fresh database, and five chances for
|
|
10
|
+
* one of them to return a row for an account it was not asked about. Each of
|
|
11
|
+
* those failures produces a NUMBER on the owner's confirmation dialog, and a
|
|
12
|
+
* wrong number there is worse than no number — it is the one they act on.
|
|
13
|
+
*
|
|
14
|
+
* So the counting lives here, once:
|
|
15
|
+
* • table and column names are validated as bare identifiers before they can
|
|
16
|
+
* reach a query string (they cannot be bound as parameters);
|
|
17
|
+
* • a table that does not exist yet counts as zero rather than throwing,
|
|
18
|
+
* because an app whose owner has never used a feature genuinely has none;
|
|
19
|
+
* • only the ids that were asked about come back.
|
|
20
|
+
*
|
|
21
|
+
* @see `ssoConsumer.server.ts` for the route, and `sso.ts` for the ticket.
|
|
22
|
+
*/
|
|
23
|
+
import type { Database } from "bun:sqlite";
|
|
24
|
+
import type { ContentCensus } from "./sso";
|
|
25
|
+
/** One kind of thing an app keeps per account. */
|
|
26
|
+
export interface CensusCounter {
|
|
27
|
+
/** Stable machine id — `save-states`. Never shown to anybody. */
|
|
28
|
+
kind: string;
|
|
29
|
+
/** How the owner should read it, PLURAL and lowercase: "save states". It is
|
|
30
|
+
* rendered as "34 save states", so a singular label reads as a bug. */
|
|
31
|
+
label: string;
|
|
32
|
+
/** The table holding one row per thing. */
|
|
33
|
+
table: string;
|
|
34
|
+
/** The column carrying the auth user id. Defaults to `user_id`. */
|
|
35
|
+
column?: string;
|
|
36
|
+
/** Extra SQL predicate, ANDed in — e.g. excluding soft-deleted rows. Written
|
|
37
|
+
* by the app, never by a request; no value from the wire reaches it. */
|
|
38
|
+
where?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build a `contentCensus` implementation from a list of tables.
|
|
42
|
+
*
|
|
43
|
+
* Counts only — the census is entitled to how MANY rows an account has, never
|
|
44
|
+
* to what they say. Pass it straight to `createSsoConsumer({ contentCensus })`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function countingCensus(db: Database, counters: readonly CensusCounter[], options?: {
|
|
47
|
+
note?: string;
|
|
48
|
+
}): (userIds: string[]) => ContentCensus;
|
|
49
|
+
/**
|
|
50
|
+
* The answer for an app whose data belongs to NOBODY in particular — one shared
|
|
51
|
+
* corpus, library or tree.
|
|
52
|
+
*
|
|
53
|
+
* It is a real answer, not a shrug, and saying it explicitly is the whole point:
|
|
54
|
+
* "nothing here is attributed to an individual account" tells the owner that
|
|
55
|
+
* closing the app costs the person their access and nothing else, where silence
|
|
56
|
+
* would read as "could not find out" and stall the decision.
|
|
57
|
+
*/
|
|
58
|
+
export declare const sharedCensus: (note: string) => () => ContentCensus;
|
|
59
|
+
//# sourceMappingURL=contentCensus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentCensus.d.ts","sourceRoot":"","sources":["../src/contentCensus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AAE9D,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC7B,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb;4EACwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;6EACyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAUD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,EAAE,EAAE,QAAQ,EACZ,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7B,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,CAmCtC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,WAAS,aAA4C,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Bare identifiers only. A table name cannot be a bound parameter, so this is
|
|
2
|
+
* the gate that keeps one from being anything but a name. */
|
|
3
|
+
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
4
|
+
const tableExists = (db, table) => (db.query("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) ?? null) !==
|
|
5
|
+
null;
|
|
6
|
+
/**
|
|
7
|
+
* Build a `contentCensus` implementation from a list of tables.
|
|
8
|
+
*
|
|
9
|
+
* Counts only — the census is entitled to how MANY rows an account has, never
|
|
10
|
+
* to what they say. Pass it straight to `createSsoConsumer({ contentCensus })`.
|
|
11
|
+
*/
|
|
12
|
+
export function countingCensus(db, counters, options = {}) {
|
|
13
|
+
for (const counter of counters) {
|
|
14
|
+
// Thrown at CONSTRUCTION, not per request: a bad identifier is a typo in
|
|
15
|
+
// this app's own source, and it should stop the app from booting rather
|
|
16
|
+
// than surface as a mysterious 500 the first time the owner opens a
|
|
17
|
+
// confirmation dialog.
|
|
18
|
+
if (!IDENTIFIER.test(counter.table)) {
|
|
19
|
+
throw new Error(`census counter "${counter.kind}": ${counter.table} is not a table name`);
|
|
20
|
+
}
|
|
21
|
+
if (counter.column !== undefined && !IDENTIFIER.test(counter.column)) {
|
|
22
|
+
throw new Error(`census counter "${counter.kind}": ${counter.column} is not a column name`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return (userIds) => {
|
|
26
|
+
const users = [];
|
|
27
|
+
for (const userId of userIds) {
|
|
28
|
+
const items = [];
|
|
29
|
+
for (const counter of counters) {
|
|
30
|
+
if (!tableExists(db, counter.table))
|
|
31
|
+
continue;
|
|
32
|
+
const column = counter.column ?? "user_id";
|
|
33
|
+
const row = db
|
|
34
|
+
.query(`SELECT COUNT(*) AS n FROM ${counter.table} WHERE ${column} = ?${counter.where ? ` AND (${counter.where})` : ""}`)
|
|
35
|
+
.get(userId);
|
|
36
|
+
const count = typeof row?.n === "number" ? row.n : 0;
|
|
37
|
+
if (count > 0)
|
|
38
|
+
items.push({ kind: counter.kind, label: counter.label, count });
|
|
39
|
+
}
|
|
40
|
+
users.push({ userId, items, total: items.reduce((sum, item) => sum + item.count, 0) });
|
|
41
|
+
}
|
|
42
|
+
return { scope: "per-user", users, ...(options.note ? { note: options.note } : {}) };
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The answer for an app whose data belongs to NOBODY in particular — one shared
|
|
47
|
+
* corpus, library or tree.
|
|
48
|
+
*
|
|
49
|
+
* It is a real answer, not a shrug, and saying it explicitly is the whole point:
|
|
50
|
+
* "nothing here is attributed to an individual account" tells the owner that
|
|
51
|
+
* closing the app costs the person their access and nothing else, where silence
|
|
52
|
+
* would read as "could not find out" and stall the decision.
|
|
53
|
+
*/
|
|
54
|
+
export const sharedCensus = (note) => () => ({ scope: "shared", note });
|
|
55
|
+
//# sourceMappingURL=contentCensus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentCensus.js","sourceRoot":"","sources":["../src/contentCensus.ts"],"names":[],"mappings":"AAyCA;8DAC8D;AAC9D,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,MAAM,WAAW,GAAG,CAAC,EAAY,EAAE,KAAa,EAAW,EAAE,CAC5D,CAAC,EAAE,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAC9F,IAAI,CAAC;AAEN;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC7B,EAAY,EACZ,QAAkC,EAClC,UAA6B,EAAE;IAE/B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,yEAAyE;QACzE,wEAAwE;QACxE,oEAAoE;QACpE,uBAAuB;QACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,IAAI,MAAM,OAAO,CAAC,KAAK,sBAAsB,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,IAAI,MAAM,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC;QAC7F,CAAC;IACF,CAAC;IAED,OAAO,CAAC,OAA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AAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACtF,CAAC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAkB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cursedauth — the server half of "sign in through the accounts app".
|
|
3
|
+
*
|
|
4
|
+
* This barrel is SERVER-ONLY: it reaches `bun:sqlite` transitively, so a browser
|
|
5
|
+
* bundle that imports it pulls a database driver into the client graph. The
|
|
6
|
+
* browser halves have their own subpaths and no server import between them:
|
|
7
|
+
*
|
|
8
|
+
* cursedauth/auth React hooks + `startSsoSignIn`
|
|
9
|
+
* cursedauth/account-ui the account menu
|
|
10
|
+
* cursedauth/account-slot-client multi-account slot switching in the browser
|
|
11
|
+
*
|
|
12
|
+
* 🔴 What this package is NOT. It is the app's side of SSO — the consumer. It
|
|
13
|
+
* never holds a password, never mints a grant, and has no user table of its own
|
|
14
|
+
* beyond a local snapshot of whoever has signed in here. The identity provider
|
|
15
|
+
* is a separate service reached over HTTPS at `authUrl`; this package's only
|
|
16
|
+
* knowledge of it is that URL and its public key.
|
|
17
|
+
*/
|
|
18
|
+
export { createSsoConsumer, resolveSsoAudience, sanitizeReturnPath, SSO_CALLBACK_PATH, SSO_CENSUS_PATH, SSO_RETURN_COOKIE, SSO_REVOKE_PATH, SSO_SESSIONS_PATH, SSO_SIGNOUT_PATH, SSO_SLOT_COOKIE, SSO_START_PATH, type SsoConsumer, type SsoConsumerOptions, type SsoUser, } from "./ssoConsumer.server";
|
|
19
|
+
export { createUserSessionStore, type SessionRecord, type SignedIn, type SignInOptions, type SlotOccupant, type UserSessionStore, type UserSessionStoreOptions, } from "./userSessions";
|
|
20
|
+
export { DEFAULT_GATE_PATH, type GatedMountPlan, gatedMountReport, type Mounter, mountGatedApp, type SessionGate, } from "./mountGatedApp";
|
|
21
|
+
export { type CensusCounter, countingCensus, sharedCensus } from "./contentCensus";
|
|
22
|
+
export { LOCAL_AUTH_URL, STAGE_IDENTITY_ENV, stageIdentityIsLocal, } from "./stageIdentity";
|
|
23
|
+
export type { ContentCensus, ContentCensusUser } from "./sso";
|
|
24
|
+
export { getSessionClaims, SESSION_CLAIMS_KEY, type SessionClaims } from "./auth.server";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,OAAO,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,iBAAiB,EACjB,KAAK,cAAc,EACnB,gBAAgB,EAChB,KAAK,OAAO,EACZ,aAAa,EACb,KAAK,WAAW,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cursedauth — the server half of "sign in through the accounts app".
|
|
3
|
+
*
|
|
4
|
+
* This barrel is SERVER-ONLY: it reaches `bun:sqlite` transitively, so a browser
|
|
5
|
+
* bundle that imports it pulls a database driver into the client graph. The
|
|
6
|
+
* browser halves have their own subpaths and no server import between them:
|
|
7
|
+
*
|
|
8
|
+
* cursedauth/auth React hooks + `startSsoSignIn`
|
|
9
|
+
* cursedauth/account-ui the account menu
|
|
10
|
+
* cursedauth/account-slot-client multi-account slot switching in the browser
|
|
11
|
+
*
|
|
12
|
+
* 🔴 What this package is NOT. It is the app's side of SSO — the consumer. It
|
|
13
|
+
* never holds a password, never mints a grant, and has no user table of its own
|
|
14
|
+
* beyond a local snapshot of whoever has signed in here. The identity provider
|
|
15
|
+
* is a separate service reached over HTTPS at `authUrl`; this package's only
|
|
16
|
+
* knowledge of it is that URL and its public key.
|
|
17
|
+
*/
|
|
18
|
+
export { createSsoConsumer, resolveSsoAudience, sanitizeReturnPath, SSO_CALLBACK_PATH, SSO_CENSUS_PATH, SSO_RETURN_COOKIE, SSO_REVOKE_PATH, SSO_SESSIONS_PATH, SSO_SIGNOUT_PATH, SSO_SLOT_COOKIE, SSO_START_PATH, } from "./ssoConsumer.server";
|
|
19
|
+
export { createUserSessionStore, } from "./userSessions";
|
|
20
|
+
export { DEFAULT_GATE_PATH, gatedMountReport, mountGatedApp, } from "./mountGatedApp";
|
|
21
|
+
export { countingCensus, sharedCensus } from "./contentCensus";
|
|
22
|
+
export { LOCAL_AUTH_URL, STAGE_IDENTITY_ENV, stageIdentityIsLocal, } from "./stageIdentity";
|
|
23
|
+
export { getSessionClaims, SESSION_CLAIMS_KEY } from "./auth.server";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,GAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,sBAAsB,GAOtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,iBAAiB,EAEjB,gBAAgB,EAEhB,aAAa,GAEb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAsB,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAsB,MAAM,eAAe,CAAC"}
|