Skip to content

fix(self-host): require an access token for every route - #223

Merged
tong-io merged 2 commits into
mainfrom
fix/self-host-api-auth
Oct 6, 2026
Merged

tong-io merged 2 commits into
mainfrom
fix/self-host-api-auth

Conversation

@tong-io

@tong-io tong-io commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Hardens the self-hosted server's access control.

  • New middleware gate (src/lib/api/self-host-gate.ts) in front of all pages and API routes.
    • TONGFLOW_AUTH_TOKEN set → token required (HttpOnly SameSite=Strict cookie via a one-time ?token= link, or Authorization: Bearer).
    • Unset → served to loopback Host headers only; pnpm dev / pnpm start bind 127.0.0.1.
  • Docker: entrypoint generates a token into /data/auth-token when none is set and prints the login link; Compose / README publish on 127.0.0.1.
  • /api/engine-assets and /api/task/webhook keep their own token checks. Uploads (/api/uploads/*.png) are no longer skipped by extension.
  • src/middleware.ts is now tracked (cloud shell still overwrites it at link time).
  • READMEs (EN/ZH/JA) and .env.example updated.

Breaking for self-hosters: Docker users open the link from docker logs once; source users who reach the server from another machine must set TONGFLOW_AUTH_TOKEN.

Verified: unit tests (7 new), full suite, lint, typecheck, build, and next start probes (401 without credentials, 200 with cookie/Bearer, 403 for a non-loopback Host without a token).

🤖 Generated with Claude Code

tong-io and others added 2 commits October 6, 2026 13:18
The self-host server answered every page and API route without knowing
the caller. Add a middleware gate:

- TONGFLOW_AUTH_TOKEN set: requests need the token as a cookie (set by
  opening any page with ?token=) or a Bearer header.
- Unset: only loopback Host headers are served; `pnpm dev` / `pnpm start`
  now bind 127.0.0.1.
- The Docker image always runs with a token: the entrypoint generates
  one into /data/auth-token and prints the login link. Compose and the
  README docker command publish the port on 127.0.0.1.

/api/engine-assets and /api/task/webhook keep their own token checks.
src/middleware.ts is now tracked; a cloud shell still replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tong-io
tong-io merged commit 7174de1 into main Oct 6, 2026
5 checks passed
@tong-io
tong-io deleted the fix/self-host-api-auth branch October 6, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant