Skip to content

fix(app): remove duplicate pre-parser mount of bypassRateLimit modules#1

Merged
azad-technext merged 1 commit into
mainfrom
fix/middleware-order-duplicate-mount
Jun 12, 2026
Merged

fix(app): remove duplicate pre-parser mount of bypassRateLimit modules#1
azad-technext merged 1 commit into
mainfrom
fix/middleware-order-duplicate-mount

Conversation

@azad-technext

Copy link
Copy Markdown
Member

The bypassRateLimit modules (/api/posts, /api/admin/posts) and globalLimiter were each mounted twice — once BEFORE express.json() and once after. Express dispatches to the first match, so every posts write hit the pre-parser copy with req.body === undefined, causing validate() to throw "expected object, received undefined" (400) on PATCH/POST/DELETE while reads worked fine.

Restore the single documented ordering: rawBody (auth) -> body parsers ->
bypassRateLimit -> globalLimiter -> regular modules. This also moves the auth catch-all above the global limiter again (it had been double-counted against the per-IP limit).

Verified against the live app: express.json (layer 8) now precedes the /api/posts (14) and /api/admin/posts (15) routers, with auth (7) above the parser.

The bypassRateLimit modules (/api/posts, /api/admin/posts) and globalLimiter
were each mounted twice — once BEFORE express.json() and once after. Express
dispatches to the first match, so every posts write hit the pre-parser copy
with req.body === undefined, causing validate() to throw
"expected object, received undefined" (400) on PATCH/POST/DELETE while reads
worked fine.

Restore the single documented ordering: rawBody (auth) -> body parsers ->
bypassRateLimit -> globalLimiter -> regular modules. This also moves the auth
catch-all above the global limiter again (it had been double-counted against
the per-IP limit).

Verified against the live app: express.json (layer 8) now precedes the
/api/posts (14) and /api/admin/posts (15) routers, with auth (7) above the
parser.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@azad-technext azad-technext merged commit d1d3c33 into main Jun 12, 2026
1 check failed
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