Repository navigation
Conversation
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.
|
Warning Review limit reachedYou'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. View limit details
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. |
andrew
left a comment
There was a problem hiding this comment.
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.
| @@ -394,17 +417,19 @@ func (h *APIHandler) HandleVulnsPath(w http.ResponseWriter, r *http.Request) { | |||
| // @Failure 500 {object} ErrorResponse | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done in dbd62f6, with docs/swagger regenerated.
| // 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done in dbd62f6: it's readJSONRequest now, HandleCreate uses it, and the CORS note is only on the helper.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
POST /api/outdatedandPOST /api/bulkwere 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/plainPOST.Content-Type: application/json, as/api/mirrordoes, and answer 415 otherwise.A client that posted JSON without the header now gets a 415. The README examples already send it.