Skip to content

fix: rate limiting behind proxies, error leaks and test type-checks, release 1.1.1 - #3

Merged
SibilSoren merged 7 commits into
mainfrom
fix/template-safety
Nov 13, 2026
Merged

SibilSoren merged 7 commits into
mainfrom
fix/template-safety

Conversation

@SibilSoren

Copy link
Copy Markdown
Owner

Description

Five fixes to the generated project, mostly about what happens once it's deployed behind a load balancer, plus the 1.1.1 release.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 📝 Documentation update
  • 🔧 Refactor / chore
  • 💥 Breaking change

Changes Made

  • TRUST_PROXY. Generated apps trusted no proxy, so behind a load balancer req.ip was the load balancer's address and Gatekeeper counted every client together. I sent 105 requests from 105 different X-Forwarded-For addresses and the last 6 got 429. TRUST_PROXY takes a hop count or the proxies' addresses, defaults to 0 and refuses true.
  • Health check before Gatekeeper. Load balancer health checks shared the limit with user traffic. The health route now comes first and Gatekeeper right after it.
  • Non-operational errors in production. ApiError.internal('...') sent its message to the client. In production those now send only the status text.
  • Tests are type-checked. tsconfig.json now covers tests/, and the build uses tsconfig.build.json.
  • PORT has to be a whole number from 1 to 65535.
  • A README note about TRUST_PROXY and the 1.1.1 changelog entry.

CI also changed: it boots with TRUST_PROXY=1 and checks that one client over the limit gets 429 while a second client still gets through, and that the first client still gets 200 from the health check. The checks for missing rate limit headers use if ... exit 1 now, because a ! command in the middle of the script never failed the step.

Testing

  • I've tested the CLI tool locally (npx tsx src/index.ts test-project)
  • The generated project boots successfully (npm run dev)
  • The generated project's tests pass (npm test)
  • I've run npm run lint with no errors

Every commit passes lint, typecheck, tests and the build. At every commit, a project generated with and without Gatekeeper passes typecheck, build, tests with coverage, lint, the format check and the boot checks from ci.yml.

The new proxy check fails on a project generated from main (the second client gets 429), and the new error test fails against the old error handler. Docker isn't installed on my machine, so the image build is left to CI. The builder stage's files build fine on their own.

Checklist

  • My code follows the project's code style
  • I've updated documentation if needed
  • I've added an entry to CHANGELOG.md (if user-facing change)

Generated apps never set trust proxy, so behind a load balancer req.ip was
the load balancer's address. Gatekeeper then counted every client together,
and the whole service got 100 requests a minute.

TRUST_PROXY takes a hop count or the proxies' addresses. It defaults to 0
and refuses true, which would let any client pick its own IP. CI now checks
that two clients behind a proxy get separate limits.
Gatekeeper was added above /api/health, so a load balancer's health checks
shared the limit with user traffic, and a busy minute could mark healthy
servers as down. The health check now comes first and Gatekeeper right
after it.

CI checks that a client over the limit still gets 200 from the health
check. The checks for missing rate limit headers now use if and exit,
because a negated command in the middle of a script doesn't fail the step.
Unknown errors were already replaced with "Internal Server Error" in
production, but an ApiError sent its message as is, even one marked
non-operational, like ApiError.internal(). A message such as "Query failed
on postgres://user:pass@..." went straight to the client.

In production a non-operational ApiError now sends only the status text.
Operational errors keep their message, and nothing changes outside
production.
tsconfig.json left out tests/, and Vitest strips types without checking
them, so a type error in a test passed both "npm run typecheck" and CI.

tsconfig.json now covers src/ and tests/ for type-checking and editors, and
the build uses tsconfig.build.json, which compiles only src/. The Dockerfile
copies both.
PORT took any positive number, so 3000.5 or 99999 passed validation and
failed later when the server tried to listen. It now has to be a whole
number from 1 to 65535, and anything else stops the app at startup with
the usual env error.
@SibilSoren
SibilSoren merged commit 76cf585 into main Nov 13, 2026
14 checks passed
@SibilSoren
SibilSoren deleted the fix/template-safety branch November 17, 2026 07:31
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.

1 participant