Repository navigation
fix(server): read /track's body only with its own 64 KB parser, after its limiter - #1533
Merged
Merged
Conversation
… its limiter The tracking routes were mounted after the server-wide JSON and form parsers (50 MB), so an application/json post to /track was read in full before the route's limiter and its 64 KB cap applied. They now come before those parsers: the limiter runs first, and the route reads every body type as text, up to 64 KB.
7 of 12 tasks
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
The public tracking routes (
/t.js,/track/:code) now come before the server-wide JSON and form parsers inserver.js.Before:
application/jsonpost to/trackwas read by the server-wide parser, with its 50 MB limit, before the route's own limiter and its 64 KB text reader applied.Now:
beaconBodyreads every body as text,text/plainandapplication/jsonalike, up to 64 KB. The handler already parses a string body.t.js(text/plain) and older or directapplication/jsoncallers are read the same way as before, from the route's own parser.Found while reviewing #1527, which adds new event kinds to this route.
Related issue
None. A follow-up to the #1527 review.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
npm testinserver/.src/routes/traffic-track.test.jschecks two things:application/jsonbeacon is read by the route itself;text/plainand asapplication/json.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — not applicable, server onlyyarn typecheckpasses (run fromweb/) — not applicable, server onlyyarn format:checkpasses (run fromweb/) — not applicable, server onlyServer: format, lint and
npm test(2,746 passed) pass.🤖 Generated with Claude Code