Repository navigation
Bot protection on the auth endpoints that cost something to hit - #19
Merged
Merged
Conversation
…r the build
Every pull request has been failing since the portable functions entry point
landed:
FAIL baas
backend/functions/hello.ts(7,8): error TS2307:
Cannot find module '@rebasepro/server/functions'
`check:templates` and `check:eject` compile a *scaffolded project*, which
resolves `@rebasepro/*` through node_modules and its `exports` map. `./functions`
points at `dist/functions/index.d.ts`, so before `pnpm run build` it resolves to
nothing and the baas preset — whose `hello.ts` now imports it — fails to compile.
Both checks ran before the build step.
Nothing caught it locally because a developer's checkout has a `dist` lying
around from the last build; CI installs and has none. Reproduced by deleting
`packages/server/dist/functions` and running the check, which fails identically.
Moved both after `Build packages`, where `check:api-surface` already sits for
exactly this reason — its comment says "Reads dist/index.d.ts, hence after the
build". The cost is that a broken template is reported a few minutes later; the
alternative is a gate that cannot pass on a clean checkout.
Verified the rest of the lane separately: core-types, types-headless, baas-types,
test-scripts, control-chars, untranslated, hooks, unused, api-surface, dts,
deps, headless, names, derived-names and verify:docs all pass on this commit, so
this is the only thing standing between main and a green run.
Rate limiting was the whole defence, and it bounds a single caller. A botnet of a thousand addresses sending one request each never touches a per-IP window — and `/auth/register`, `/auth/forgot-password` and `/auth/magic-link` all send mail, so the bill for an unprotected form is paid in reputation on a sending domain rather than in CPU. `auth.captcha` adds a challenge verified server-side before the route does any work. Turnstile and hCaptcha, whose verify endpoints share one shape, or your own `verify` function. Three decisions worth stating. **It fails closed.** A provider that cannot be reached refuses the request. That is the opposite of the choice made for the scheduled RLS audit, and the difference is what failure means: an audit that does not run leaves you where you were, while a challenge that is not checked leaves the door open for exactly as long as the outage lasts — and an attacker able to cause the outage would otherwise be able to switch the protection off. The cost is that a provider outage blocks sign-ups, which is loud and undone by removing one key. **A misconfiguration fails the boot.** Enabled with no provider, an unknown provider, or no secret all refuse to start, and the middlewares are built at factory time so that happens at boot rather than on the first request. A challenge that is silently absent while the config says otherwise is the one failure this cannot have. **`login` is not protected by default.** A challenge on every sign-in is a tax on every real user; credential stuffing is what the rate limiter and lockout are for. It is one entry in `routes` for anyone who wants it. The verifier is injected, so no provider SDK enters this package's dependency graph and the whole thing is testable without a network — the built-in verifier is a form post, which is the entire protocol. Reachable from the environment too (`CAPTCHA_PROVIDER`, `CAPTCHA_SECRET`, `CAPTCHA_ROUTES`), because a managed tenant configures by variable and would otherwise be unable to turn it on. The caller is told only that the challenge failed. Absent, malformed, already used and provider-unreachable are one message; which one it was goes to the log, because telling a script tells it how to get closer.
Member
Author
|
Merge-order note: this conflicts with #12 (email dev sink). Both touch the same three files:
All three are additive: the resolution is keep both sides, not choose. I've done exactly that on Whichever of #12 or #19 lands second will need that resolution. Nothing subtle in it, but it won't auto-merge. |
`check:api-surface` reads `dist/index.d.ts`, so it only sees a new export after a build — and CI builds before it runs. The baseline had not been regenerated, so this branch failed that step while passing every gate that reads source. Additions only: `RebaseAuthConfig.captcha` and `BuiltinAuthAdapterConfig.captcha`.
`check:generated` runs the website generators and fails on any diff, so a docs change that does not carry its regenerated artifact fails CI. Mechanical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third item of #6.
Rate limiting was the whole defence, and it bounds a single caller. A botnet of
a thousand addresses sending one request each never touches a per-IP window — and
/auth/register,/auth/forgot-passwordand/auth/magic-linkall send mail. Sothe bill for an unprotected signup form is paid in reputation on your sending
domain, not in CPU.
Turnstile and hCaptcha (their verify endpoints share one shape), or your own
verifyfunction. Also reachable from the environment —CAPTCHA_PROVIDER,CAPTCHA_SECRET,CAPTCHA_ROUTES— because a managed tenant configures byvariable and could otherwise never turn it on.
Three decisions worth arguing with
It fails closed. A provider that can't be reached refuses the request. This
is deliberately the opposite of the RLS audit, which logs and continues, and
the difference is what failure means: an audit that doesn't run leaves you where
you were, while a challenge that isn't checked leaves the door open for exactly
as long as the outage lasts — and an attacker who can cause the outage could
otherwise switch the protection off. The cost is that a provider outage blocks
sign-ups; that's loud, and undone by removing one config key.
A misconfiguration fails the boot. Enabled with no provider, an unknown
provider, or no secret all refuse to start — and the middlewares are built at
factory time so this happens at boot, not on the first request. A challenge
that's silently absent while the config says it's there is the one failure this
can't have.
loginis off by default. A challenge on every sign-in taxes every realuser, and credential stuffing is what the rate limiter and lockout are for. It's
one entry in
routesfor anyone who disagrees.Why this and not email OTP
Both are #6 items. This one is additive-restrictive: the worst a bug can do is
refuse a legitimate login, which is visible and recoverable. A new OTP path is
additive-permissive — a bug there admits someone. That's a change I'd rather make
in daylight than at 4am.
Verification
token extraction, body-still-readable-by-the-route, the remote-IP cross-check,
the built-in verifier against a stubbed fetch (non-200, unreachable, malformed,
timeout), and every branch of the environment resolver
packages/server: 146 suites, 2161 passingpnpm typecheck,check:deps,verify:docscleanNot verified: a real token against a real Turnstile endpoint. The verifier is
injected and stubbed; the protocol is a documented form post.
Not included: the client-side widget. This is the enforcement half — the
necessary half — but a
<Turnstile />in the admin login form is separate work.