Skip to content

fix(server): read /track's body only with its own 64 KB parser, after its limiter - #1533

Merged
gkhngyk merged 1 commit into
mainfrom
fix/track-body-before-global-parser
Oct 26, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/track-body-before-global-parser

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

The public tracking routes (/t.js, /track/:code) now come before the server-wide JSON and form parsers in server.js.

Before:

  • They were mounted after those parsers.
  • So an application/json post to /track was read by the server-wide parser, with its 50 MB limit, before the route's own limiter and its 64 KB text reader applied.
  • The route's comment relied on that.

Now:

  • The tracking limiter runs first.
  • beaconBody reads every body as text, text/plain and application/json alike, up to 64 KB. The handler already parses a string body.
  • Beacons from today's t.js (text/plain) and older or direct application/json callers 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  • npm test in server/. src/routes/traffic-track.test.js checks two things:
    • an application/json beacon is read by the route itself;
    • a body over 64 KB answers 413, both as text/plain and as application/json.
  • After the API deploy, the AI Traffic snippet keeps recording visits as before.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — not applicable, server only
  • yarn typecheck passes (run from web/) — not applicable, server only
  • yarn format:check passes (run from web/) — not applicable, server only
  • Changes are focused — one concern per PR

Server: format, lint and npm test (2,746 passed) pass.

🤖 Generated with Claude Code

… 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.
@gkhngyk
gkhngyk merged commit ced91f8 into main Oct 26, 2026
6 checks passed
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