Skip to content

fix(indexer): skip non-regular files and prevent tar path traversal - #6505

Open
another-rex wants to merge 1 commit into
google:masterfrom
another-rex:fix/indexer-symlink-tarslip
Open

another-rex wants to merge 1 commit into
google:masterfrom
another-rex:fix/indexer-symlink-tarslip

Conversation

@another-rex

@another-rex another-rex commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Some general hardening for indexer. I don't want to touch it too much.

Mitigate symlink arbitrary file reads and Tar-Slip path traversal in gcp/indexer with minimal changes.

(AI-assisted PR)

Details

  • gcp/indexer/stages/preparation/preparation.go:
    • Clone repositories with NoCheckout: true so working-tree symlinks from external repos are not materialized on disk during preparation.
    • In copyToBucket, check filepath.Walk errors, skip non-regular files (!info.Mode().IsRegular()), and write clean relative tar paths (filepath.Rel).
  • gcp/indexer/stages/processing/processing.go:
    • Check filepath.Walk errors and skip non-regular files (!info.Mode().IsRegular()) so checked-out symlinks are never dereferenced or hashed into RepoIndex.
  • gcp/indexer/shared/shared.go:
    • In CopyFromBucket, enforce regular-file tar entry types (skipping tar.TypeDir and rejecting symlinks/hardlinks), verify extracted paths remain strictly within tmpDir (preserving compatibility with existing leading-/ tarballs), close the GCS reader, and clean up tmpDir on error.

Testing

  • Ran go test ./..., go vet ./..., and golangci-lint@v2.14.0 run ./... + fmt --diff ./... in gcp/indexer (all passed, 0 issues).
  • Verified locally before removing the temporary test helpers that NoCheckout: true clones work with ref enumeration and Worktree().Checkout, that symlinks/broken symlinks are skipped, and that tar traversal/symlink entries are rejected.

agy

@another-rex
another-rex force-pushed the fix/indexer-symlink-tarslip branch from c4ccc3e to 8800181 Compare December 4, 2026 02:25
@another-rex
another-rex requested review from a team and jess-lowe December 4, 2026 04:13
@another-rex
another-rex marked this pull request as ready for review December 4, 2026 04:13

This branch has not been deployed

No deployments
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.

2 participants