Disimula – Security
What is protected, from whom, and how - network isolation, identity at the edge, authorization in the backend, CSRF, CSP, secrets, webhooks, AI isolation and privacy by design.
What there is to protect
- The missions. The game only works if nobody, organizers and admins included, can read the decks that will be dealt to them. This is a functional requirement that shaped the API.
- The home server. A machine at home, on a residential connection.
- Personal data. Emails, names and players' photos.
- Money. Payments, passes and AI credits, and the bills of the services behind the app.
- The AI. Text typed by users goes into prompts.
Network: nothing to attack at home
- No inbound ports. The server publishes no port;
cloudflareddials out to Cloudflare. - Players never reach the server. The online game runs on Cloudflare; the home backend only makes outgoing calls to it with a shared secret.
- The backend is never exposed. Only the Next.js container is in the tunnel's ingress; it proxies
/apito the backend on the compose network./actuatoris not proxied, so metrics are only reachable from the server's own network. - Grafana is LAN-only, not in the tunnel, optionally bound to
127.0.0.1and reached over SSH. - WAF rate limiting on
/api/*stops requests before they reach any code.
Identity at the edge, authorization in the backend
Cloudflare Access authenticates; the backend re-verifies the JWT (signature with the team's JWKS, issuer, expiry, audience) and maps the email to an active user and role. Details in Users and roles.
- Every endpoint must declare its permission (
@PreAuthorize); an ArchUnit test fails the build otherwise. - Ownership checks answer 404, not 403, for other people's games and sets, so their existence does not leak.
- Role management cannot escalate privileges or remove the last admin. Impersonation is bounded the same way: only towards roles that grant nothing the admin's own role does not, checked again on every request.
- The admin email in the configuration only bootstraps the first admin of an empty database; after that, who is admin is decided in the app, so demoting a compromised account sticks across restarts.
- The app refuses to start without an explicit auth mode, or in dev mode with Cloudflare settings.
CSRF
Cloudflare adds the identity to every request carrying its cookie, including those a third-party
site makes the browser send. So any change (not GET, HEAD or OPTIONS) is refused with
403 cross_site_request unless the browser says it comes from the app:
Sec-Fetch-Site, when present, must besame-originornone;- otherwise
Origin(orReferer) must be one of the app's origins;Origin: nullis refused; - no such header at all means a non-browser caller (the worker), which has its own credential.
Browser hardening
Every response of the app carries:
- a Content-Security-Policy:
default-src 'self', no third-party scripts, styles, connections or frames,object-src 'none',form-action 'self',frame-ancestors 'none'. One compromise:script-srcincludes'unsafe-inline', because the pages are prerendered static shells and Next.js inlines its bootstrap scripts, so per-request nonces are not an option. The CSP still keeps out every external origin; the protection against injected markup is React's escaping and the absence of any user HTML; X-Frame-Options: DENY,X-Content-Type-Options: nosniff, a strictReferrer-Policy,Permissions-Policydenying camera, microphone, geolocation, USB and payments, and HSTS.
The checkout page /pagar is the single exception: its CSP lets in *.paddle.com scripts,
frames and connections, and its Permissions-Policy allows the Payment Request API for Paddle's frame
only (Apple Pay, Google Pay). Since the browser lands there with a full page load from Paddle's payment
link, it always gets that page's headers. The landing page and the players' page ship their own
strict _headers.
The online rooms
- The Worker accepts room creation, photo uploads, result collection and deletion only with the home server's bearer token, compared by SHA-256 digest in constant time.
- It strips the internal "this came from home" header from every incoming request before deciding, so a player cannot forge it.
- A code that cannot exist is rejected without waking any Durable Object.
- The organizer's key travels in the URL fragment, which browsers never send to any server; the page stores it on the phone and removes it from the address bar.
view()decides per caller what is visible: a hand only goes to the phone that holds that profile, the organizer's key gives no access to anybody's hand, and the backend never receives a mission while the game is on.
Payments
- Webhooks are accepted only with a valid HMAC signature (
Paddle-Signature), at most 5 minutes old (no replays), and each event id is processed once. - The webhook path is the only one open in Access (Paddle cannot sign in), and a WAF rule only lets Paddle's published IPs reach it (live ones for production, sandbox ones for dev), so anyone else is blocked at the edge. Invalid signatures that still arrive raise an alert.
- The browser never decides what was paid: passes and credits are given only by the webhook.
- The Paddle client token in the browser is public by design; the API key and webhook secret live only in the backend's environment.
Secrets
- Generated by OpenTofu (
random_id) where possible, stored in an encrypted state. - In GitHub as environment-prefixed secrets; written to
~/<project>/.env(mode 600) by the deploy. - The deploy refuses to change the database password or the backup passphrase once set.
- The AI worker's secrets never reach a model session, so a prompt-injected session cannot read the worker token.
- Backups are encrypted before leaving the server (rclone crypt).
The AI
User text in prompts is treated as hostile. Layered defences (prompt guard, bounded fields, data wrapping, no tools, output cleaning, a second evaluator session, human review) are described in AI.
Uploaded images
Photos must be JPEG or PNG, at most 2 MB, and are redrawn server-side as plain JPEGs of at most 1100 px. Re-encoding drops metadata (EXIF location included) and anything hidden in the file.
Supply chain
- GitHub Actions pinned by commit SHA; third-party images and Dockerfile base images pinned by digest.
- Dependabot opens grouped update PRs for Actions, npm, Maven, Docker and compose files.
- Images run as non-root.
- The self-hosted runner executes workflow code on the server, so the repository stays private and
production only deploys from
main. - Production gets exactly what was tested in dev: the deploy starts the image digests dev is
running, never a
latesttag that may have moved since. - Production's Cloudflare changes (Access, tunnel, DNS, WAF) wait for a human approval in a protected GitHub environment; dev applies on its own.
Privacy by design
- Missions are never logged. Log lines carry ids, emails and counts.
- Stats and dashboards read counts and sums only.
- Online rooms (names, missions, photos) are deleted a week after the game ends, or at once when the game is deleted.
- Account deletion removes everything the user owned and anonymizes the row. Copies in the encrypted backups expire with them, within 30 days.
- One deliberate exception to "counts only": admins can read the prompts behind AI requests, private ones included, to spot abuse of the AI. They never see a private set's missions.