Fix silent truncation of large npm metadata responses#79
Open
Fix silent truncation of large npm metadata responses#79
Conversation
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.
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.
ReadMetadatausedio.LimitReaderwhich silently truncated responses at the size limit. For packages likedrizzle-orm(~92MB metadata), this produced invalid JSON that was served to clients.The truncated body would fail
json.UnmarshalinrewriteMetadata, then the fallback path would write the truncated bytes directly to the response, giving npm clientsUnterminated string in JSON at position 52428800.Two fixes:
ReadMetadatanow returnsErrMetadataTooLargewhen the response exceeds the limit instead of silently truncating. Limit bumped from 50MB to 100MB.application/vnd.npm.install-v1+json(npm's abbreviated metadata format). This dropsdrizzle-ormfrom 92MB to 4MB by stripping READMEs and other bulk data. Falls back to full metadata when cooldown is enabled since the abbreviated format lacks thetimemap needed for publish-date filtering.Fixes #78