Repository navigation
fix: validate pack POSTs before buffering and cap body size (bug) - #48
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
Run the User-Agent/Accept/URL checks and the repository allow-list lookup before reading any pack request body, buffer at most maxPackSizeBytes (default 100 MiB) and reject larger bodies with 413. Read the body directly from the request and replay it to the upstream proxy so backpressure no longer stalls pack requests larger than the PassThrough buffers. Remediates code scan finding sfind-9fb894441f914d5095e932af8d0ab90e.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
| "maxPackSizeBytes": { | ||
| "type": "number", | ||
| "description": "Maximum size in bytes of a git-upload-pack or git-receive-pack request body that the proxy will buffer for inspection. Larger requests are rejected with HTTP 413 (default 104857600, i.e. 100 MiB)." | ||
| }, |
There was a problem hiding this comment.
🟡 Pack-size setting missing from schema reference
Adding maxPackSizeBytes leaves the generated website reference unchanged, despite the repository's required schema documentation update. Readers cannot discover the configurable limit there.
Learn more
The website's schema reference is generated from the JSON schema. Contributing guidance requires regenerating it whenever a configuration property changes. The new property has no entry in the existing reference, leaving the public setting and its default undocumented there.
Example: An operator consulting the website schema reference after encountering HTTP 413 cannot find maxPackSizeBytes or its default value.
Recommended fix: Run npm run gen-schema-doc and commit the resulting update to the website reference with the schema change.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Agreed this should be regenerated. npm run gen-schema-doc couldn't run in my environment: npm and pip registries are unreachable, so json-schema-for-humans isn't installed. Editing reference.mdx by hand would mean renumbering every section after rateLimit, which the generator should do instead. I'm leaving this thread open so the docs get regenerated before merge. It's flagged as an unchecked item in the PR checklist.
Reuse parseAction and checkRepoInAuthorisedList for the early repository check and write the audit record for rejected non-pull actions, matching what the action chain recorded before.
| const action = await checkRepoInAuthorisedList(req, await parseAction(req)); | ||
| if (!action.continue()) { | ||
| // keep the audit record the action chain would have written, without reading the body | ||
| await audit(req, action); |
There was a problem hiding this comment.
🟨 Unauthenticated denials exhaust audit storage
An unauthenticated client can send bodyless git-receive-pack requests for unknown repositories to trigger audit writes. Each request gets a timestamp ID, so repeated denials grow the persistent pushes store without a body-size cost.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
The behavior exists, but this PR doesn't introduce it. On main, a bodyless git-receive-pack POST to an unknown repo already went through executeChain, failed checkRepoInAuthorisedList, and was written by audit with a timestamp ID. This PR keeps that audit record, which the earlier review in this PR asked for. It just no longer buffers the body first.
The two possible changes pull in opposite directions:
- Stop auditing rejected pushes: closes the storage path but loses the audit trail.
- Rate-limit the proxy router:
rateLimitcurrently applies only to the management service insrc/service/index.ts, not the proxy app. Adding it would be a behavior change for every Git client.
Both need a maintainer decision, so I'm leaving behavior unchanged here and flagging it for whoever owns the policy.
Description
Fixes code-scan finding
sfind-9fb894441f914d5095e932af8d0ab90e:extractRawBody(the first router middleware) read every pack POST body (up tolimit: '1gb') before any request validation ran.Changes in
src/proxy/routes/index.ts(extractRawBody):processUrlPath+validGitRequest(User-Agent / Accept), then the existingparseAction+checkRepoInAuthorisedListprocessors (no body needed). Rejected requests get the usual git error packet viasendErrorResponse(connection: close) and the body is never read. Rejected non-pull actions are still written through the existingauditpost-processor, so audit history is unchanged.maxPackSizeBytesconfig key, read throughgetMaxPackSizeBytes()insrc/config/index.ts. The default is 100 MiB (DEFAULT_MAX_PACK_SIZE_BYTES), in line with the existinglimit: '100000kb'. A declaredContent-Lengthabove the cap gets 413 straight away. A chunked body that goes over the cap while streaming also gets 413.reqwas piped into bothproxyStreamandpluginStream. Nothing readsproxyStreamuntilgetRawBodyfinishes, soreqpaused once roughly 15 MB had arrived and the request hung forever. That hit both valid pushes over about 15 MB and attacker connections. The body is now read straight fromreq, and the buffer is replayed to the upstream proxy through the overriddenreq.pipe.Config surface: this adds the optional
maxPackSizeBytestop-level key. Existing configs are unaffected.Not included: a per-IP limit on concurrent in-flight pack requests (the scan suggested considering one). That is a separate design choice, and an operator would more likely put it in the reverse proxy / ingress.
Before/after harness (real
getRouter()on a real HTTP socket; chain/db/config mocked, upstream stubbed to count the bytes it receives)mainContent-Length: 200MBRelated Issue
Code scan finding
sfind-9fb894441f914d5095e932af8d0ab90e(scanscan-70082f73b42b43fda8ae0a7ecbe7fedf).Checklist
General
Documentation
config.schema.json)Configuration
config.schema.json) was modified:src/config/generated/config.tsby hand to match quicktype output. The npm registry was unreachable from the dev box, so the generator couldn't run.npm run gen-schema-doc): not run, same reasonTests
test/extractRawBody.test.ts(pre-validation, audit of rejected pushes, 413 paths, configured limit, body replay) andtest/testProxyRoute.test.ts(HTTP-level bad UA / unregistered repo)npm test):test/extractRawBody.test.tspasses locally (14/14). The full suite andtest/testProxyRoute.test.tswere not run locally because dependencies couldn't be installed, so this relies on CI.npm run lintnot run locally.npm run check-types): not run locally, relies on CIDevin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/5d9ba3020bbf49ac9b1607243a5a2d9c
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/5d9ba3020bbf49ac9b1607243a5a2d9c?variant=devin
Devin Review