Skip to content

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

Open
simonchrz wants to merge 3 commits into
git-pkgs:mainfrom
simonchrz:fix/api-bulk-limits
Open

simonchrz wants to merge 3 commits into
git-pkgs:mainfrom
simonchrz:fix/api-bulk-limits

Conversation

@simonchrz

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.

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 3f65a5dc-4f79-431a-9e59-a5d3fc98aa68
Commits

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

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
  • 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

@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.

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.
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