Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/outbound-call-isolation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'seamless-auth-api': patch
---

Callouts and OAuth provider requests each open a connection of their own instead of sharing Node's keep-alive pool, so the connect-time checks for `CALLOUT_PRIVATE_HOSTS` and `OAUTH_PROVIDER_PRIVATE_HOSTS` always run for the request they guard. A callout host is now compared with the `ISSUER` host without case or a trailing dot, and a callout to a private or loopback address and port the `ISSUER` host resolves to is refused as pointing at the API itself. The version on `/health/version` and the adapter manifest stays public; `docs/security-posture.md` records why.
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, 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)).
- `https` only in production, no userinfo, and not the API itself. The host is compared with the `ISSUER` host without case or a trailing dot, and at connect time a host that resolves to a private or loopback address the `ISSUER` host also resolves to, on the `ISSUER` port, or to loopback on the port the API listens on, is refused, which catches another name for the same server ([#601](https://github.com/fells-code/seamless-auth-api/issues/601)). Public addresses are not compared (decided 2026-12-04): edge networks and load balancers put unrelated sites on one public address, so a match there would refuse receivers that are not this server, and a public address reaches only what any client on the internet reaches.
- 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 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).
- 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, and every callout and OAuth provider request opens a connection of its own rather than taking one from Node's global keep-alive pool, which is keyed by destination and not by the lookup that checked it. A callout therefore never reuses a connection a provider request opened to a host listed only in `OAUTH_PROVIDER_PRIVATE_HOSTS` ([#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
40 changes: 22 additions & 18 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,34 @@ 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. 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. |
| 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 are the `ISSUER` host and the private addresses it resolves to (see the note below). |

> 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`.
> A callout never points at the API itself. Its host is refused when it names the `ISSUER` host,
> compared without case or a trailing dot (`auth.example.com.`), and at connect time when it
> resolves to a private or loopback address that the `ISSUER` host also resolves to, on the
> `ISSUER` port, which catches another name for the same server. Loopback counts as one address,
> and loopback on the port the API listens on (`PORT`) is always refused. Behind a proxy that
> terminates TLS, the API's own private address on another port is not recognised, so do not list
> it in `CALLOUT_PRIVATE_HOSTS`. Public addresses are not compared, since edge networks
> and load balancers share them between unrelated sites. The two private-host lists stay separate
> at connect time too: callouts and OAuth provider requests each open a connection of their own
> rather than sharing a keep-alive pool, so a callout never reuses a connection a provider request
> opened to a host listed only in `OAUTH_PROVIDER_PRIVATE_HOSTS`.

### Database

Expand Down
20 changes: 20 additions & 0 deletions docs/security-posture.md
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,26 @@ The event is written server side and never reflected to the caller. The refusal
the same `401 { "error": "unauthorized" }` whether or not a row is written, so the decoy
rules above are untouched.

## Version and route map

`GET /health/version` and `/.well-known/seamless-adapter.json` answer without
credentials in every mode, and both name the running release. This is accepted
(decided 2026-12-04,
[#601](https://github.com/fells-code/seamless-auth-api/issues/601)).

The adapter manifest has to stay public: server adapters fetch it before they hold
any credential, to learn which routes to proxy and with which token. Its route map
already narrows the release to a range, so hiding `/health/version` alone would not
hide the version, and the operator checklist reads `/health/version` on a fresh
deployment to confirm which release is running. The source and the security
advisories are public, so the version tells a reader which published fixes a
deployment has, and nothing about its configuration or data.

What keeps an older release safe is upgrading it, not hiding its number. A
deployment that does not want either endpoint reachable from the internet can block
`/health/version` at its reverse proxy and serve the manifest only to its own server
adapters.

## Static analysis triage

**Posture: gated on a zero baseline, deliberately.** CodeQL runs on every pull request,
Expand Down
17 changes: 6 additions & 11 deletions src/lib/auditSinkTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AUDIT_SINK_SECRET_ENV_PATTERN } from '@seamless-auth/types';
import { type ExportedAuthEvent, exportLine } from '../services/auditExport.js';
import { authEventOutcome } from './authEventCategories.js';
import {
assertCalloutAddress,
CalloutError,
calloutHostProblem,
calloutLookup,
Expand Down Expand Up @@ -253,25 +254,19 @@ function tlsMaterial(settings: SyslogSinkSettings, env: EnvSource) {
* Writes every frame on one connection, ends it, and resolves once the collector closes its
* side. Syslog has no acknowledgement, so that is as much as a sender can know.
*/
function writeSyslog(
async function writeSyslog(
settings: SyslogSinkSettings,
payload: string,
env: EnvSource,
timeoutMs: number,
): Promise<void> {
const destination = destinationProblem(settings, env);
if (destination) {
return Promise.reject(
new CalloutError(destination.failure, `Audit sink ${destination.problem}`),
);
throw new CalloutError(destination.failure, `Audit sink ${destination.problem}`);
}

let material: ReturnType<typeof tlsMaterial>;
try {
material = tlsMaterial(settings, env);
} catch (error) {
return Promise.reject(error);
}
const material = tlsMaterial(settings, env);
await assertCalloutAddress(settings.host, settings.port, env);

return new Promise((resolve, reject) => {
let settled = false;
Expand All @@ -285,7 +280,7 @@ function writeSyslog(
};

const send = () => socket.end(payload);
const lookup = calloutLookup(env);
const lookup = calloutLookup(env, settings.port);
const socket: Socket =
settings.transport === 'tls'
? tlsConnect(
Expand Down
Loading