A Capture-the-Flag platform built to look like a robotics company's corporate site. Players sign up, get a robotics project, and recover flags from the site itself — its source, its endpoints, its auth and its admin surface. 22 active challenges live as rows in Supabase; the vulnerabilities they exploit are deliberate parts of the product.
CTF_README.md is the challenge inventory — every flag, its
location, and its solve path. CLAUDE.md is the working agreement for
anyone (human or agent) changing code here. Read both before touching auth, admin
routes, middleware.ts or the signup response.
| Framework | Next.js 16.3 (App Router), React 19.1 |
| Language | TypeScript 5.9 — pinned, see docs/decisions.md |
| Styling | Tailwind CSS 3.4 + PostCSS, theme tokens as CSS variables |
| Backend | Supabase (Postgres, Auth, RLS, Realtime) via @supabase/ssr |
| Validation | Zod 4 |
| Unit / component tests | Jest 30 (jsdom) |
| Browser tests | Playwright 1.62 — one mocked suite, one against a real database |
| Linting | oxlint + ESLint 9, both run by npm run lint |
| Node | 22.x (engines, .nvmrc, CI all pinned); npm >= 10 |
middleware.ts at the repo root still exports middleware, not the Next 16 proxy
name. next.config.mjs strips console.* from production builds except error and
warn — a value a player must see belongs in the HTTP response, not a log line.
git clone <repo-url> && cd CTF
npm installFrontend work needs nothing else. npm run dev:offline runs the whole app with no
credentials, no .env.local and no database — skip to Run it. typecheck,
test and build also pass on a bare clone. The two sections below are only for work
that talks to a real Supabase.
Copy .env.local.example to .env.local and fill it in. The variables that matter:
| Variable | Required | What it does |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL |
yes | Supabase project URL |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
yes | Browser-side Supabase key |
SUPABASE_SERVICE_ROLE_KEY |
yes | Server-only; RLS-bypassing client |
NEXTAUTH_SECRET |
yes | HMAC key for the signed enumeration-challenge cookie |
NEXT_PUBLIC_SITE_URL |
prod | First choice for password-reset redirect URLs |
NEXTAUTH_URL |
no | Used for redirects only when it is not localhost |
NEXT_PUBLIC_THEME |
no | robotics (default) or starfall |
CHALLENGE_CUTOFF_DATE |
no | Scoring cutoff read by /api/cutoff-date |
NEXT_PUBLIC_ENABLE_COOKIE_CONSENT |
no | true turns on the cookie banner |
NEXT_PUBLIC_FABRILE_AGENT_ID, NEXT_PUBLIC_FABRILE_WEB_TOKEN |
no | Embedded chat agent |
Password-reset emails resolve their redirect base in this order:
NEXT_PUBLIC_SITE_URL → VERCEL_URL → NEXTAUTH_URL (ignored if it points at
localhost) → http://localhost:3000.
The hosted Supabase project is the source of truth; everything under supabase/ is a
copy pulled from it. Apply supabase/migrations/ — not supabase/schema.sql,
which is superseded and carries a bad foreign key. supabase/seed.sql holds the
challenge rows. docs/README.md has the full procedure, including how to refresh
each copy and how to take a backup (the free plan has none).
npm run dev # http://localhost:3000, needs a real Supabase
npm run dev:offline # http://localhost:3001, needs nothing at alldev:offline boots the app already signed in, with the real challenge list parsed out
of supabase/seed.sql and no database anywhere. Reads are faked, writes still hit the
real route and fail. UNLOCK=1 reveals the four progress-gated challenges. Full
details and its caveats: docs/how-to-run-offline.md. It needs Node >= 22.18.
One env var picks the theme a build renders:
NEXT_PUBLIC_THEME=starfall npm run dev # needs a real Supabase
NEXT_PUBLIC_THEME=starfall UNLOCK=1 npm run dev:offline # needs nothingThere is no runtime switch — the variable is read at render time, so changing it means
restarting the server. Production renders robotics, so that is the skin a change
has to survive unless you are told otherwise.
robotics is the default corporate-robotics skin. starfall is the Star Wars-flavoured
skin for Operation Starfall — Imperial in dark mode, Rebel in light. For starfall the two
modes are not a palette swap, they are two factions with separate copy
(starfall/strings.ts for dark, starfall/strings.light.ts for light), so a starfall
change has to be checked in both. Robotics has one strings.ts covering both modes.
Light and dark come from the nav toggle, which writes localStorage['theme']; with
nothing stored, starfall opens dark and robotics opens light.
A theme bundles colour tokens, shape, fonts, copy and art. lib/themes/ holds the
registry and the implementations; npm run theme:css generates
app/theme-tokens.generated.css from each theme's tokens.ts and shape.ts, so the
CSS variables are no longer hand-synced and CI fails if the generated file drifts.
docs/theming.md is the guide for adding or tuning a theme;
docs/design-system.md is the design contract for anything a
player sees, and is what to read before writing UI.
Three suites. They barely overlap, and only the last one talks to a database.
npm test # Jest — unit and component
npm run test:watch
npm test -- --coverage
npm run test:e2e # Playwright, fully mocked
npm run test:e2e:integration # Playwright against a live SupabaseJest (__tests__/) covers validation, security headers, permissions, rate
limiting, the CTF traps and the React contexts. It mocks global.fetch, so no
Supabase query ever runs — a route can be rewritten and stay green. Coverage is in
the single digits, and collectCoverageFrom is app/** only, so nothing under
lib/ is measured at all. Treat a green run as weak evidence.
Playwright e2e/ is mocked despite the directory name. Every spec intercepts its
own calls with page.route, and NEXT_PUBLIC_SUPABASE_URL points at a local JWKS stub
so middleware.ts can verify the fixture session offline. It runs with the database
stopped and in CI, and it proves UI wiring only. There are no pixel baselines any more:
the 25 that used to live in 06-visual-baseline and 07-assembly-baseline only ever
passed on the machine that captured them, and were deleted with the robotics redesign.
What replaced them are two screenshot tours that assert nothing and exist to be looked
at — ROBOTICS_TOUR=1 npx playwright test e2e/12-robotics-tour.spec.ts and
STARFALL_TOUR=1 npx playwright test e2e/10-starfall-tour.spec.ts, both writing PNGs
into test-results/.
Playwright e2e-integration/ runs a dev server on the real .env.local
credentials, so it needs a local Supabase up and it writes to whatever database
.env.local points at. Never point it at production. flags.spec.ts submits every
enabled lib/flag-registry.ts value to /api/challenges/submit and asserts the matching
row's points come back — the only check that a flag actually solves — and asserts the
reverse, that no active row is missing from the registry. It also guards the admin
promotion in both directions. Not in CI, which has no Supabase.
Type checking is a separate step and is not optional: npm run typecheck runs
next typegen first because next-env.d.ts is gitignored, and a bare tsc --noEmit
fails on a fresh checkout without it.
Every script in package.json:
| Script | What it does |
|---|---|
npm run dev |
Next dev server on :3000 |
npm run dev:turbo |
Same, forcing --turbo |
npm run dev:offline |
Database-free stack on :3001 (e2e/stub/fixture-proxy.mjs) |
npm run build |
Production build (Turbopack; prints no bundle sizes) |
npm run build:analyze |
Build with webpack-bundle-analyzer |
npm start |
Serve a production build |
npm run lint |
lint:fast then lint:deep |
npm run lint:fast |
oxlint, ~1.5s, --max-warnings 21 |
npm run lint:deep |
ESLint, ~11s, --max-warnings 30 |
npm run typecheck |
next typegen && tsc --noEmit |
npm test / npm run test:watch |
Jest |
npm run test:e2e |
Mocked Playwright suite |
npm run test:e2e:integration |
Real-database Playwright suite |
npm run perf:dev |
Dev server with NODE_ENV=development |
npm run perf:monitor |
scripts/performance-monitor.js |
Both linters carry a --max-warnings ratchet so new warnings fail CI. Lower the
numbers as warnings get fixed; never raise them, and never set them to the exact
current count. Why there are two linters at all: docs/decisions.md.
The gate for any code change is all four of
npm run typecheck && npm run lint && npm test && npm run build.
Pages: /, /about, /projects, /assembly-line, /team, /display, /login,
/signup, /forgot-password, /reset-password, /privacy.
Plus these, which exist for the CTF and must stay reachable and exploitable:
| Route | Why it exists |
|---|---|
/robots.txt |
Hints and disallowed paths |
/sitemap.xml |
Base64-encoded challenge |
/security.txt |
ROT13-encoded flag in a PGP block |
/intranet |
Portal index whose config comment hints at the handle below |
/intranet/kilroy |
Hidden internal page |
/admin-terminal?access=alex_was_here |
XSS-vulnerable admin terminal |
/api/admin/graphql |
Deliberately over-permissive admin endpoint |
The two long URLs are the solutions, not the starting points. What the
challenge cards link to (challenges.file_url) is /intranet and
/admin-terminal; the query parameter and the handle are hinted at in
app/security.txt/route.ts, app/intranet/page.tsx and robots.txt, never
spelled out. Do not put either full URL back into a challenge row.
Four data-fragment elements carry a hex flag (app/page.tsx twice, app/about/page.tsx,
app/projects/page.tsx). One of them renders as visible stray text on the homepage on
purpose. Never delete or reword one.
Every flag value is written in lib/flag-registry.ts and nowhere else; the client-side
artifacts are generated from it by npm run flags:plant, and /api/challenges/submit
compares against it rather than against challenges.flag. That column is readable by any
signed-in player, which is deliberate and is itself a challenge. docs/flag-rotation.md
covers rotating, disabling, and what is verified.
API routes live under app/api/; CTF_README.md documents the ones players touch and
docs/data-access.md documents the three that bypass RLS.
dev— super admin. Full access, challenge management, real-time notifications.admin— a player who solved the final challenge. AI activation and a read-only project switch, nothing more.user— a CTF participant.
Authorization is enforced server-side in @/lib/auth/permissions. Frontend permission
checks are decorative and bypassable by design — that bypass is a challenge.
The promotion to admin lives in app/api/challenges/submit/route.ts, keyed on the
challenge id in lib/challenge-ids.ts. It used to live in a Postgres trigger keyed
on the challenge's title; the row was renamed and the whole admin tier died silently
with no test failing. Behaviour hides in triggers here — grep the migration before
concluding no code does something.
Start at the file that answers your question.
| File | Read it when |
|---|---|
CTF_README.md |
You need a flag, its location, or its solve path. The challenge inventory and answer key. |
CLAUDE.md |
Before changing any code. Toolchain quirks, the definition of done, and what must not be "fixed". |
| File | Read it when |
|---|---|
docs/flag-rotation.md |
You are cycling flags for an event, disabling a challenge, or wondering why the database no longer holds the answers. |
docs/supabase-advisors.md |
You are about to run SQL against the live database. What the Supabase linter flags, which of it is real, which of it is a challenge, and how to connect by hand. |
docs/archive/supabase-runbook-2026-08-18.md |
Archived. The five migrations applied on 2026-08-18, with the verification queries and the reasoning about run order. History, not a queue. |
docs/README.md |
Anything touches supabase/. Which file is authoritative, how to refresh it, how to back up, the table and trigger summary. |
docs/data-access.md |
You are reviewing a route that uses createServiceRoleClient(). Covers the three that bypass RLS, including the deliberate IDOR. |
docs/decisions.md |
You want to upgrade TypeScript, add a lint plugin, or resurrect a CI workflow. Records what was tried and reverted. |
docs/theming.md |
You are adding or tuning a theme, or a colour is not doing what you expect. |
docs/design-system.md |
You are writing or reviewing any player-facing UI. The palette, type scale, shape rules and the defaults this design deliberately avoids. |
docs/RATE_LIMITING.md |
You are changing a rate-limit policy or debugging a lockout. Policies, progressive lockout, client identification. |
docs/how-to-run-offline.md |
You want the app running without any database, or dev:offline is behaving oddly. |
docs/cookie-inventory.md |
A privacy or GDPR question, or you are about to add a cookie or a localStorage write. |
docs/AUTO_PROJECT_CREATION.md |
Signup is not producing a project, or you are changing the default-project generator. |
docs/operation-starfall-bible.md |
You need the organisers' Starfall design intent and where each element stands. The repo's copy of the source PDF. |
docs/mockups/ holds the design bible's scanned panels; docs/starfall-tour-2026-08-14/
holds a light/dark screenshot tour of the starfall theme.
Historical material, kept as a record and not maintained. The changelog, the neural
backdoor challenge's design notes, the earlier security write-ups, and the two scaling
documents — scaling-report.md is the analysis, scaling-branch-report.md is the
record of what the scaling branch actually shipped. Read them for context on a past
decision; do not treat any of them as current.
- Intentional vulnerabilities are the product. Do not fix a CTF flaw unless asked.
CTF_README.mdis the inventory; removing a deliberate weakness deletes a challenge and no test will catch it. - No agent applies migrations.
supabase/migrations/*.sqlare files in the repo; the live schema exists only in the hosted project. lib/flag-registry.tsis the complete answer key, and it is in git only because this repo is private.supabase/seed.sqlwas one too, and stops being once the decoy migration runs. If this is ever made public, the registry comes out first, thenseed.sqlandsupabase/schema.sql.LICENSEis a proprietary all-rights-reserved licence: access to this repo is a revocable permission, not a grant. Nothing here may be reused, redistributed or used as training data without written permission.