Skip to content

Vendored Cargo, Go and gem directories lose the files a .gitignore matches at commit: a fresh clone fails vendor --check and vex, and a vendored crate can stop compiling #2348

Backlog

Description

[agent] Filed by the architecture refactor routine. Checked on main at cfc870f with the built binary, git 2.43.0, cargo 1.97.0, Go 1.24.7 and Bundler on Ruby 3.3.6.

Kind: bug. A vendored run reports success and vendor --check reports "committed artifact and wiring verified" for a tree git will only partly commit. The same class was fixed for tarballs, jars, nupkgs, wheels and platform gems (#831, #1061, #1116, #1572, #2154); the directory trees of Cargo, Go and a plain gem were left out.

Problem

A vendored run ends with Commit .socket/vendor/ and the updated lockfiles to make the patches portable. For Cargo, Go, a plain gem and Composer the artifact is a directory of the package's own files. Nothing asks git whether it will commit each file of that directory. Two kinds of rule drop files from the commit:

  1. The package's own .gitignore, which travels inside the copy. A crate ships a Cargo.lock that cargo package generates, and its own .gitignore names Cargo.lock. A Go module ships fixtures under a directory its .gitignore names.
  2. The project's .gitignore. GitHub's stock Rust.gitignore has target and debug, Go.gitignore has *.test, *.out and *.exe, and Rails.gitignore has .rspec. Each matches files that real packages ship.

The checkout that ran vendor keeps every file, so it builds and verifies there. Every other checkout gets the tree without them.

Evidence

Each project below is a real one: cargo init, go mod tidy or bundle install from the public registry, then one patch record and blob, then socket-patch vendor against the repository's fixture vendor service (tests/prebuilt_common, which packs the package as the registry extracted it).

Cargo, the crate's own .gitignore (cfg-if 1.0.4; the project's .gitignore is the /target that cargo init writes):

$ socket-patch vendor
Vendored 1 package.
Next steps:
  1. Commit .socket/vendor/ and the updated lockfiles to make the patches portable.
$ git status --short --ignored | grep '^!!'
!! .socket/vendor/cargo/<uuid>/cfg-if-1.0.4/Cargo.lock
$ socket-patch vendor --check
pkg:cargo/cfg-if@1.0.4: committed artifact and wiring verified                     # exit 0
$ git add -A && git commit -qm vendor && git clone -q . ../clone && cd ../clone
$ cargo build --locked --offline                                                   # exit 0, links the patched copy
$ socket-patch vendor --check
pkg:cargo/cfg-if@1.0.4: committed artifact .socket/vendor/cargo/<uuid>/cfg-if-1.0.4 has files that differ from its recorded inventory (vendor_inventory_mismatch); run `socket-patch repair` to restore it, then commit it      # exit 1
$ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json
Warning: omitting pkg:cargo/cfg-if@1.0.4 from VEX: the vendored artifact's contents do not match its ledger inventory (vendor_inventory_mismatch)
Error: No applied patches with vulnerability metadata to attest.                   # exit 1, no document
$ socket-patch repair                                                              # the remedy
Redownloaded 1 vendored artifact.
$ git add -A && git diff --cached --name-only | wc -l
0                                                                                  # nothing to commit: the next clone fails again

Cargo, GitHub's Rust.gitignore in the project (cc 1.2.56 as a build dependency):

$ socket-patch vendor                                                              # exit 0, "Vendored 1 package."
$ git status --short --ignored | grep '^!!'
!! .socket/vendor/cargo/<uuid>/cc-1.2.56/Cargo.lock
!! .socket/vendor/cargo/<uuid>/cc-1.2.56/src/target/
$ socket-patch vendor --check                                                      # exit 0, "committed artifact and wiring verified"
$ git add -A && git commit -qm vendor && git clone -q . ../clone && cd ../clone
$ cargo build --locked --offline
   Compiling cc v1.2.56+socket.3c4d5e6f-… (…/.socket/vendor/cargo/<uuid>/cc-1.2.56)
error[E0583]: file not found for module `apple`
 --> .socket/vendor/cargo/<uuid>/cc-1.2.56/src/target.rs:4:1
error[E0583]: file not found for module `generated`
…                                                                                  # exit 101

The project built before it was vendored and builds in the checkout that vendored it. It stops building in CI.

Go, the module's own .gitignore (github.com/pelletier/go-toml/v2 v2.4.3, whose .gitignore has fuzz/; the project has no .gitignore):

$ socket-patch vendor                                                              # exit 0
$ git status --short --ignored | grep '^!!'
!! .socket/vendor/golang/<uuid>/github.com/pelletier/go-toml/v2@v2.4.3/testdata/
$ socket-patch vendor --check                                                      # exit 0, verified
# after the commit, in a fresh clone:
$ GOPROXY=off go build ./...                                                       # exit 0
$ socket-patch vendor --check                                                      # exit 1, vendor_inventory_mismatch
$ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json                     # exit 1, no document

