Skip to content

fix(config): refuse weak or default service tokens in production - #618

Merged
Bccorb merged 1 commit into
mainfrom
fix/refuse-weak-service-token
Nov 23, 2026
Merged

Bccorb merged 1 commit into
mainfrom
fix/refuse-weak-service-token

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #599. Part of #603.

Problem

SEAMLESS_SERVICE_TOKEN is the raw HS256 key for service tokens, and boot required only that it be non-empty. A production deployment that kept the published docker-compose.yml default, local-development-service-token-not-for-deployment, or any short value would boot. Anyone who knew or guessed the value could then call the API as a trusted adapter.

Change

With NODE_ENV=production, the server refuses to start when the resolved service token (SEAMLESS_SERVICE_TOKEN, or the API_SERVICE_TOKEN fallback) is:

  • shorter than 32 bytes (UTF-8 byte length, after the same trim the middleware applies), or
  • a published default or placeholder: the values that have shipped in this repo's compose files and example, the CLI verify stack, the templates and the adapter README, plus the markers replace-me, not-for-deployment, not-a-real-secret and changeme, compared case-insensitively.

This mirrors assertSecretStrength in seamless-auth-server packages/core/src/validateSecrets.ts: the same 32 minimum, an explicit list of shipped values, and a marker match.

Where it applies:

  • assertServiceTokenStrength in src/config/serviceToken.ts, called from assertServiceTokenConfig, which runs first in startServer. It checks the value returned by resolveServiceToken, the same function the service-token middleware reads its key from, so the checked value and the signing key cannot differ.
  • validateEnvs.sh runs the same check before migrations, so a misconfigured container stops before it touches the database. The comment there says to keep the two lists in step.

The error names the variable and the reason, never the value, and points to openssl rand -base64 48.

Development and test runs are unchanged. Both compose files run NODE_ENV=development, the CLI verify stack does too, and development mode is already refused off localhost unless SEAMLESS_ALLOW_INSECURE_DEV is set.

Breaking change

A production deployment that kept one of these values will stop booting after the upgrade. The minor changeset says this and gives the rotation step: set a new token on the API and on every server adapter that calls it.

Tests and checks

New cases in tests/unit/config/serviceToken.spec.ts cover: a short token refused, bytes counted rather than characters, every shipped default of 32 characters or more refused, the legacy name reported correctly, markers matched in any case, a strong token accepted, an unset token left to the presence checks, and development or test values accepted.

validateEnvs.sh was exercised by hand with NODE_ENV=production. A short value, the compose default and GRAB_FROM_SEAMLESS_AUTH_PORTAL_DEV through API_SERVICE_TOKEN each exit with the expected message. A value from openssl rand -base64 48 passes on to the next check. With NODE_ENV=development, a short value is accepted.

npm run typecheck, npm run lint, npm run format:check, npm run test:run (195 files, 3452 tests), npm run coverage (lines 99.28%, branches 95.82%) and npm run check:changeset-bump pass. A security review of the diff found nothing.

Docs

docs/configuration.md and docs/production-operations.md describe the refusal. The docker-compose.yml comment now says the default is refused in production. The comment it replaces described a fallback from other secrets to the service token, which no longer exists.

SEAMLESS_OIDC_SERVICE_TOKEN is out of scope for #599 and is left unchanged.

With NODE_ENV=production, boot and validateEnvs.sh refuse a
SEAMLESS_SERVICE_TOKEN (or API_SERVICE_TOKEN) shorter than 32 bytes or
equal to a published default such as the docker-compose.yml value.

Closes #599.
@Bccorb
Bccorb merged commit 45530a8 into main Nov 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(config): refuse weak or default SEAMLESS_SERVICE_TOKEN values in production

1 participant