Skip to content

Fix silent truncation of large npm metadata responses#79

Open
andrew wants to merge 2 commits intomainfrom
fix-metadata-size-limit
Open

Fix silent truncation of large npm metadata responses#79
andrew wants to merge 2 commits intomainfrom
fix-metadata-size-limit

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 8, 2026

ReadMetadata used io.LimitReader which silently truncated responses at the size limit. For packages like drizzle-orm (~92MB metadata), this produced invalid JSON that was served to clients.

The truncated body would fail json.Unmarshal in rewriteMetadata, then the fallback path would write the truncated bytes directly to the response, giving npm clients Unterminated string in JSON at position 52428800.

Two fixes:

  • ReadMetadata now returns ErrMetadataTooLarge when the response exceeds the limit instead of silently truncating. Limit bumped from 50MB to 100MB.
  • When cooldown is disabled, requests use application/vnd.npm.install-v1+json (npm's abbreviated metadata format). This drops drizzle-orm from 92MB to 4MB by stripping READMEs and other bulk data. Falls back to full metadata when cooldown is enabled since the abbreviated format lacks the time map needed for publish-date filtering.

Fixes #78

ReadMetadata used io.LimitReader which silently truncated responses at
the size limit. For packages like drizzle-orm (~92MB metadata), this
produced invalid JSON that was served to clients.

Now returns ErrMetadataTooLarge when the limit is exceeded, and bumps
the limit from 50MB to 100MB.

Fixes #78
Request application/vnd.npm.install-v1+json from the npm registry
when cooldown filtering is not enabled. This format strips READMEs
and other bulk data, reducing drizzle-orm metadata from 92MB to 4MB.

Fall back to full metadata when cooldown is enabled since the
abbreviated format lacks the time map needed for publish-date filtering.
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.

Issue installing npm package drizzle-orm

1 participant