diff --git a/SECURITY.md b/SECURITY.md index d7c970b7..fef9c1e7 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -14,8 +14,8 @@ to upgrade. | Version | Supported | | ---------------- | --------- | -| 0.19.x (latest) | Yes | -| 0.18.x and older | No | +| 0.24.x (latest) | Yes | +| 0.23.x and older | No | Under 0.x a minor release can contain breaking changes. Read the [CHANGELOG](./CHANGELOG.md) before upgrading across a minor version. diff --git a/docs/account-recovery.md b/docs/account-recovery.md index 9ed7934a..e5e7bd4b 100644 --- a/docs/account-recovery.md +++ b/docs/account-recovery.md @@ -122,9 +122,15 @@ The attempt cannot be kept alive instead. Every token re-minted within an attemp by an OTP resend, expires when the attempt's first token did, so the request can only be completed on an attempt that proved the channel within the last few minutes. -Starting is not enough to disturb anything: anyone who knows an address can start, so only -a verified code opens, resumes or cancels a request. Five wrong codes on a resume void -that code and leave the open request as it was. +Anyone who knows an address can start, so only a verified code opens, resumes or cancels a +request, and starting never changes an open request's state, its clock or its notices. It +does change which code resumes it. An open request holds one resume code, and every start on +its channel replaces that code with a new one bound to the new attempt. A start by someone +else while the owner is typing their code makes the owner's code fail (without spending the +failure budget, since it no longer matches the owner's attempt), and the owner starts again. +Per-attempt resume codes are tracked in +[issue #600](https://github.com/fells-code/seamless-auth-api/issues/600). Five wrong codes on +a resume void that code and leave the open request as it was. ### Failure budget @@ -150,8 +156,10 @@ off, and a request id from another account answers `404`. ### Notes - Account lockout does not block recovery, since lockout is what someone recovering may be - locked out by. Wrong codes are limited per request as above, and every route sits behind - the OTP flow rate limits. + locked out by. Wrong codes are limited per request as above. Every route that takes a + pre-auth token sits behind the OTP flow rate limits (per IP and per identity), and + `/recovery/cancel` behind the per-IP one. Listing and cancelling with an access session + have only the global limiter. - A pre-auth token for an identifier with no account gets the answers a real account with no verified address gets, and nothing is stored or sent for it. - Under external delivery the code arrives with `purpose: "account_recovery"`, so an diff --git a/docs/adr/0005-extensibility-callouts.md b/docs/adr/0005-extensibility-callouts.md index 4eb82cec..3840ce49 100644 --- a/docs/adr/0005-extensibility-callouts.md +++ b/docs/adr/0005-extensibility-callouts.md @@ -108,10 +108,10 @@ Among roles of one kind, sets apply in role-name order, so the last name alphabe `calloutTransport.ts` serves webhooks, hooks and sinks: -- `https` only in production, no userinfo, never the API's own issuer host. +- `https` only in production, no userinfo, and not the API's own issuer host. That check compares host names exactly, so a trailing dot (`auth.example.com.`) or another DNS name for the same server is not caught by it ([#601](https://github.com/fells-code/seamless-auth-api/issues/601)). - DNS resolves inside the socket's `lookup`, and every address a name resolves to must be allowed, which defeats rebinding. - Link-local, unspecified, multicast and broadcast addresses are never reachable, in any mode, for any host. -- Other private and loopback addresses are refused in production unless the host is listed in `CALLOUT_PRIVATE_HOSTS`. It is an env var, so nothing written through the API can widen it, and it is separate from `OAUTH_PROVIDER_PRIVATE_HOSTS`, so allowing an internal hook service does not also allow it as an identity provider. +- Other private and loopback addresses are refused in production unless the host is listed in `CALLOUT_PRIVATE_HOSTS`. It is an env var, so nothing written through the API can widen it, and it is checked separately from `OAUTH_PROVIDER_PRIVATE_HOSTS`, so allowing an internal hook service does not also allow it as an identity provider. The checks run when a connection opens. Callouts and OAuth provider requests both use Node's global keep-alive agent, whose connection pool is keyed by destination and not by the lookup that checked it, so a callout can reuse an open connection that a provider request made to a host listed only in `OAUTH_PROVIDER_PRIVATE_HOSTS` and skip its own check. A dedicated agent per policy is tracked in [#601](https://github.com/fells-code/seamless-auth-api/issues/601). - Redirects are never followed. Responses are capped at 64 KiB. The deadline covers the whole request, so a destination that trickles bytes cannot hold a sign-in open. - URLs are checked when written and again at connect time. - Failures are reported as `refused`, `misconfigured`, `timed_out`, `connection_failed`, `http_status`, `invalid_response` or `too_large`, never with the resolved address or the socket's error text, so the delivery log cannot be used to map the internal network. `refused` means the API would not connect to the destination's address; `misconfigured` means the destination's own settings cannot be used, so no call was attempted. diff --git a/docs/configuration.md b/docs/configuration.md index 8ccfc35d..8ffca37c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -147,23 +147,31 @@ sinks need API 0.23.1 or later; 0.23.0 refuses them with a 400. ### Service tokens and secrets -| Variable | Required | Default | Notes | -| ------------------------------- | ------------------------------------ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `SEAMLESS_SERVICE_TOKEN` | Yes | - | Trusted server-adapter and internal bearer secret. No other secret falls back to it. In production, boot refuses a value shorter than 32 bytes or a published default (such as the `docker-compose.yml` value). Generate one with `openssl rand -base64 48`. | -| `API_SERVICE_TOKEN` | No | - | Supported fallback name for `SEAMLESS_SERVICE_TOKEN`. Used only when `SEAMLESS_SERVICE_TOKEN` is unset, with an info notice at boot. Setting both to different values stops the server at boot. | -| `REFRESH_TOKEN_LOOKUP_SECRET` | Production | development-only value | HMAC key for indexed refresh-token lookup fingerprints. Always required in production. | -| `TOTP_SECRET_ENCRYPTION_KEY` | Production, once TOTP is used | development-only value | Encrypts stored TOTP secrets (hashed with SHA-256 to derive the key, so any high-entropy value works). Production refuses to start while any TOTP credential exists without it, and `POST /totp/enroll/start` answers `409 secret_required` until it is set. | -| `OAUTH_STATE_SECRET` | Production, once OAuth is configured | development-only value | Signs OAuth state. Production refuses to start with a provider configured and no value, and adding a provider answers `409 secret_required` until it is set. | -| `DECOY_SUBJECT_SECRET` | Production | development-only value | HMAC key the decoy pre-auth subjects on `POST /login` derive from. Always required in production. Rotating it re-maps which subject an unknown identifier gets, which is harmless: decoys are stateless and pre-auth tokens live five minutes. | -| `OAUTH_PROVIDER_PRIVATE_HOSTS` | No | - | Comma-separated OAuth provider hosts allowed to resolve to private or loopback addresses in production, for an on-premises IdP. Other provider hosts must resolve to public addresses. Link-local is always refused. | -| `CALLOUT_SECRET_ENCRYPTION_KEY` | Production, once a webhook exists | development-only value | Encrypts stored webhook signing secrets (hashed with SHA-256 to derive the key). Production refuses to start while any webhook exists without it, and creating one answers `409` until it is set. | -| `CALLOUT_PRIVATE_HOSTS` | No | - | Comma-separated webhook and audit sink hosts allowed to resolve to private or loopback addresses in production, for a receiver inside your own network. Separate from `OAUTH_PROVIDER_PRIVATE_HOSTS`. Link-local, multicast and the unspecified address are always refused, and a callout can never point at the API's own issuer host. | +| Variable | Required | Default | Notes | +| ------------------------------- | ------------------------------------ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `SEAMLESS_SERVICE_TOKEN` | Yes | - | Trusted server-adapter and internal bearer secret. No other secret falls back to it. In production, boot refuses a value shorter than 32 bytes or a published default (such as the `docker-compose.yml` value). Generate one with `openssl rand -base64 48`. | +| `API_SERVICE_TOKEN` | No | - | Supported fallback name for `SEAMLESS_SERVICE_TOKEN`. Used only when `SEAMLESS_SERVICE_TOKEN` is unset, with an info notice at boot. Setting both to different values stops the server at boot. | +| `REFRESH_TOKEN_LOOKUP_SECRET` | Production | development-only value | HMAC key for indexed refresh-token lookup fingerprints. Always required in production. | +| `TOTP_SECRET_ENCRYPTION_KEY` | Production, once TOTP is used | development-only value | Encrypts stored TOTP secrets (hashed with SHA-256 to derive the key, so any high-entropy value works). Production refuses to start while any TOTP credential exists without it, and `POST /totp/enroll/start` answers `409 secret_required` until it is set. | +| `OAUTH_STATE_SECRET` | Production, once OAuth is configured | development-only value | Signs OAuth state. Production refuses to start with a provider configured and no value, and adding a provider answers `409 secret_required` until it is set. | +| `DECOY_SUBJECT_SECRET` | Production | development-only value | HMAC key the decoy pre-auth subjects on `POST /login` derive from. Always required in production. Rotating it re-maps which subject an unknown identifier gets, which is harmless: decoys are stateless and pre-auth tokens live five minutes. | +| `OAUTH_PROVIDER_PRIVATE_HOSTS` | No | - | Comma-separated OAuth provider hosts allowed to resolve to private or loopback addresses in production, for an on-premises IdP. Other provider hosts must resolve to public addresses. Link-local is always refused. | +| `CALLOUT_SECRET_ENCRYPTION_KEY` | Production, once a webhook exists | development-only value | Encrypts stored webhook signing secrets (hashed with SHA-256 to derive the key). Production refuses to start while any webhook exists without it, and creating one answers `409` until it is set. | +| `CALLOUT_PRIVATE_HOSTS` | No | - | Comma-separated webhook and audit sink hosts allowed to resolve to private or loopback addresses in production, for a receiver inside your own network. Checked separately from `OAUTH_PROVIDER_PRIVATE_HOSTS` (see the note below). Link-local, multicast and the unspecified address are always refused, as is the `ISSUER` host by name. | > None of these falls back to the service token. Development (any `NODE_ENV` other than > `production`) uses a fixed development-only value for each unset one, with a warning. See > [docs/production-operations.md](./production-operations.md) for upgrading from a deployment > that relied on the fallback. +> The callout host rules have two gaps, both tracked in +> [issue #601](https://github.com/fells-code/seamless-auth-api/issues/601). The `ISSUER` host +> check compares names exactly, so a trailing dot (`auth.example.com.`) or another DNS name for +> the same server is not caught by it. And the two private-host lists are checked when a +> connection opens, but callouts and OAuth provider requests share Node's keep-alive connection +> pool, so a callout can reuse an open connection a provider request made to a host listed only +> in `OAUTH_PROVIDER_PRIVATE_HOSTS`. + ### Database Provide **either** a connection string (`DATABASE_URL`, or `DB_URI` as an alias) **or** the diff --git a/docs/security-posture.md b/docs/security-posture.md index 4ffd44fd..fbc33eb2 100644 --- a/docs/security-posture.md +++ b/docs/security-posture.md @@ -51,7 +51,8 @@ separated from every account that has one. It offers one fabricated credential i ### How a decoy is built Everything derives from one HMAC over the normalised identifier, keyed with -`DECOY_SUBJECT_SECRET` (falling back to `SEAMLESS_SERVICE_TOKEN`). That gives three +`DECOY_SUBJECT_SECRET`. Production refuses to start without it, and it never falls back to +`SEAMLESS_SERVICE_TOKEN` (see [configuration](./configuration.md)). That gives three properties: - **Stable.** The same unknown identifier yields the same subject every time. A real @@ -261,10 +262,18 @@ belongs to is refused rather than given a new window. Account recovery leans on is at least an hour, so completing a request always takes a new attempt that proves the channel again (see [Account recovery](account-recovery.md#coming-back-after-the-delay)). -Every continuation endpoint that accepts an ephemeral token is behind the -OTP, magic-link, or registration rate limiters, which are keyed per IP, per identity and attempt, -and per identity across attempts (see [Code and link sends per address](#code-and-link-sends-per-address)), -so replay cannot be used to generate OTPs in bulk. An ephemeral token also cannot be exchanged for anything +Every continuation endpoint that sends an OTP code or a magic link, or verifies a code, is behind +the OTP or magic-link rate limiters, which are keyed per IP, per identity and attempt, and per identity +across attempts (see [Code and link sends per address](#code-and-link-sends-per-address)), so +replay cannot be used to generate OTPs in bulk. Three endpoints that accept an ephemeral token +have only the global per-IP limiter: `POST /webauthn/login/start`, `POST /webauthn/login/finish` +and `GET /magic-link/check`. None of them sends a message. Each call to +`/webauthn/login/start` for an account with a passkey stores a new `webauthn_challenges` row +(the attempt's earlier challenge is marked spent, and no job deletes either), and for an +account with no usable passkey it records `login_failed`, which counts toward that account's +lockout. Moving them behind the flow +limiters is tracked in [issue #600](https://github.com/fells-code/seamless-auth-api/issues/600). +An ephemeral token also cannot be exchanged for anything on its own: it authorizes a continuation step that still requires the OTP code, the magic-link token, or a WebAuthn assertion. @@ -627,7 +636,8 @@ be read, the account is treated as locked (see [An unknown count means locked](# ## Code and link sends per address -**Posture: one attempt cannot spend or void another attempt's codes or links.** +**Posture: one attempt cannot spend another attempt's send allowance or void its magic links. +OTP codes are one per account and channel, so a new code from any attempt replaces the last.** The same thing that makes lockout a denial-of-service lever applies to message sends: `/login` mints an ephemeral token from an address alone, so anyone can start attempts for someone else's @@ -645,9 +655,16 @@ methods unavailable to the owner. 10; the magic link cap equals `magicLink.perIp`, so one location can just reach it. - **Links.** Requesting a magic link expires only earlier links from the same attempt. A link another attempt is waiting on stays usable until it expires or is used. - -What remains: a stranger with several network locations can still fill the per-address cap for the -window, and the owner then waits it out, as with lockout. Wrong codes from every attempt still +- **Codes.** An account holds one pending email code and one pending phone code, stored on the + user row ([`src/utils/otp.ts`](../src/utils/otp.ts)). Every send for that channel, from any + attempt, replaces it, so a code the owner received stops working as soon as someone else's + attempt sends another, and the owner has to request a new one. The per-attempt and + per-address limits above bound how often that can happen. Per-attempt codes are tracked in + [issue #600](https://github.com/fells-code/seamless-auth-api/issues/600). + +What remains: a stranger can void the owner's pending code with each send, up to the per-address +cap. A stranger with several network locations can fill that cap for the window, and the owner +then waits it out, as with lockout. Wrong codes from every attempt still count toward lockout together, because lockout is per account (see [Account lockout](#account-lockout)). ## Recovery codes and lockout @@ -906,7 +923,9 @@ Adding a factor needs proof as well. Passkey and TOTP enrollment, phone registra recovery code generation answer `403 step_up_required` until an account that already has a passkey or TOTP has stepped up, and `403 reauthentication_required` to an account with neither whose sign-in is more than five minutes old. A recovery session is exempt, since enrolling is -what it is for. Deleting a passkey (`DELETE /users/credentials`) also needs a fresh step-up. +what it is for. Deleting a passkey (`DELETE /users/credentials`) and deleting one's own account +(`DELETE /users/delete`) also need a fresh step-up, so an account with no passkey or TOTP cannot +delete itself; an administrator can. ### What is still accepted