Skip to content

Access token for the public tunnel - #5

Merged
sklsp merged 3 commits into
mainfrom
feat/access-token
Oct 8, 2026
Merged

sklsp merged 3 commits into
mainfrom
feat/access-token

Conversation

@sklsp

@sklsp sklsp commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

launcher.py, the README's main way to start Apollo, always opens a public trycloudflare.com tunnel, and Apollo had no authentication. Anyone with that link could read your uploaded documents and chats, upload files, and run ComfyUI generations or LoRA training on your GPU. The tunnel's requests reach uvicorn from localhost, so an "only allow local" rule wouldn't help.

What changes:

  • Token check: with APOLLO_ACCESS_TOKEN set, every request except /live and /health (the launcher's probes) needs the token. It's compared in constant time. It can come from:
    • the X-Apollo-Token header, for API clients, or
    • a cookie that opening /?token=<token> sets once. The cookie is HttpOnly, SameSite=Lax (so other sites' requests never carry it), and Secure behind the tunnel. The page then redirects to the same URL without the token, and all of the page's own requests work unchanged.
  • Launcher: it generates a random token unless you set one, then prints, copies and opens the link with the token.
  • Local runs: without the variable, Apollo stays open, exactly as before. A plain uvicorn run is unchanged.
  • README: explains the token, and the environment table lists the variable.

Tests:

  • tests/test_access_token.py (6) covers:
    • open without a token
    • 401 without or with a wrong token
    • the header works
    • the probes stay open
    • the link sets the cookie and strips the token from the URL
    • the launcher's links carry the token
  • All 259 tests pass. The README's test count is updated separately in README: 253 tests, as CI reports #4.
  • Checked in a real browser with a token set: a stranger gets 401, and the link lands on / with the cookie set. All 7 of the page's API calls then succeed (/health reports 503 only because Ollama wasn't running).

CORS (second commit): allow_origins=["*"] with allow_credentials=True made Starlette echo any caller's Origin when a cookie came along, so another site could read responses made with the access cookie. I checked it: a request from an evil origin with the cookie got back that origin and allow-credentials: true. Credentials are now off. The dashboard is same-origin, and API clients use the header. A test pins this; 260 tests pass.

Security headers (third commit), on every response including the 401 and the redirect: nosniff, X-Frame-Options: DENY with CSP frame-ancestors 'none'; base-uri 'self'; object-src 'none' (the directives that can't break the dashboard's inline scripts), and Referrer-Policy: no-referrer. The token arrives once in a URL, so no Referer header may carry it anywhere.

🤖 Generated with Claude Code

sklsp and others added 3 commits October 8, 2026 04:36
launcher.py publishes Apollo on a public trycloudflare.com URL, and Apollo had no
authentication: anyone with the link could read uploaded documents, upload
files and run ComfyUI or LoRA jobs on the host GPU. The tunnel's requests reach
uvicorn from localhost, so the fix cannot trust "local" either.

- With APOLLO_ACCESS_TOKEN set, every request except /live and /health needs
  the token: the X-Apollo-Token header, or an HttpOnly, SameSite=Lax cookie that
  opening /?token=<token> sets once (then redirects without the token).
  Constant-time comparison. Unset, Apollo stays open as a local tool.
- The launcher generates a token (unless you set one), and prints, copies and
  opens the link with the token.
- 6 tests; checked in a browser: no token 401, the link sets the cookie and
  lands on /, all 7 of the page's API calls succeed. 259 tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With allow_origins=["*"] and allow_credentials=True, Starlette echoes the
caller's Origin whenever the request carries a cookie, so another site could
read responses made with the access cookie (checked: Origin evil + cookie ->
allow-origin evil, allow-credentials true). The dashboard is same-origin and
needs no CORS; API clients use the header. Credentials off; a test pins it.
260 tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nosniff, X-Frame-Options DENY plus CSP frame-ancestors/base-uri/object-src (the
directives that cannot break the dashboard's inline scripts), and
Referrer-Policy no-referrer: the token arrives once in a URL, so no Referer
header may carry it anywhere. The middleware wraps the token check, so the 401
and the cookie redirect carry the headers too. Test included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sklsp
sklsp marked this pull request as ready for review October 8, 2026 09:59
@sklsp
sklsp merged commit 80de55e into main Oct 8, 2026
1 check passed
@sklsp
sklsp deleted the feat/access-token branch October 8, 2026 09:59
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