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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Use short, imperative subjects ("Add invitation expiry option"), with a body whe

Use the issue templates. For security problems, follow [SECURITY.md](SECURITY.md) instead of opening a public issue.

By contributing, you agree that your contributions are licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).
By contributing, you agree that your contributions are licensed under the MIT License.
256 changes: 21 additions & 235 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Multi-tenant auth for small apps. OIDC, passkeys and email codes, running on Cloudflare Workers.

**Live:** [stem.shiftbloom.studio](https://stem.shiftbloom.studio) · **License:** AGPL-3.0-or-later
**Live:** [stem.shiftbloom.studio](https://stem.shiftbloom.studio) · **License:** MIT

stem is the sign-in behind shiftbloom studio's apps. You make one account, and every app that uses stem lets you in with it. There are no passwords: you sign in with a passkey, or with a six-digit code we email you.

Expand Down Expand Up @@ -112,7 +112,7 @@ Deploy settings (`.env.deploy`, or build variables in Workers Builds):

Set `LEGAL` (operator details as JSON, see the comment in `wrangler.jsonc`) as a variable in the Cloudflare dashboard. It fills `/privacy`, `/datenschutz`, `/imprint` and `/impressum`; without it those pages are hidden. `keep_vars` keeps it across deploys.

If you fork, point `SOURCE_URL` in `src/ui/layout.ts` at your repository (AGPL-3.0 section 13).
If you fork, point `SOURCE_URL` in `src/ui/layout.ts` at your repository (footer source link).

Register an app and create its first team with the operator API, as shown in [docs/integration.md](docs/integration.md).

Expand Down Expand Up @@ -155,7 +155,7 @@ Please don't report vulnerabilities in public issues. Use GitHub's private vulne

Copyright © 2026 shiftbloom studio and contributors.

stem is free software: you can redistribute it and/or modify it under the terms of the [GNU Affero General Public License](LICENSE) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version (`AGPL-3.0-or-later`). If you run a modified version for others over a network, offer them its source and point `SOURCE_URL` at your fork.
stem is free software: you can redistribute it and/or modify it under the terms of the [MIT License](LICENSE). If you run a modified version for others over a network, offer them its source and point `SOURCE_URL` at your fork.

---

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Sign-in for shiftbloom studio apps: passkeys, email codes, organizations and OpenID Connect on Cloudflare Workers",
"private": true,
"type": "module",
"license": "AGPL-3.0-or-later",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/shiftbloom-studio/stem.git"
Expand Down
2 changes: 1 addition & 1 deletion scripts/render-config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Fills the <PLACEHOLDERS> in wrangler.jsonc from environment variables (or a local .env.deploy file)
// and writes wrangler.deploy.jsonc, which `npm run deploy` uses. Keeps installation-specific values
// (hostname, database id, sender, keys) out of the repository.
Expand Down
2 changes: 1 addition & 1 deletion scripts/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Prints the SQL that creates stem's tables, generated from the Better Auth config.
// Run with `npm run db:schema > migrations/000N_name.sql` after changing plugins or fields,
// against a database that already has the earlier migrations (see test/schema.test.ts).
Expand Down
2 changes: 1 addition & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// What a signed-in person can do with their own data, besides what Better Auth already offers:
// download all of it (GDPR Art. 15 and 20), and see and remove the apps that can act for them.
import type { BetterAuthPlugin } from "better-auth";
Expand Down
2 changes: 1 addition & 1 deletion src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Anonymous usage counts for PostHog (src/posthog.ts): which sign-in steps succeed, how people sign in, and
// which apps they sign in to. Off unless POSTHOG_KEY is set. Events carry no user id, email address, name,
// IP address, code or token, and every event gets a fresh random distinct_id, so none can be tied to a person.
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Two server-to-server APIs:
// - /api/v1/operator/*: the person running stem sets up apps, OAuth clients and organizations (OPERATOR_TOKEN).
// - /api/v1/*: an app manages its own organizations, members and invitations with a client-credentials
Expand Down
2 changes: 1 addition & 1 deletion src/assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
/** Font proxy: visitors only ever talk to stem's own origin, never to Fontshare or jsDelivr. */
const FONT_CSS = "https://api.fontshare.com/v2/css?f[]=clash-display@500,600&f[]=general-sans@400,500,600&display=swap";
const MONO = (w: number) => `https://cdn.jsdelivr.net/npm/@fontsource/jetbrains-mono@5/files/jetbrains-mono-latin-${w}-normal.woff2`;
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// The Better Auth instance behind stem. One instance per isolate and environment.
import { betterAuth } from "better-auth";
import { usageEvents } from "./analytics";
Expand Down
2 changes: 1 addition & 1 deletion src/bloom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// The shiftbloom bloom, exactly as shiftbloom.studio draws it (brand book v2, "The Mark").
// viewBox 0 0 200 200, four interleaved petal rings + seed. Gradient only inside the mark.
// Sizes >= 32px use the gradient; below that (favicons) use the solid variant.
Expand Down
2 changes: 1 addition & 1 deletion src/claims.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

/** Most organizations one token lists. Apps with more need the directory API. */
export const MAX_ORGS_IN_TOKEN = 50;
Expand Down
2 changes: 1 addition & 1 deletion src/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Daily cleanup (cron trigger): personal data that has done its job is deleted instead of piling up in D1.
// The periods here are the ones the privacy policy promises; change both together.

Expand Down
2 changes: 1 addition & 1 deletion src/client/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Browser code for stem's pages. Bundled to /assets/app.js; no inline scripts anywhere (strict CSP).
import { createAuthClient } from "better-auth/client";
import { emailOTPClient, organizationClient } from "better-auth/client/plugins";
Expand Down
2 changes: 1 addition & 1 deletion src/client/mandates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Browser side of mandates: the approval page and "Your agents" on the account page.
import { startAuthentication } from "@simplewebauthn/browser";

Expand Down
2 changes: 1 addition & 1 deletion src/email.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
import type { Env } from "./env";
import { esc } from "./ui/html";

Expand Down
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

import type { PostHogEnv } from "./posthog";

Expand Down
2 changes: 1 addition & 1 deletion src/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// App gateway: a named Workers entrypoint for app Workers on the same Cloudflare account.
//
// An app binds to it with a service binding that names the entrypoint and its app in `props`:
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// stem: passwordless sign-in, organizations and OpenID Connect for shiftbloom studio apps.
import { Hono } from "hono";
import { oauthProviderOpenIdConfigMetadata, oauthProviderAuthServerMetadata } from "@better-auth/oauth-provider";
Expand Down
2 changes: 1 addition & 1 deletion src/limits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Per-address limits for email codes. Per-IP limits alone don't stop someone who rotates IPs:
// every fresh code would bring five more guesses. These counters follow the address instead.
import type { BetterAuthPlugin } from "better-auth";
Expand Down
2 changes: 1 addition & 1 deletion src/mandates/authorize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// One call that answers "may this request go ahead?" for apps: the offline chain check (./verify.ts),
// the call against the rights at the end of the chain, then the live check in the mandate's object.
// Apps on the same Cloudflare account call it over a service binding (MandateGateway); others over
Expand Down
2 changes: 1 addition & 1 deletion src/mandates/object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// The live half of a mandate: one Durable Object per root mandate, shared by every token derived from
// it. It holds what a signature can't: the stop button, the expiry, a budget all branches share, a
// replay check for proofs of possession, and a hash-chained trail of every call.
Expand Down
2 changes: 1 addition & 1 deletion src/mandates/page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// The approval page: the terms in plain words, then the passkey prompt. The passkey signs the hash of
// exactly what the page's script fetched from /api/auth/mandates/prepare, and stem only countersigns
// that, so what is shown here and what is signed come from the same stored request.
Expand Down
2 changes: 1 addition & 1 deletion src/mandates/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// mandates(): a power of attorney the person's passkey signs. An agent asks for exact rights, the
// person reads them on stem's approval page and signs with a passkey (the WebAuthn challenge is the
// hash of the mandate), stem checks that signature and countersigns. See docs/mandates.md.
Expand Down
2 changes: 1 addition & 1 deletion src/mandates/verify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Mandates: what an app runs to check one. Needs stem's public keys (its JWKS) and nothing else:
// no database, no call to stem. Self-contained on purpose (jose and WebCrypto only), so an app can
// copy this file. The live half (stop button, shared budget, replay check) is in ./object.ts.
Expand Down
2 changes: 1 addition & 1 deletion src/passes/issuer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Passes: stem as a Privacy Pass issuer (RFC 9576/9577/9578, token type 2, publicly verifiable blind RSA).
//
// A signed-in browser asks stem for a batch of passes. It blinds each token request first, so stem signs
Expand Down
2 changes: 1 addition & 1 deletion src/passes/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// HTTP side of passes (see ./issuer.ts):
// GET /.well-known/private-token-issuer-directory public keys (RFC 9578, section 4), for apps
// POST /api/passes/issue blinded requests in, blind signatures out, for browsers
Expand Down
2 changes: 1 addition & 1 deletion src/passes/rsa.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// The RSA pieces of Privacy Pass issuance (RFC 9578, token type 2, blind RSA per RFC 9474):
// key encoding, the blind signature itself and its check. No dependencies: WebCrypto and BigInt.

Expand Down
2 changes: 1 addition & 1 deletion src/passkey-notice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// An email whenever a passkey is added to an account. A passkey is a full way in, so someone who got hold
// of a session (or of the mailbox, through a code) could add their own and come back later. The notice
// tells the person in time to remove it. Off unless NOTIFY_NEW_PASSKEY is "true".
Expand Down
2 changes: 1 addition & 1 deletion src/roles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
import { createAccessControl } from "better-auth/plugins/access";
import { defaultStatements, ownerAc, adminAc, memberAc } from "better-auth/plugins/organization/access";

Expand Down
2 changes: 1 addition & 1 deletion src/sealed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Sealed apps (docs/sealed-apps.md): apps that sign people in through stem without learning who they are
// elsewhere. Each sealed app gets its own `sub` for a person (OpenID Connect pairwise identifiers), never
// gets the email address, and can't read people through the directory API. While sealed apps are on,
Expand Down
2 changes: 1 addition & 1 deletion src/strength.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// How strongly someone signed in, and how apps learn about it.
// Each session remembers its sign-in method; tokens carry it as `auth_method`, so an app can ask
// for a fresh passkey (prompt=login or max_age) before an admin action and check what happened.
Expand Down
2 changes: 1 addition & 1 deletion src/ui/html.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
export const esc = (s: unknown) =>
String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]!);
6 changes: 3 additions & 3 deletions src/ui/layout.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// stem's pages follow the shiftbloom studio brand book v2: paper and ink, one loud flower.
// Paper is a soft warm off-white rather than pure white, which is easier on bright screens.
// Bloom Red for actions and seeds, gradients only inside the mark. Clash Display for statements,
// General Sans for UI and body, JetBrains Mono for labels and codes.
import { bloomSvg } from "../bloom";
import { esc } from "./html";

