Skip to content

fix: validate pack POSTs before buffering and cap body size (bug) - #48

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/sfind-9fb89444-pack-body-validate-first
Open

devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/sfind-9fb89444-pack-body-validate-first

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Description

Fixes code-scan finding sfind-9fb894441f914d5095e932af8d0ab90e: extractRawBody (the first router middleware) read every pack POST body (up to limit: '1gb') before any request validation ran.

Changes in src/proxy/routes/index.ts (extractRawBody):

  • Cheap checks first. Before touching the body: processUrlPath + validGitRequest (User-Agent / Accept), then the existing parseAction + checkRepoInAuthorisedList processors (no body needed). Rejected requests get the usual git error packet via sendErrorResponse (connection: close) and the body is never read. Rejected non-pull actions are still written through the existing audit post-processor, so audit history is unchanged.
  • Configurable cap. New optional maxPackSizeBytes config key, read through getMaxPackSizeBytes() in src/config/index.ts. The default is 100 MiB (DEFAULT_MAX_PACK_SIZE_BYTES), in line with the existing limit: '100000kb'. A declared Content-Length above the cap gets 413 straight away. A chunked body that goes over the cap while streaming also gets 413.
  • Backpressure stall fixed. Previously req was piped into both proxyStream and pluginStream. Nothing reads proxyStream until getRawBody finishes, so req paused 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 from req, and the buffer is replayed to the upstream proxy through the overridden req.pipe.

Config surface: this adds the optional maxPackSizeBytes top-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)

Case main this branch
bad User-Agent, 300 MB chunked hangs (stalled after ~13 MB, no response in 60 s) rejected after ~3 MB on the socket, "Invalid request received", ~65 ms
unregistered repo, 300 MB chunked hangs rejected, "Rejecting repo not in the authorised whitelist"
Content-Length: 200MB hangs 413 before the body is read
registered repo, 150 MB chunked hangs 413 at the 100 MiB cap
registered repo, 1.1 GB chunked hangs 413 at the 100 MiB cap
registered repo, 50 MB chunked (valid) hangs at ~15 MB forwarded, upstream got all 52,428,800 bytes

Related Issue

Code scan finding sfind-9fb894441f914d5095e932af8d0ab90e (scan scan-70082f73b42b43fda8ae0a7ecbe7fedf).

Checklist

General

Documentation

  • Documentation has been added/updated for any new features (description is in config.schema.json)

Configuration

  • If configuration schema (config.schema.json) was modified:
    • TypeScript types regenerated: edited src/config/generated/config.ts by hand to match quicktype output. The npm registry was unreachable from the dev box, so the generator couldn't run.
    • Schema reference docs regenerated (npm run gen-schema-doc): not run, same reason

Tests

  • Tests have been added/updated for new functionality: test/extractRawBody.test.ts (pre-validation, audit of rejected pushes, 413 paths, configured limit, body replay) and test/testProxyRoute.test.ts (HTTP-level bad UA / unregistered repo)
  • Unit tests pass (npm test): test/extractRawBody.test.ts passes locally (14/14). The full suite and test/testProxyRoute.test.ts were not run locally because dependencies couldn't be installed, so this relies on CI.
  • Formatting passes (prettier check on changed files). npm run lint not run locally.
  • Type checks pass (npm run check-types): not run locally, relies on CI

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

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)


Devin Review

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.
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 2 potential issues.

Devin Review

Comment thread src/proxy/routes/index.ts Resolved
Comment thread config.schema.json
Comment on lines +264 to +267
"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)."
},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Devin Review

Comment thread src/proxy/routes/index.ts
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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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: rateLimit currently applies only to the management service in src/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants