Files
CatoandClaude c83c8f473e feat(starter): kickoff and new-site.sh both produce the fleet starter (#1138)
scripts/site-template is now bitbaum/fleet templates/app — Next.js 16,
better-auth accounts (password, link, passkey, 2FA, OrangeCat/bitbaum sign-in
as env-gated OIDC), en/de/fr, nonce CSP, ai-kit/mail-kit/limitkit/bip-kit,
tests and CI — copied at a pinned fleet commit by
scripts/templates/sync-starter.sh. CI proves the copy is exact
(sync-starter.sh --check), and starter-sync.yml opens the PR when fleet's
starter moves. Never edited here.

The kickoff's "nextjs-tailwind" starter seeds the same app from
src/lib/starter-app.generated.ts (generated from the directory, pinned by
scripts/test/starter-app.ts), minus the workflows register-site.sh adds with
the site's CD. The repo is seeded in one Trees API call with inline contents
instead of a blob POST per file (~85 for this starter). The widget token rides
in .env.production; the starter's .gitleaks.toml allows NEXT_PUBLIC_* values.
The new-from-scratch picker reads the light template list, so the starter's
file bodies never reach a client bundle.

Both paths give the site its database and auth/seal secrets ON THE BOX
(scripts/hetzner/provision-db-on-box.sh: role + database, ~/.db-credentials,
/opt/<slug>/shared/.env; existing secrets never replaced; nothing printed), and
record the db in the register row so every deploy applies drizzle/.
register-site.sh seeds the starter's full workflow set to starter repos and
the golden CI floor to anything else, never overwriting another repo's ci.yml.

test-site-template.sh follows the starter (verify SSOT, design tokens instead
of a local palette) and its comment stripper is fixed: the sed range deleted
the page from the doc comment to EOF, so every day-zero check had been passing
against an empty string. check-template-contrast.mjs and the starter-lock
generator are retired with the files they checked.


Claude-Session: https://claude.ai/code/session_01W7K2Gm5wcbfCi7THtmV1Hy

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-11 13:39:14 -07:00

82 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { contentSecurityPolicy, newNonce, SECURITY_HEADERS } from "./security";
const directives = (csp: string) =>
new Map(
csp.split(";").map((part) => {
const [name, ...values] = part.trim().split(/\s+/);
return [name, values.join(" ")] as const;
}),
);
describe("contentSecurityPolicy", () => {
const nonce = newNonce();
const csp = directives(contentSecurityPolicy(nonce));
it("runs only scripts carrying this response's nonce", () => {
expect(csp.get("script-src")).toBe(`'self' 'nonce-${nonce}' 'strict-dynamic'`);
expect(csp.get("script-src")).not.toContain("unsafe-inline");
expect(csp.get("script-src")).not.toContain("unsafe-eval");
});
it("sends data only to this origin", () => {
expect(csp.get("connect-src")).toBe("'self'");
});
it("cannot be framed, embeds nothing, posts forms only here", () => {
expect(csp.get("frame-ancestors")).toBe("'none'");
expect(csp.get("frame-src")).toBe("'none'");
expect(csp.get("object-src")).toBe("'none'");
expect(csp.get("base-uri")).toBe("'self'");
expect(csp.get("form-action")).toBe("'self'");
expect(csp.get("default-src")).toBe("'self'");
});
it("opens only Loki, and only when the widget is on", () => {
const withWidget = directives(contentSecurityPolicy(nonce, { widget: true }));
expect(withWidget.get("connect-src")).toBe("'self' https://loki.orangecat.ch");
expect(withWidget.get("frame-src")).toBe("https://loki.orangecat.ch");
});
it("allows eval only in development", () => {
const dev = directives(contentSecurityPolicy(nonce, { dev: true }));
expect(dev.get("script-src")).toContain("'unsafe-eval'");
});
it("refuses a nonce that could break out of the header", () => {
expect(() => contentSecurityPolicy("abc'; script-src *")).toThrow();
expect(() => contentSecurityPolicy("")).toThrow();
});
});
describe("newNonce", () => {
it("is fresh every time", () => {
const seen = new Set(Array.from({ length: 50 }, newNonce));
expect(seen.size).toBe(50);
});
});
describe("SECURITY_HEADERS", () => {
const headers = new Map(SECURITY_HEADERS.map(({ key, value }) => [key.toLowerCase(), value]));
it("pins HTTPS for two years", () => {
expect(headers.get("strict-transport-security")).toMatch(/max-age=63072000/);
expect(headers.get("strict-transport-security")).toMatch(/includeSubDomains/);
});
it("sends no referrer and refuses framing and sniffing", () => {
expect(headers.get("referrer-policy")).toBe("no-referrer");
expect(headers.get("x-frame-options")).toBe("DENY");
expect(headers.get("x-content-type-options")).toBe("nosniff");
});
it("switches off camera, microphone, location and payment", () => {
const policy = headers.get("permissions-policy") ?? "";
for (const feature of ["camera", "microphone", "geolocation", "payment"]) {
expect(policy).toContain(`${feature}=()`);
}
// Passkeys must keep working.
expect(policy).not.toContain("publickey-credentials");
});
});