/** AGPL §13: people using stem over a network are offered the source. Forks: point this at your repo. */
/** Source link: people using stem over a network are offered the source. Forks: point this at your repo. */
export const SOURCE_URL = "https://github.com/shiftbloom-studio/stem";

const css = `
Expand Down Expand Up @@ -87,7 +87,7 @@ export function topbar(right = "") {

export function footer(lang: "en" | "de", legal: boolean) {
const links = legal ? (lang === "de" ? ` · <a href="/datenschutz">Datenschutz</a> · <a href="/impressum">Impressum</a>` : ` · <a href="/privacy">Privacy</a> · <a href="/imprint">Imprint</a>`) : "";
return `<footer class="foot"><p>${lang === "de" ? "stem ist Open Source unter AGPL-3.0." : "stem is open source under AGPL-3.0."} <a href="${SOURCE_URL}">${lang === "de" ? "Zum Code" : "Read the code"}</a>${links}</p><p>${STUDIO}</p></footer>`;
return `<footer class="foot"><p>${lang === "de" ? "stem ist Open Source unter der MIT-Lizenz." : "stem is open source under the MIT License."} <a href="${SOURCE_URL}">${lang === "de" ? "Zum Code" : "Read the code"}</a>${links}</p><p>${STUDIO}</p></footer>`;
}

export function page(o: PageOpts, body: string, right = "") {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/legal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// Imprint and privacy policy, in English and German. Operator details come from the LEGAL variable.
import type { Legal } from "../util";
import { esc } from "./html";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
import { bloomSvg } from "../bloom";
import { esc } from "./html";
import { page, SOURCE_URL } from "./layout";
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

export function timingSafeEqual(a: string, b: string) {
const ea = new TextEncoder().encode(a), eb = new TextEncoder().encode(b);
Expand Down
2 changes: 1 addition & 1 deletion test/clearance.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
import { describe, it, expect } from "vitest";
import { accountPage, signInPage } from "../src/ui/pages";

Expand Down
2 changes: 1 addition & 1 deletion tools/mandate-agent.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT
// A small helper for agent sessions: ask stem for a mandate, wait for the person to approve it, hand
// narrower copies to sub-agents (offline) and sign each request. Node 26+, needs only `jose`.
// Also usable as a module (import { requestMandate, derive, proof, headers } from "./mandate-agent.mjs").
Expand Down