Security model
Auth, rate limits, CSRF, fail-closed.
The premise is that this will be reachable from the public internet. Security therefore decides whether the service starts at all.
Three auth paths
- HTTP Basic — simplest, requires TLS on public
- H5 one-time token — for temporary devices
- Feishu OAuth — for people who won't remember another password
All three issue the same HMAC cookie, valid for seven days. Auth completes before the request body is read.
Writes
Every write requires X-CSRF-Token from the page, compared in constant time. A cross-site request may carry the cookie but not the token.
Limits
Five failures per IP locks for fifteen minutes; a per-IP token bucket caps overall rate. Rate limiting runs before auth: better to over-block than under-block.
Input
No user input reaches a shell: argv is passed directly and remote commands are quoted segment by segment. Endpoints are allowlisted; unknown actions are rejected.
Fail closed
Without MEDIA_WEB_PASSWORD the service refuses to start instead of degrading to no auth. That default is the most important line in the project.