Repository navigation
Conversation
The scan capped the compressed download at 100 MB to bound what it materializes on the function's /tmp, but the tar it wrote and the tree it extracted were unbounded. gzip turns a few hundred KB of zeros into hundreds of MB, so a repository with large low-entropy files passed the download cap and filled the shared 500 MB tmpfs, and the ENOSPC counted as retryable, so the queue redelivered the same scan up to five times. The download is now decompressed in the pipeline under a second budget of 100 MB, and the file written to disk is the plain tar, so extraction cannot grow past it. Exceeding either budget is an UnscannableRepoError, which already maps to a suspicious verdict for manual review instead of a retry. tar 7.5.15, the version in bun.lock, has no decompression guard of its own; the ratio guard in later 7.5.x releases is relative and lets a 2 MB download unpack to 300 MB at 144:1, so an absolute cap is still needed.
|
@deanrie is attempting to deploy a commit to the Anysphere Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
cloneRepoinlib/plugins/scan.tscaps the GitHub tarball download atREPO_ARCHIVE_MAX_BYTES(100 MB). The comment above the constant says why: "Cap how much of the repo archive we materialize on the function's tmpfs", since/tmpis shared and has a ~500 MB limit. Only the compressed bytes are counted, though. The.tar.gzwritten to disk and the treetar.xextracts from it are unbounded.gzip compresses low-entropy data at up to ~1000:1, so a public repo with a few 100 MB files of zeros (GitHub's per-file limit) produces a tarball of a few hundred KB that passes the download cap and the
content-lengthcheck, then writes hundreds of MB to tmpfs. TheENOSPCthat follows is a plainError, whichrunSecurityAgenttreats as transient and rethrows, so the drain route lets pgmq redeliver the scan up toMAX_ATTEMPTS(5), each attempt filling/tmpagain and failing whatever other scan shares the instance. Anyone can submit a plugin that points at such a repo.Measured with a standalone replica of the pipeline (same stages in the same order) against a local HTTP server:
bun.lock)The
maxDecompressionRatioguard in later 7.5.x releases is relative, so a 95 MB download at 500:1 would still unpack to ~47 GB. An absolute cap is needed either way.Fix
The download is decompressed inside the pipeline (
createGunzip) under a second byte budget,REPO_UNPACKED_MAX_BYTES(100 MB), and the file written to disk is the plainrepo.tar, so extraction cannot grow past it. Peak tmpfs use is at most the two caps together. Exceeding either budget raisesUnscannableRepoError, which already maps to thesuspicious/repository_clone_failedverdict for manual review, so the scan is not retried.archiveSizeGuardbecamebyteBudget, used for both stages, with the same log line per stage.With the change, both archives above stop at exactly 100 MB of decompressed bytes with
Repository archive unpacks to more than the 104857600-byte scan limit.and the scratch dir is cleaned up. Real tarballs ofcursor/plugin-templateandxai-org/grok-build-plugin-ccextract with the same file list as before.The repo has no test runner, so the replica script is not committed, as with #467.
tsc --noEmit -p apps/cursor/tsconfig.jsonshows the same single pre-existing error on this file (platforminAgentOptions, already noted in the source) and nothing new;biome checkon the file is clean.