Close the door the edge gate used to hold
A security review of the whole repo. The queries were already scoped, the
OIDC flow already did state and nonce and PKCE, the session tokens were
already stored as hashes. What it found was mostly the seam between the
code and the deployment — and one place where the deployment quietly
undid the code.
The one that matters: with any AUTHENTIK_* variable missing, Petal fell
back to resolving every request to the single `local` user. That is right
on a laptop and a catastrophe on a public host, and Phase 16 removed the
Traefik basic-auth gate that used to stand behind the mistake. A typo in
the client secret would have served her journals to the open internet and
said so only in a log line nobody reads. It now refuses to start, guarded
by default for any BASE_URL that isn't loopback.
Then the one that would have been fixed and wasn't: stored images now
serve under `default-src 'none'; sandbox`, so an SVG pasted into a
document can't run as a page on Petal's own origin. Traefik's
customresponseheaders *overwrites*, so the CSP declared in the compose
labels would have silently replaced that per-route policy in production.
The whole header block moved into the binary, where a route can tighten
its own and a test can prove it; only HSTS stays at the edge, where TLS
actually terminates.
The rest, smaller:
- PETAL_ALLOWED_SUBS empty means everyone authentik authenticates, and
authentik here fronts half a dozen applications. Still legal, now
said out loud every boot, and set in both env examples.
- LLM failures relayed err.Error() to the browser, which carries the
address of the inference box on the far side of the VPN. Logged
instead; the client only ever rendered "the helper is resting".
- Exports scheme-check their links. Escaping makes a URL safe to sit
in an attribute and says nothing about following it, and an export
is the one artifact here meant to leave. Writing the test found the
markdown image src, which I'd missed reading it.
- The draft rescue is namespaced per account and cleared on sign-out.
Everything else in localStorage is a preference; this is her unsaved
writing, sitting in a profile two people share.
- /auth/logout is POST-only. With SameSite=Lax a GET route lets any
page on the internet sign her out mid-draft.
- Image uploads get a per-account allowance and the TTS cache a size
cap. Both share the encrypted volume the database is on, and a full
disk is SQLite failing to write, not a feature degrading.
- The session cookie takes the __Host- prefix over https, so nothing
else under parodia.dev can plant one. Old cookies still resolve;
nobody is signed out to get there.
- npm audit: linkify-it and postcss.
Verified: go build, go vet, the full Go suite, tsc, 195 frontend tests,
npm audit clean. The startup guard and both CSPs checked against a
running server rather than only asserted.
Claude-Session: https://claude.ai/code/session_016y6gyuHkQXPiEuW8RGQyua
This commit is contained in:
+37
-2
@@ -233,8 +233,21 @@ unauthenticated `/api/health` router that existed only to escape it: every `/api
|
||||
route now answers 401 without a session, and the only thing an anonymous visitor
|
||||
gets is the app shell and a redirect to sign in.
|
||||
|
||||
If you ever run this stack *without* `AUTHENTIK_*` configured — Petal then falls
|
||||
back to the single `local` user — put the gate back before pointing DNS at it:
|
||||
Removing that gate meant a missing `AUTHENTIK_*` variable stopped being a
|
||||
nuisance and became an exposure: Petal would fall back to the single `local`
|
||||
user and hand every anonymous visitor full read and write over the database,
|
||||
saying so only in a log line. So **it now refuses to start instead**:
|
||||
|
||||
```
|
||||
auth: refusing to start unauthenticated at https://petal.parodia.dev.
|
||||
Petal would resolve every anonymous request to the single "local" user, ...
|
||||
```
|
||||
|
||||
The guard defaults on for any `BASE_URL` that isn't loopback, so a laptop
|
||||
checkout still runs open and a deployment cannot. If you genuinely want an
|
||||
unauthenticated instance on a trusted private network, say so out loud with
|
||||
`PETAL_REQUIRE_AUTH=false` — and if it is reachable from anywhere else, put a
|
||||
gate back in front of it first:
|
||||
|
||||
```yaml
|
||||
traefik.http.routers.petal.middlewares: compression@file,petal-headers,petal-auth
|
||||
@@ -243,6 +256,28 @@ traefik.http.middlewares.petal-auth.basicauth.users: ${PETAL_BASIC_AUTH:?}
|
||||
|
||||
with `htpasswd -nbB petal 'your-password'` in `.env` as `PETAL_BASIC_AUTH`.
|
||||
|
||||
### Who gets in
|
||||
|
||||
`PETAL_ALLOWED_SUBS` is a comma-separated list of emails and/or OIDC subject
|
||||
ids. **Set it.** Empty means everyone authentik authenticates, and authentik on
|
||||
this host fronts several applications — a valid account there is not the same as
|
||||
belonging in someone's private journal. An empty list is legal (a single-
|
||||
household instance may want it) and warns at every boot:
|
||||
|
||||
```
|
||||
auth: WARNING — PETAL_ALLOWED_SUBS is empty, so EVERY account ... may sign in
|
||||
```
|
||||
|
||||
### Response headers
|
||||
|
||||
`Content-Security-Policy`, `X-Content-Type-Options` and `Referrer-Policy` are set
|
||||
by the binary, not by the Traefik labels. Traefik's `customresponseheaders`
|
||||
*overwrites*, which would silently replace the stricter policy an individual
|
||||
route picks for itself — the image store serves stored uploads under
|
||||
`default-src 'none'; sandbox` so that an SVG someone pasted into a document
|
||||
cannot run as a page on Petal's own origin. Only HSTS stays at the edge, where
|
||||
TLS is actually terminated.
|
||||
|
||||
---
|
||||
|
||||
## 4a. Moving an account (`scripts/migrate_local_user.py`)
|
||||
|
||||
Reference in New Issue
Block a user