Skip to content

Authentication

Hotaru uses Better Auth with email (or username) and password, as decided in ADR-0003. Setup: packages/core/src/auth/auth.ts. The SvelteKit side (cookies, the request handler, the route guard) is in apps/web/src/hooks.server.ts.

What needs a login

Everything, except:

  • /health
  • the pages in apps/web/src/routes/(public)/: login, registration (only when an admin opened it, accounts.md), forgot password and reset password
  • Better Auth’s own endpoints under /api/auth/
  • the starred feed, /feeds/starred/<token>: the secret token in its URL is the key (stream.md)

Pages redirect to /login?redirectTo=…. Everything under /api/ answers 401 instead. A new route is protected unless it’s put in the (public) group. Unknown paths are treated the same way, so they don’t reveal whether something exists.

Only users with status active can log in or use a token. An account that registered while registration was open is pending until its email is confirmed (accounts.md). Setting a user to suspended locks them out at once, including their existing sessions and tokens. Admins do it on Settings → Accounts, or with pnpm user suspend (accounts.md).

The first admin, and accounts in general

Registration is off until an admin opens it to people with an invite or to anyone, on Settings → Accounts (accounts.md). Off, /register answers 404. Better Auth’s own sign-up endpoint is always off: accounts come from the registration form, which checks the mode and the invite, or from the admin CLI:

Terminal window
# Locally (uses apps/web/data/hotaru.db, or DATABASE_PATH)
pnpm user create --email [email protected] --name "Your Name" --username you --admin
# On the server: Coolify → the app → Terminal, or docker exec on the VPS
node /app/packages/core/scripts/user.ts create --email [email protected] --name "Your Name" --username you --admin

The CLI asks for the password without echoing it (at least 12 characters). Piped, it reads the first line of stdin. Other commands:

Command What it does
user password --email … Sets a new password and ends all of the user’s sessions
user token --email … --name … [--scope read|cron|subscribe|write] Creates an API token and prints it once (--write is short for --scope write)
user suspend --email … / user activate --email … Locks an account out and lets it back in; its data stays
user delete --email … --yes Deletes an account and everything it owns (accounts.md)

People who register themselves always get the role user. Only the CLI makes admins, and accounts it makes need no email confirmation.

Password reset

/forgot-password emails a reset link that is valid for one hour, through Resend (email.md). Without Resend set up, the email is written to the server log ([email] To …), where the operator can pick the link up. Resetting ends all of the user’s sessions. As the operator, pnpm user password is quicker.

The page answers the same whether the address has an account or not. The server log tells the operator which it was: [Better Auth]: Reset Password: User not found when there’s no such account, [email] Resend accepted "Reset your Hotaru password" (id …) when the email went to Resend, [email] Resend refused … with Resend’s status and message when it didn’t, and [auth] Password reset request failed: … when Better Auth refused the request itself. email.md has what to check then.

Changing your password

Settings → Account → Password asks for the current password and the new one twice (POST /api/v1/me/password, a logged-in browser only, SI-579). The new one needs 12 characters or more. Changing it ends every other session of the account, on other devices too; this browser gets a new session and stays logged in. API tokens aren’t sessions and aren’t revoked by this: revoke them under API tokens if they might be known to someone else.

API tokens

For clients without a browser (CLI, TUI, Pi agents, cron). Users create them on API tokens (/settings/tokens) or with the CLI. A token looks like hotaru_… and is shown only once. Only its SHA-256 hash is stored.

Terminal window
curl -H "Authorization: Bearer hotaru_…" https://hotaru.example.com/api/v1/me

The SDK takes it as createClient({ baseUrl, token }). Tokens only work under /api/, never for pages. A wrong token answers 401, even if the request also carries a session cookie.

A token has one of four scopes:

  • read: reads everything, previews filters and rules, resolves views.
  • cron: also starts work, for scheduled jobs: fetches a source, reruns an item’s pipeline, groups topics, runs a taste review.
  • subscribe: reads, and finds and follows feeds, for the browser extension (SI-570). It can’t start work, change or delete anything else.
  • write: everything a token may do.

cron and subscribe each include read, not each other; write includes all.

A request the token’s scope doesn’t allow answers 403, saying which token it needs. Managing API tokens and the starred feed’s address is for a logged-in browser only: no token may do it, so a leaked token can’t make more. Which scope each request needs is in api.md.

The starred feed has a token of its own (hotaru_feed_…, stored as a hash in feed_tokens). It opens only that feed, and API tokens don’t open it.

Rate limits

What Limit
Login form, per client address 20 failed attempts per 15 minutes (a successful login gives its attempt back)
Login form, per account (email or username) 5 attempts per 15 minutes, reset by a successful login
Registration and reset requests, per client address 5 per hour
Direct calls to /api/auth/send-verification-email 5 per hour
Direct calls to /api/auth/sign-in/* 5 per minute (Better Auth’s own limit)

The API has per-user limits of its own: api.md.

The counters live in memory and reset when the app restarts. They count per client address, which comes from the reverse proxy: see below.

Behind a reverse proxy

Hotaru expects a reverse proxy in front of it that terminates HTTPS and passes on the client’s address in a request header. ADDRESS_HEADER names that header, for both the app’s own limits and Better Auth’s. The Docker image sets ADDRESS_HEADER=x-real-ip.

The proxy must set the header and overwrite whatever a client sends in it. Otherwise anyone can pick their own address and get around the per-address limits.

Proxy Setting
Traefik (also in Coolify) Sets X-Real-Ip by default. Nothing to do
Caddy reverse_proxy hotaru:3000 { header_up X-Real-Ip {remote_host} }, as in the caddy profile of compose.yaml
nginx proxy_set_header X-Real-IP $remote_addr;
Cloudflare in front of the proxy Use the proxy’s setting for Cloudflare’s real client IP, or ADDRESS_HEADER=cf-connecting-ip when Cloudflare talks to Hotaru directly

To use X-Forwarded-For instead, set ADDRESS_HEADER=x-forwarded-for and XFF_DEPTH to the number of trusted proxies (adapter-node).

When a request arrives without the header, its address is unknown, and the server logs [auth] A request came without the x-real-ip header… once. Until the proxy sets the header, all clients share one counter, so a few failed logins by anyone slow down everyone’s logins. Never expose Hotaru’s port to the internet without a proxy: a client could then send the header itself.

Sessions

A session cookie lasts 30 days and is extended when the user comes back after a day. Logging out (the button in the header) ends the session on the server.