Skip to content

fix(scan): refuse filesystem-sized scan and build roots - #365

Merged
vibgrate-team merged 3 commits into
mainfrom
cursor/unsafe-scan-root-64ca
Oct 6, 2026
Merged

vibgrate-team merged 3 commits into
mainfrom
cursor/unsafe-scan-root-64ca

Conversation

@vibgrate-team

@vibgrate-team vibgrate-team commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

vg scan and vg build walked whatever directory they were given. Pointing either command at /, an unpacked operating-system image, or a huge unpack directory could hang or run out of memory before the existing file cap applied, and the failure was not something a user could act on.

Both commands now fail closed before that walk runs away:

  • A filesystem root (/, a drive root, or a symlink to one) is refused without listing it.
  • A top-level layout that looks like an OS image (etc + usr + var, plus bin, sbin, lib, or boot; or Windows plus Program Files, Users, or ProgramData) is refused after one directory listing.
  • A walk that passes VG_MAX_WALK_ENTRIES (default 1000000; 0 disables the budget) stops with the same class of error.

The process exits 1. The message is stable for a given path and names what to do next: pass a project subdirectory, narrow the walk with --exclude ignore patterns, raise VG_MAX_WALK_ENTRIES, or pass --allow-unsafe-root (VG_ALLOW_UNSAFE_ROOT=1 does the same). vg build ./app checks ./app, not the current directory.

Related issues

Fixes #258

Checklist

  • pnpm test passes
  • pnpm lint is clean
  • pnpm typecheck is clean
  • Docs updated (README / DOCS / ARCHITECTURE) where behavior changed
  • Determinism preserved — identical input still produces identical graph.json / report output. The new error text depends only on the path and a fixed marker list, not on readdir order, time, or randomness.
  • No proprietary or internal references — public, Apache-2.0 content only
  • Commits use Conventional Commits and are signed off (git commit -s, DCO)

Notes for reviewers

The walk budget counts directory entries the walk actually looks at. Skipped dependency directories such as node_modules count as one entry and are not descended into. --allow-unsafe-root skips the filesystem-root check, the OS-image check, and the walk budget. VG_MAX_WALK_ENTRIES raises or disables only the budget, so an OS image is still refused.

vg build <subdir> and a scoped discover judge the directories that will be walked, so a narrowed path is accepted even when the current directory would not be.

How to verify

pnpm test test/root-safety.test.ts
pnpm lint
pnpm typecheck

test/root-safety.test.ts covers the filesystem root (including a symlink to it), Unix and Windows image layouts, the walk budget, the override, and the vg scan / vg build error path. Those cases use temp directories and a fixed entry ceiling, so they do not depend on the clock and they do not walk /.

Full pnpm test (5022 tests), pnpm lint, and pnpm typecheck passed.

Open in Web Open in Cursor 

cursoragent and others added 3 commits October 5, 2026 12:34
Walking a filesystem root, an OS image, or an enormous directory could
hang or exhaust memory before any file cap applied. vg scan and vg build
now exit 1 with a stable message that tells the user to pass a project
subdirectory, --exclude ignore patterns, or --allow-unsafe-root.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: vibgrate-team <vibgrate-team@users.noreply.github.com>
Keep this branch's public walk policy: VG_MAX_WALK_ENTRIES defaults to
1000000, and --allow-unsafe-root / VG_ALLOW_UNSAFE_ROOT skip the
filesystem-root, OS-image, and walk-budget checks. Call sites that
arrived with main delegate to that policy.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: vibgrate-team <vibgrate-team@users.noreply.github.com>
Keep both unreleased changelog notes. The walk policy is unchanged:
VG_MAX_WALK_ENTRIES defaults to 1000000, and --allow-unsafe-root still
skips the filesystem-root, OS-image, and walk-budget checks.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: vibgrate-team <vibgrate-team@users.noreply.github.com>
@vibgrate-team
vibgrate-team marked this pull request as ready for review October 6, 2026 12:38
@vibgrate-team
vibgrate-team merged commit fee2a10 into main Oct 6, 2026
1 check passed
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.

Bug: actionable error (no crash) when scan/build root looks like a whole filesystem

2 participants