Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions docs/account-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/adr/0005-extensibility-callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 19 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading