Repository navigation
fix(config): refuse weak or default service tokens in production - #618
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #599. Part of #603.
Problem
SEAMLESS_SERVICE_TOKENis the raw HS256 key for service tokens, and boot required only that it be non-empty. A production deployment that kept the publisheddocker-compose.ymldefault,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 theAPI_SERVICE_TOKENfallback) is:replace-me,not-for-deployment,not-a-real-secretandchangeme, compared case-insensitively.This mirrors
assertSecretStrengthin seamless-auth-serverpackages/core/src/validateSecrets.ts: the same 32 minimum, an explicit list of shipped values, and a marker match.Where it applies:
assertServiceTokenStrengthinsrc/config/serviceToken.ts, called fromassertServiceTokenConfig, which runs first instartServer. It checks the value returned byresolveServiceToken, the same function the service-token middleware reads its key from, so the checked value and the signing key cannot differ.validateEnvs.shruns 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 unlessSEAMLESS_ALLOW_INSECURE_DEVis set.Breaking change
A production deployment that kept one of these values will stop booting after the upgrade. The
minorchangeset 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.tscover: 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.shwas exercised by hand withNODE_ENV=production. A short value, the compose default andGRAB_FROM_SEAMLESS_AUTH_PORTAL_DEVthroughAPI_SERVICE_TOKENeach exit with the expected message. A value fromopenssl rand -base64 48passes on to the next check. WithNODE_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%) andnpm run check:changeset-bumppass. A security review of the diff found nothing.Docs
docs/configuration.mdanddocs/production-operations.mddescribe the refusal. Thedocker-compose.ymlcomment 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_TOKENis out of scope for #599 and is left unchanged.