fix(config): validate numeric env vars at boot; default Swagger off in production - #402
Merged
Conversation
…n production - env.validation now rejects a non-integer RATE_LIMIT_*/WEBHOOK_*/DATABASE_POOL_SIZE value at boot (a NaN previously slipped through parseInt and silently disabled the corresponding rate-limit/timeout), mirroring the existing port validation. - isSwaggerEnabled now factors in NODE_ENV: an explicit ENABLE_SWAGGER still wins, but when unset it defaults on outside production and OFF in production (the API schema is reconnaissance surface). The startup banner only prints the docs URL when served.
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.
Summary
Two small production-hardening fixes.
Validate numeric env vars at boot
The rate-limit windows/limits (
RATE_LIMIT_*), webhookWEBHOOK_TIMEOUT/WEBHOOK_MAX_RETRIES/WEBHOOK_RETRY_DELAY, andDATABASE_POOL_SIZEwere read with an unboundedparseInt. A non-integer value (e.g.RATE_LIMIT_SHORT_LIMIT=abc) becameNaNand silently disabled the corresponding limit.validateEnvnow rejects a non-negative-integer violation at boot with a clear message, mirroring the existingPORT/DATABASE_PORT/REDIS_PORTchecks. Unset vars and valid integers are unaffected.Swagger off by default in production
/api/docsserved the full API schema unauthenticated by default in every environment — reconnaissance surface.isSwaggerEnablednow factors inNODE_ENV: an explicitENABLE_SWAGGERstill wins ('true'/'false'); when unset it defaults on outside production, off in production. Operators who want it in production opt in withENABLE_SWAGGER=true. The startup banner only prints the docs URL when Swagger is actually served.Tests
env.validation.spec.ts: rejects non-integer/negative/decimal rate-limit, webhook, and pool-size values; valid integers and unset still pass.bootstrap-security.spec.ts: production defaults off, explicittruestill on, dev unchanged.Risk
Low. The env validation only rejects already-misconfigured (NaN-producing) values. The Swagger default flip is a behavior change for operators who relied on
/api/docsin production without settingENABLE_SWAGGER— they setENABLE_SWAGGER=true. Dev/test default unchanged (so e2e and local docs still work).