Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
with:
node-version: 26
cache: npm
- run: npm ci --prefer-offline --no-audit --no-fund
- run: npm ci --ignore-scripts --prefer-offline --no-audit --no-fund
- run: npm run check
6 changes: 3 additions & 3 deletions scripts/render-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ if (example) {
Object.assign(env, process.env);
if (existsSync(".env.deploy")) {
for (const line of readFileSync(".env.deploy", "utf8").split("\n")) {
const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/);
if (m && !(m[1] in process.env)) env[m[1]] = m[2].replace(/^["']|["']$/g, "");
const m = /^\s*([A-Z0-9_]+)\s*=(.*)$/s.exec(line);
if (m && !(m[1] in process.env)) env[m[1]] = m[2].trim().replace(/^["']|["']$/g, "");
}
}
}
Expand All @@ -53,7 +53,7 @@ const json = (v) => JSON.stringify(v ?? "").slice(1, -1);
let config = readFileSync("wrangler.jsonc", "utf8");
for (const k of Object.keys(REQUIRED)) config = config.replaceAll(`<${k}>`, json(env[k]));
config = config.replace(/<([A-Z0-9_]+)\?>/g, (_m, k) => json(env[k]));
const left = config.replace(/^\s*\/\/.*$/gm, "").match(/<[A-Z0-9_]+\??>/);
const left = config.replace(/^[ \t]*\/\/.*$/gm, "").match(/<[A-Z0-9_]+\??>/);
if (left) {
console.error(`Unfilled placeholder ${left[0]} in wrangler.jsonc`);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function signInEvent(ctx: Ctx, now = Date.now()): [string, Props] | null
const method = SIGN_IN_METHODS[ctx.path];
const user = ctx.context.newSession?.user;
if (!method || !user) return null;
const created = user.createdAt ? new Date(user.createdAt).getTime() : NaN;
const created = user.createdAt ? new Date(user.createdAt).getTime() : Number.NaN;
return ["signed_in", { method, first_sign_in: Number.isFinite(created) && now - created < FIRST_SIGN_IN_MS }];
}

Expand All @@ -71,7 +71,7 @@ export const usageEvents = (env: Env, exec: Exec) =>
const c = ctx as unknown as Ctx;
if (failed(c.context.returned)) return;
const ev = Object.hasOwn(SIGN_IN_METHODS, c.path) ? signInEvent(c) : EVENTS[c.path](c);
if (ev) phCapture(env, exec, ev[0], ev[1]);
if (ev) void phCapture(env, exec, ev[0], ev[1]);
} catch (e) {
console.error("[stem] usage event failed", e);
}
Expand Down
18 changes: 9 additions & 9 deletions src/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function signIn() {
ev.preventDefault();
const form = ev.currentTarget as HTMLFormElement;
const btn = form.querySelector<HTMLButtonElement>("button[type=submit]");
busy(btn, async () => {
void busy(btn, async () => {
fail(null);
email = ($<HTMLInputElement>("email")?.value || "").trim().toLowerCase();
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) { fail("That doesn't look like an email address."); return; }
Expand All @@ -217,7 +217,7 @@ function signIn() {
codeForm?.addEventListener("submit", (ev) => {
ev.preventDefault();
const btn = codeForm.querySelector<HTMLButtonElement>("button[type=submit]");
busy(btn, async () => {
void busy(btn, async () => {
fail(null);
const otp = ($<HTMLInputElement>("otp")?.value || "").replace(/\D/g, "");
if (otp.length !== 6) { fail("The code has six digits."); return; }
Expand All @@ -237,7 +237,7 @@ function signIn() {
nameForm?.addEventListener("submit", (ev) => {
ev.preventDefault();
const btn = nameForm.querySelector<HTMLButtonElement>("button[type=submit]");
busy(btn, async () => {
void busy(btn, async () => {
fail(null);
const name = ($<HTMLInputElement>("name")?.value || "").trim();
if (name.length < 1) { fail("Tell us a name, even a short one."); return; }
Expand Down Expand Up @@ -300,7 +300,7 @@ async function account() {
$<HTMLFormElement>("profile-form")?.addEventListener("submit", (ev) => {
ev.preventDefault();
const btn = (ev.currentTarget as HTMLFormElement).querySelector<HTMLButtonElement>("button");
busy(btn, async () => {
void busy(btn, async () => {
fail(null);
const name = (nameInput?.value || "").trim().slice(0, 80);
if (!name) { fail("Tell us a name, even a short one."); return; }
Expand All @@ -324,7 +324,7 @@ async function account() {
const r = await client.passkey.deletePasskey({ id: pk.id });
if (r.error) { fail(explain(r.error as ApiError)); return; }
if (pk.credentialID) await forgetCredential(pk.credentialID);
loadPasskeys();
void loadPasskeys();
},
}));
}
Expand All @@ -334,7 +334,7 @@ async function account() {
fail(null);
const res = await client.passkey.addPasskey({ name: deviceName() });
if (res?.error && !/cancel|abort|NotAllowed/i.test(res.error.message || "")) fail(explain(res.error as ApiError));
loadPasskeys();
void loadPasskeys();
}));

async function loadSessions() {
Expand All @@ -347,7 +347,7 @@ async function account() {
const current = x.id === session.id;
ul.append(li(`${browserOf(x.userAgent)}${current ? " (this one)" : ""}`, `Since ${fmt(x.createdAt)}${x.ipAddress ? ` · ${x.ipAddress}` : ""}`, current ? undefined : {
label: "End",
run: async () => { const r = await client.revokeSession({ token: x.token }); if (r.error) fail(explain(r.error as ApiError)); else loadSessions(); },
run: async () => { const r = await client.revokeSession({ token: x.token }); if (r.error) fail(explain(r.error as ApiError)); else void loadSessions(); },
}));
}
}
Expand Down Expand Up @@ -383,14 +383,14 @@ async function account() {
run: async () => {
if (!confirm(`Remove ${a.name}'s access? It can't use your account anymore until you sign in to it again.`)) return;
const r = await client.$fetch("/stem/apps/remove", { method: "POST", body: { client_id: a.client_id } });
if (r.error) fail(explain(r.error as ApiError)); else loadApps();
if (r.error) fail(explain(r.error as ApiError)); else void loadApps();
},
}));
}

$("revoke-others")?.addEventListener("click", async () => {
const r = await client.revokeOtherSessions();
if (r.error) fail(explain(r.error as ApiError)); else loadSessions();
if (r.error) fail(explain(r.error as ApiError)); else void loadSessions();
});
$("sign-out")?.addEventListener("click", async () => { await client.signOut(); location.assign("/"); });
$("delete-account")?.addEventListener("click", async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/client/mandates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function challengeOf(core: unknown) {
const d = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canon(core))));
let s = "";
for (const x of d) s += String.fromCharCode(x);
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
}

export function approveMandate(h: Helpers) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function loadAgents(h: Helpers) {
run: async () => {
if (!confirm(`Stop "${a.purpose}"? It and every helper it started lose access on their next request.`)) return;
const r = await h.$fetch("/mandates/revoke", { method: "POST", body: { id: a.id } });
if (r.error) h.fail(r.error.message || "That didn't work."); else loadAgents(h);
if (r.error) h.fail(r.error.message || "That didn't work."); else void loadAgents(h);
},
} : undefined);
const more = document.createElement("button");
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const routeOf = (p: string) => p.replace(/\/[0-9a-f-]{36}(?=\/|$)/gi, "/:id").re
app.notFound((c) => html(messagePage(ui(c.env), "Not here", "This page doesn't exist. Maybe the link is old or has a typo."), 404));
app.onError((e, c) => {
console.error("[stem] unhandled", e);
phException(c.env, c.executionCtx as never, e, { path: routeOf(c.req.path) });
void phException(c.env, c.executionCtx as never, e, { path: routeOf(c.req.path) });
return c.req.path.startsWith("/api/") ? c.json({ error: "server_error" }, 500) : html(messagePage(ui(c.env), "Something broke", "That's on us. Try again in a moment.", "error"), 500);
});

Expand Down
2 changes: 1 addition & 1 deletion src/mandates/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const te = new TextEncoder();
export const b64u = (b: Uint8Array) => {
let s = "";
for (const x of b) s += String.fromCharCode(x);
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
};
export const unb64u = (s: string) => Uint8Array.from(atob(s.replace(/-/g, "+").replace(/_/g, "/")), (c) => c.charCodeAt(0));
export const sha256 = async (d: Uint8Array | string) => new Uint8Array(await crypto.subtle.digest("SHA-256", typeof d === "string" ? te.encode(d) : d));
Expand Down
4 changes: 2 additions & 2 deletions src/passes/rsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export const b64u = (b: Uint8Array) => {
let s = "";
for (let i = 0; i < b.length; i += 0x8000) s += String.fromCharCode(...b.subarray(i, i + 0x8000));
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
};
export const unb64u = (s: string) => {
if (!/^[A-Za-z0-9_-]*$/.test(s)) throw new Error("not base64url");
Expand All @@ -21,7 +21,7 @@ export const intToBytes = (n: bigint, len: number) => {
const hex = n.toString(16).padStart(len * 2, "0");
if (hex.length > len * 2) throw new Error("integer too large");
const out = new Uint8Array(len);
for (let i = 0; i < len; i++) out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
for (let i = 0; i < len; i++) out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
return out;
};
export function modPow(base: bigint, exp: bigint, mod: bigint): bigint {
Expand Down
2 changes: 1 addition & 1 deletion src/sealed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function clientIdOf(query: unknown, body: unknown, headers: Headers | undefined)
const b = body as { client_id?: unknown } | undefined;
if (typeof q?.client_id === "string" && q.client_id) return q.client_id;
if (typeof b?.client_id === "string" && b.client_id) return b.client_id;
const basic = /^Basic\s+(.+)$/i.exec(headers?.get("authorization") || "");
const basic = /^Basic\s+(\S.*)$/i.exec(headers?.get("authorization") || "");
if (!basic) return null;
try {
const raw = atob(basic[1].trim());
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function invitePage(ui: Ui, inv: { id: string; orgName: string; email: st
<div>
<span class="label">invitation</span>
<h1 style="margin-top:14px">Join ${esc(inv.orgName)}<em>.</em></h1>
<p class="lead">${inv.inviter ? `${esc(inv.inviter)} invited` : "You've been invited with"} <strong>${esc(inv.email)}</strong>${inv.inviter ? "" : ""}.</p>
<p class="lead">${inv.inviter ? `${esc(inv.inviter)} invited` : "You've been invited with"} <strong>${esc(inv.email)}</strong>.</p>
</div>
<div class="panel stack">
<p style="margin:0" id="invite-hint">Sign in with that address to accept. If you don't have an account yet, signing in creates one.</p>
Expand Down