A plain gem, GitHub's Rails.gitignore in the project (rest-client 2.1.0): git ignores .socket/vendor/gem/<uuid>/rest-client-2.1.0/.rspec. In a fresh clone a frozen bundle install and bundle exec ruby -e 'require "restclient"' load the patched copy, vendor --check exits 1 (vendor_inventory_mismatch) and vex exits 1 with no document.

How common. Each package copied to its vendored path in an empty repository, then git ls-files -o -i --exclude-standard:

Packages No project .gitignore GitHub's stock template in the project
229 crates (this repository's dependencies, as cargo extracted them) 65 lose a file; 63 of them Cargo.lock, among them h2, http, bytes, tar, smallvec, hashbrown, serde_json, hyper-util Rust.gitignore: also source files of cc (src/target/*.rs) and winnow (src/combinator/debug/*.rs, a mod debug; with no cfg), and tests of syn
59 Go modules (the latest of well-known ones) 4: go-toml/v2, docker/distribution, hashicorp/go-getter (two .go files of its command), open-policy-agent/opa Go.gitignore: 8, adding golang.org/x/net v0.63.0 (14 .test fixtures), golang.org/x/sys, containerd, klauspost/compress
58 gems (popular ones, unpacked) 0 Rails.gitignore: 2 (rest-client, rspec-core); Ruby.gitignore: 0

Agent mode is not affected by the Go case: with the same module in .socket/go-patches/, apply --check and apply pass in a fresh clone, because they hash only the patched files.

Not run: Composer (the copy's own .gitignore is already emptied there, for Composer's path mirror; the project's rules are not asked about), and the patch service itself. This sandbox has no route to it, so what the fixture packs stands in for its artifact. The second kind of rule does not depend on that: a crate cannot compile without the files Rust.gitignore matches.

Where

  • CLI commands/vendor.rs, lines 1608 to 1620: artifacts_gitignore_checked lists the backends that ask git per package (npm, NuGet, PyPI, the JVM trees) and says "The others rely on the run-level ledger check".
  • core vendor/state.rs, lines 1067 to 1100: that check, ledger_gitignore_refusal, asks git about two paths, .socket/vendor/ and the ledger.
  • core vendor/gem.rs: keep_platform_trees_committable (line 1957) asks git about every file of the inventory, empty_shipped_gitignores (line 1820) empties a .gitignore shipped inside the tree, and UUID_GITIGNORE (line 1938) is the !* written beside it. All three run only for a gem locked as platform gems.
  • core vendor/cargo.rs and vendor/golang.rs have no ignore handling at all.
  • The fresh-checkout proofs of the real-tool suites cannot see this: tests/e2e_vendor_cargo_build.rs (lines 757, 1040 and 1208) copies a hand-picked list of "committable files" to a new directory instead of committing and cloning.

Earlier fixes of the class: 6fa6a9e (npm tarballs, #831), eca5d24 (JVM and NuGet, #1061), debe1c0 (PyPI wheels, #1572), 9d54302 (the ledger, #1638), d16c589 (platform gems, #2154).

Planned fix

Give every directory-tree backend what platform gems have, from one shared function rather than a fifth copy:

  1. Write <uuid>/.gitignore (!*) and the .gitattributes the other backends write. With real git this re-includes cc's src/target/ under Rust.gitignore.
  2. Empty each .gitignore shipped inside the copy, as the platform-gem and Composer backends do (a deeper .gitignore wins over the !* above it; with cc's emptied, git no longer ignores its Cargo.lock). The ledger's inventory is of the copy as vendored.
  3. Ask git about every file of the inventory after the write, and refuse vendor_artifact_gitignored when a rule still wins.
  4. Have an in-sync re-run and repair put the pair back, so a tree vendored before the fix heals.
  5. Make the Cargo, Go and gem fresh-checkout tests go through git add -A, git commit and git clone, with the stock template in the project.

The .gitattributes of step 1 also covers the vendored trees of #2318's comment (line-ending conversion of the same Go, Cargo and Composer directories).

Behavior change: a vendored Cargo, Go, gem or Composer directory gains the two files beside it, and a .gitignore inside the copy is emptied. CLI_CONTRACT.md's rows for those four backends and for vendor_artifact_gitignored need the same sentences the platform-gem row has.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. added a commit that references this issue on Nov 28, 2026
  3. mikolalysenko commented on Dec 1, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] The Composer row this issue lists as not run, run on main at 1b3f422 with the built binary, git 2.43.0, Composer 2.8.12 and PHP 8.3.6. It is the same defect: a project .gitignore rule keeps a file of the vendored Composer directory out of the commit, vendor and vendor --check report success, and every fresh clone installs the package without that file.

    Evidence

    A real project that requires composer/ca-bundle 1.5.6, whose dist ships res/cacert.pem. The project's .gitignore is /vendor/, *.pem and *.key (rules that keep private keys out of a repository). One patch record and blob (a comment appended to src/CaBundle.php), then socket-patch vendor against the repository's fixture vendor service (tests/prebuilt_common), as in the rows above.

    $ socket-patch vendor
    Vendored 1 package.
    Next steps:
      1. Commit .socket/vendor/ and the updated lockfiles to make the patches portable.
      …                                                                                # exit 0
    $ git status --short --ignored
     M composer.lock
    ?? .socket/vendor/
    !! .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6/res/
    !! vendor/
    $ socket-patch vendor --check
    pkg:composer/composer/ca-bundle@1.5.6: committed artifact and wiring verified      # exit 0
    $ git add -A && git commit -qm vendor && git clone -q . ../clone && cd ../clone
    $ find .socket/vendor -type f
    .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6/LICENSE
    .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6/README.md
    .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6/composer.json
    .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6/src/CaBundle.php
    .socket/vendor/composer/<uuid>/socket-patch.vendor.json
    .socket/vendor/state.json
    $ composer install
      - Installing composer/ca-bundle (1.5.6): Mirroring from .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6
    Generating autoload files                                                          # exit 0
    $ ls vendor/composer/ca-bundle
    LICENSE  README.md  composer.json  src                                             # no res/
    $ php -r 'require "vendor/autoload.php"; $p = \Composer\CaBundle\CaBundle::getBundledCaBundlePath(); var_dump(file_exists($p));
              $ch = curl_init("https://repo.packagist.org/packages.json"); curl_setopt($ch, CURLOPT_CAINFO, $p); …; curl_exec($ch);
              echo "curl errno ", curl_errno($ch), ": ", curl_error($ch), "\n";'
    bool(false)
    curl errno 77: error setting certificate file: …/clone/vendor/composer/ca-bundle/src/../res/cacert.pem
    $ socket-patch vendor --check
    pkg:composer/composer/ca-bundle@1.5.6: committed artifact .socket/vendor/composer/<uuid>/composer/ca-bundle@1.5.6 has files that differ from its recorded inventory (vendor_inventory_mismatch); run `socket-patch repair` to restore it, then commit it      # exit 1
    $ socket-patch vex --product pkg:generic/app@1.0.0 -O vex.json
    Warning: omitting pkg:composer/composer/ca-bundle@1.5.6 from VEX: the vendored artifact's contents do not match its ledger inventory (vendor_inventory_mismatch)
    Error: No applied patches with vulnerability metadata to attest.                   # exit 1, no document
    $ socket-patch repair
    Redownloaded 1 vendored artifact.                                                  # exit 0
    $ git add -A && git diff --cached --name-only | wc -l
    0                                                                                  # nothing to commit: the next clone fails again
    

    composer install exits 0 in the clone, so nothing says the package is short a file until the application asks for the bundle. The checkout that ran vendor keeps the file and works.

    Control. The same project with the *.pem rule taken out: git commits res/cacert.pem, the clone's composer install gives file_exists true, vendor --check exits 0 and vex writes one statement.

    Step 1 of the planned fix covers Composer. With .socket/vendor/composer/<uuid>/.gitignore holding !*, written by hand beside the copy and under the same *.pem rule, git commits res/cacert.pem. In the clone Composer's mirror copies it, file_exists is true, vendor --check exits 0 with that extra file in the uuid directory, and vex writes one statement.

    How common

    78 packages: 24 well-known ones picked by hand (several because I expected a match) and what they require. Each file of a package's dist (git archive HEAD, which applies export-ignore) at its vendored path, 7,498 files, against one rule at a time with git check-ignore:

    Project rule Packages that lose files
    *.pem composer/ca-bundle (res/cacert.pem), paragonie/certainty (19 bundles)
    *.crt stripe/stripe-php (data/ca-certificates.crt), braintree/braintree_php (lib/ssl/…ca.crt), tecnickcom/tcpdf
    dist/ twbs/bootstrap (96 files: all of its compiled CSS and JS), paragonie/random_compat
    *.map dompdf/php-font-lib (21 maps/*.map encoding tables), twbs/bootstrap, components/jquery
    *.min.js components/jquery, twbs/bootstrap, filp/whoops
    bin/ nesbot/carbon, symfony/console (Resources/bin/hiddeninput.exe), symfony/translation, masterminds/html5, paragonie/certainty
    build/, docs/, tmp/ twbs/bootstrap, psr/http-message, mpdf/mpdf
    *.key, *.log, *.zip, *.sql, .env, temp/, cache/, node_modules/ none of the 78

    Where

    • CLI commands/vendor.rs, line 1713: artifacts_gitignore_checked names npm, NuGet, PyPI and the JVM trees. Composer is among "the others", which get the run-level check of .socket/vendor/ and the ledger alone (core vendor/state.rs, ledger_gitignore_refusal, line 1067).
    • core vendor/composer_lock.rs asks git about no file of the copy and writes no <uuid>/.gitignore. What it does empty is the copy's own .gitignore, for Composer's mirror.

    So the shared function of the planned fix has four callers, not three: Cargo, Go, a plain gem and Composer.

    Not run: the patch service itself (the fixture packs the package as installed, as in the rows above). Composer could not reach the dist host from this sandbox and installed from source, so I gave vendor/composer/ca-bundle the dist's file list with git archive HEAD and set installation-source to dist before vendoring. Which stock .gitignore templates carry each rule of the table was not looked up. A line-ending rule on the same tree is #2318's first comment.


    Generated by Claude Code

  4. added a commit that references this issue on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions