Add a config toggle to turn off new user registration
APP_ALLOW_REGISTRATION (default true) gates the only "sign up" this app has -- the account-creation side effect of POST /api/auth/magic-link. When false, an unknown address is silently ignored (find-only, no findOrCreateByEmail) while an existing address still gets its sign-in link as normal; the response is identical either way (202, same message), so there's still no enumeration signal. - Config::allowRegistration, read from APP_ALLOW_REGISTRATION. - AuthController::requestLoginLink takes the flag; only looks up (doesn't create) when it's off. - docker-compose.yml / .env.example / README document the new var. - ApiTestCase::reconfigure() rebuilds the app against changed env (same database) for tests that need a non-default Config; two new AuthTest cases cover both halves (blocks a new address, doesn't block an existing one). 59 tests pass. Verified against the rebuilt container: with the flag on (default), a new address gets a link and an account; switched off via the same env var, a brand-new address gets the same 202 but no email and no user row, while an address that already had an account still receives its link. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,7 @@ environment). See [.env.example](.env.example).
|
||||
| `DATABASE_PATH` | `storage/database.sqlite` | SQLite file location |
|
||||
| `JWT_SECRET` | auto-generated into `storage/secret.key` | Token signing key |
|
||||
| `JWT_TTL` | `86400` | Token lifetime in seconds |
|
||||
| `APP_ALLOW_REGISTRATION` | `true` | When `false`, a magic link is only ever sent to an existing address — an unknown one is silently ignored, so no new accounts get created |
|
||||
| `APP_URL` | `http://localhost:8080` | Base URL used to build magic links (`http://localhost:5173` for a host `npm run dev`) |
|
||||
| `MAIL_TRANSPORT` | `mail` | `mail` (PHP `mail()`), `smtp`, or `log` (append to a file) |
|
||||
| `MAIL_FROM` / `MAIL_FROM_NAME` | `no-reply@todo.test` / `Projects` | Envelope sender |
|
||||
@@ -156,8 +157,11 @@ Request: `{ "email": "ada@example.com" }`.
|
||||
Emails a one-time sign-in link (`<APP_URL>/verify-email?token=…`, 15-minute
|
||||
expiry) and always returns `202` with the same message. If the address has no
|
||||
account yet, one is created (unverified) right here — that's the only "sign
|
||||
up" there is. A link is only actually (re-)sent if this address hasn't been
|
||||
emailed one in the last 60 seconds. `422` if the address is malformed.
|
||||
up" there is — unless `APP_ALLOW_REGISTRATION=false`, in which case an unknown
|
||||
address is silently ignored (still `202`, nothing sent) and only an address
|
||||
that already has an account can sign in. A link is only actually (re-)sent if
|
||||
this address hasn't been emailed one in the last 60 seconds. `422` if the
|
||||
address is malformed.
|
||||
|
||||
```json
|
||||
{ "message": "Check your email for a link to sign in." }
|
||||
|
||||
Reference in New Issue
Block a user