chore(env): tighten DB_PORT parsing to non-zero finite integers#293
Merged
Conversation
Same parseInt-leniency class fixed for \`PORT\` in #124. The line was \`port: parseInt(process.env.DB_PORT, 10) || 5432\`, which means \`DB_PORT="5432abc"\` (typo) silently becomes 5432 — the operator gets the default port without knowing their value was rejected. Guard with Number.isFinite + > 0 so only NaN and non-positive values fall through. (Unlike server.js's PORT where 0 is a valid "kernel pick a free port" sentinel, DB_PORT=0 wouldn't actually connect — postgres doesn't listen on 0 — so > 0 is the right floor here.) No behavior change for sane DB_PORT values. 761 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones
added a commit
that referenced
this pull request
May 19, 2026
#293 tightened DB_PORT parsing to non-zero finite integers — only NaN / negative / zero values fall through to the 5432 default. Existing env-validation tests covered the DB_PASSWORD empty-warn path but not the port logic, so the new behavior had no regression pin. Added 6 test cases via spawnSync into a child node process that prints env.port to stdout: - valid integer parsed verbatim ("5433" → 5433) - missing → default (5432) - garbage non-numeric → default - parseInt-typo "5433abc" → 5433 (documents the guard's exact reach: Number.isFinite passes here because parseInt returns a finite number, just one without the trailing chars) - "0" → default (postgres doesn't listen on 0) - negative → default Test count: 761 → 767. All passing. Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 19, 2026
CryptoJones
added a commit
that referenced
this pull request
May 19, 2026
Same parseInt-leniency footgun as PORT (#124) and DB_PORT (#293): `parseInt('100abc', 10)` returns 100, so a typo'd `RATE_LIMIT_MAX=1abc` silently sets max=1 — a near-total block on /v1/* — instead of falling back to the documented default of 100. The operator would only notice this after every legitimate client started seeing 429s. Add a `strictParseIntEnv(raw)` helper that pre-validates the raw string against `^-?\d+$` before parseInt. Anything else returns NaN so the existing `Number.isFinite + > 0` fallback below picks the default. Apply to both `RATE_LIMIT_MAX` and `RATE_LIMIT_WINDOW_MS`. No test added — the helper is module-private and the existing server-boots smoke test doesn't drive env-permutation paths. The unit-test-equivalent coverage lives in `tests/unit/env-validation.test.js` for the DB_PORT case (#293); a future env-validation expansion can fold these in. Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Same parseInt-leniency class fixed for
PORTin #124. The line was:which means
DB_PORT="5432abc"(typo) silently becomes 5432 — the operator gets the default port without knowing their value was rejected. Same shape was a real bug forPORT=0(kernel-pick-a-free-port → 3000) and got fixed there; carrying the same guard toDB_PORTremoves the typo-eats-your-config footgun for DB connectivity.What changed
Replaced the falsy-fallback with
Number.isFinite + > 0. Note: unlike server'sPORTwhere 0 is a valid sentinel,DB_PORT=0wouldn't actually connect (postgres doesn't listen on port 0), so> 0is the right floor here.Test plan
npm run lint && npm test— 761 passing.DB_PORTvalue.Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/