Open endpoints
Open endpoints
An endpoint that asks for no login can be called by anyone on the internet, as often as they like. That is how an app gets its accounts made by a stranger, its data read with no role, or its paid API run dry overnight. Each of those happened to somebody else in November 2026: an app whose sign-up routes took no authentication, and apps whose AI credits were spent through a sign-in bug.
So in this app no endpoint is open by accident. Since 2026-11-22 a test fails when one is.
The rule
Every endpoint asks for a login (requireUser(), requireAdmin()) before
it does anything. An endpoint that cannot, because a visitor or another
service has to reach it, is written down in
scripts/endpoint-audit/manifest.ts with what protects it instead and why
it is open.
An endpoint is either of:
- a route file with server handlers (
server: { handlers: { GET, POST } }), - a server function (
createServerFn).
The test
scripts/endpoint-audit/endpoints.test.ts, part of bun test and so of
make ci. It reads the source and fails when:
- an endpoint asks for no login and is not in the manifest;
- the manifest lists an endpoint that is gone, or that asks for a login now;
- an entry claims a protection its code does not show: a rate limit with no
limiter, a signature with no check. For a server function the test reads
the function's own code and the helpers of its file that it calls, not
the whole file: on 2026-11-22 a file with five limiters had one open
function that called none, and a check of the file passed it. When the
check lives in another file, the entry names that file (
seeFile).
To see the list as the code has it:
bun scripts/endpoint-audit/scan.ts
The scanner reads text, not types. It errs towards calling an endpoint
open: one that is guarded in a way it cannot see is listed like any other
open one, with the reason. A login check through a helper of another file
is named once in EXTRA_GUARDS, after reading the helper.
What may protect an open endpoint
| In the manifest | Meaning | Ask |
|---|---|---|
rate-limit | One caller may call it only so often. | Is the limit per address, and per user or email where one is known? Does it fail closed when the address is unknown? |
signature | The caller signs the body with a shared secret. | Is the signature checked before the body is read as data, in constant time? |
token | A secret in the address or a header. | Is it long and random, compared in constant time, and can it be revoked? |
env-switch | 404 unless an environment variable turns it on. | Is it off in production, and does the boot check say so if it is not? |
auth-library | The sign-in library's own routes. | Is the library up to date? See "The sign-in library" below. |
nothing-to-protect | No database read, nothing that costs money, nothing changed. | Is that still true after the last change to it? |
An open endpoint that reads the database for every caller is not
nothing-to-protect. Keep its answer in memory (src/lib/cached-read.ts)
or limit it.
Before adding an open endpoint
- Can it ask for a login? An admin page, a status report, an export: yes.
Use
requireAdmin()and answer 404 to everyone else, assrc/routes/api/v1/ad-conversions.tsdoes. - Does it spend money (an AI call, an email, an SMS)? Then a login, a limit per user, and a cap per day on what it may spend.
- Does it write? Then a limit, and input checked with a schema.
- Does it read the database? Then a limit, or an answer kept in memory.
- Write the line in the manifest. The reviewer reads that line first.
The captcha
The sign-in and sign-up code functions verify the Turnstile token when one is sent and refuse a bad one. When none is sent they still answer, because a browser that blocks the widget sends none: Brave with strict Shields, a privacy extension, a corporate filter. A bot sends none too. Decided by the founder on 2026-11-22:
| Form | No token | Why |
|---|---|---|
| Sign-in | Sent, within the normal limits | A sign-in code goes only to an address that has an account. A bot cannot mail strangers through it. |
| Sign-up | Sent, but at most one code per address an hour and three per IP an hour (noCaptchaSignupRefusal in src/server/otp-send-limits.ts) | A sign-up code goes to any address. Without the captcha this is the way a bot would use our sending domain. |
| Contact, newsletter | Refused | No person is locked out of anything that matters. |
Each request with no token is counted per day and per form
(captcha_missing_counts in platform_settings, src/server/captcha-missing.ts).
After a week the counts say whether that path is people or bots; if it is
only bots, sign-up can refuse a missing token outright.
The sign-in library
The sign-in routes are open by nature, so a flaw in the library is a flaw in every app at once. In better-auth before 1.7.7 a sign-in state value could be used as a magic link token, which let a stranger sign in as another user (GHSA-965c-763c-88jm). This template was on 1.7.18 when that was read, on 2026-11-22.
- Renovate opens a pull request for a new version. A security release of
better-authis merged the day it appears, not with the weekly batch. bun auditis the check; run it when an advisory is in the news.- A key for a paid API is one per app, with a spending cap per day at the provider. A flaw then costs one day of one app.
What was found when this was written
The first run of the test, on 2026-11-22, listed 22 open endpoints in the
template. Each was read. One had no protection: getSignupOpenFn read the
database for any caller with no limit. Its answer is now kept for 30
seconds.
Two things were found beside the test and fixed the same day:
- A cap on the size of a request body.
Bun.servetakes up to 128 MB when nothing is set, and an open POST route reads the body before it checks anything. The server is now started withmaxRequestBodySize: MAX_REQUEST_BODY_BYTES(src/lib/request-limits.ts, 8 MB). Files never pass through the server: uploads go straight to storage with a presigned URL. - The boot check refuses
LOADTEST_AUTH_ENABLEDon the live site. With it on,/api/loadtest/authsigns the test user in for anyone who knows the test secret. The server will not start when it is on andBETTER_AUTH_URLis a public address; e2e still runs it against a local production build.