Skip to content

Cap the entries of an outdated or bulk request and require JSON - #794

Merged
andrew merged 4 commits into
git-pkgs:mainfrom
simonchrz:fix/api-bulk-limits
Nov 23, 2026
Merged

andrew merged 4 commits into
git-pkgs:mainfrom
simonchrz:fix/api-bulk-limits

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

POST /api/outdated and POST /api/bulk were limited only by the 1 MB body, about 30,000 entries. Each entry is looked up at its registry, one after the other, uncached and from the proxy's address, so a few requests could keep the proxy busy for minutes and get its address rate-limited upstream.

Neither endpoint checked the content type either, so a page on another site could send such a request to an internal proxy through a visitor's browser with a text/plain POST.

  • A request may name at most 1000 packages or PURLs; more is a 400 that says so.
  • Both endpoints now require Content-Type: application/json, as /api/mirror does, and answer 415 otherwise.

A client that posted JSON without the header now gets a 415. The README examples already send it.

Summary by CodeRabbit

  • API Updates
    • Requests to the outdated-package and bulk endpoints must use application/json; unsupported content types receive a 415 response. JSON requests with a charset are accepted.
    • The outdated-package endpoint accepts up to 100 entries per request, and the bulk endpoint accepts up to 1,000 PURLs. Requests exceeding these limits receive a 400 response.
    • Both endpoints continue to limit request bodies to 1 MiB and return a 400 response for oversized bodies or invalid JSON.
  • Documentation
    • Updated API documentation with request limits and unsupported-media-type responses.

One request could name about 30,000 packages, each looked up at its
registry, and a page on another site could send it through a visitor's
browser.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The outdated and bulk endpoints now require JSON requests and enforce body and entry limits. The mirror creation handler uses the shared JSON parser. The README and Swagger documentation describe the lookup endpoints’ request requirements and responses.

Changes: Request validation

Layer / File(s) Summary
Lookup request validation
internal/server/api.go, internal/server/api_limits_test.go, internal/server/api_test.go, docs/swagger/docs.go, docs/swagger/swagger.json, README.md
The outdated and bulk endpoints use shared JSON parsing, retain the 1 MiB body limit, and reject requests over 100 packages or 1,000 PURLs. Tests cover the limits and content types. The README and Swagger documentation describe the requirements and 415 responses.
Mirror handler parsing
internal/server/mirror_api.go
HandleCreate delegates request-body parsing to the shared JSON parser.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested labels: breaking

Suggested reviewers: andrew

Merge Risk: Minimal · up to e758f

This change adds request-size and JSON content-type requirements to the outdated and bulk lookup endpoints, and the mirror creation handler now uses the shared JSON parser. Clients that post JSON without the Content-Type header will now receive a 415, which is documented. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: capping entries in outdated and bulk requests, and requiring JSON content type. The raw summary and objectives confirm both (100-entry cap for outdated, 1,000-PUR…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: capping entries in outdated and bulk requests, and requiring JSON content type. The raw summary and objectives confirm both (100-entry cap for outdated, 1,000-PURL cap for bulk, 415 for non-JSON requests). The title is specific, though it omits the exact limit values, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8215b1a8-abf1-4a41-af4b-be92875e6bb6
Commits

Reviewing files that changed from the base of the PR and between 784ba61 and e758f5a.

Files selected for processing: 7

  • README.md
  • docs/swagger/docs.go
  • docs/swagger/swagger.json
  • internal/server/api.go
  • internal/server/api_limits_test.go
  • internal/server/api_test.go
  • internal/server/mirror_api.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@simonchrz simonchrz added the bug Something isn't working label Nov 21, 2026

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cap and the content-type check are both right, and the 415 for clients that post without the header is an accepted break. Three things inline before this goes in.

Comment thread internal/server/api.go
@@ -394,17 +417,19 @@ func (h *APIHandler) HandleVulnsPath(w http.ResponseWriter, r *http.Request) {
// @Failure 500 {object} ErrorResponse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler and HandleBulkLookup can now answer 415, but the annotations only list 400 and 500. Add // @Failure 415 {object} ErrorResponse to both and regenerate docs/swagger.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dbd62f6, with docs/swagger regenerated.

Comment thread internal/server/api.go Outdated
// content type cross-origin after a CORS preflight, which the proxy never
// answers, so requiring it stops other sites from sending lookups through a
// visitor's browser.
func readLookupRequest(w http.ResponseWriter, r *http.Request, req any) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MirrorAPIHandler.HandleCreate in mirror_api.go now has the same ten lines as this helper, CORS comment included. Give the helper a general name such as readJSONRequest, call it from HandleCreate too, and keep the CORS explanation once here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dbd62f6: it's readJSONRequest now, HandleCreate uses it, and the CORS note is only on the helper.

Comment thread internal/server/api.go Outdated
maxBodySize = 1 << 20 // 1 MB
// maxLookupEntries is how many packages one outdated or bulk request
// may name: each is looked up at its registry.
maxLookupEntries = 1000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HandleOutdated still does its lookups one after another, so 1000 of them have to average under 300ms each to finish inside the default 5m write_timeout. Either lower the cap to a size where a full request finishes comfortably inside the timeout, or say why 1000 is the right number.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowered outdated to 100 in dbd62f6, which leaves 3s per lookup inside the default write_timeout. Bulk stays at 1000: it's one ecosyste.ms request, or 15 registry lookups at a time without it, so over 4s per round. Both reasons are in the comments on the constants.

simonchrz and others added 3 commits November 22, 2026 10:40
Outdated looks its packages up one after another, so 1000 of them could
run past the default write_timeout. HandleCreate now reads its body with
the same helper, and the swagger docs list the 415.
@andrew
andrew merged commit 66d7e4a into git-pkgs:main Nov 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants