Skip to content

repair cannot restore a vendored npm tarball whose top directory is not package/ (ejs@3.1.6), and every vendored scan downloads it again #2423

Backlog

Description

[agent] Found while checking #2410 against real patched tarballs from the patch service. Run with a binary built from main on 2026-12-01, against the production API, on macOS. The strict reader and its two callers are unchanged on main since.

Problem

The patch service serves the patched tarball of ejs@3.1.6 with the top directory of the upstream tarball, ejs-v3.1.6/, not package/. Two readers in core patch/package.rs disagree about such a tarball:

  • vendor, vendor --check and vex read it with the lenient reader and accept it: the patch is vendored, checked and attested.
  • repair and the re-run of a vendored scan read it with read_archive_bytes_to_map_strict (called from vendor/redownload.rs and vendor/reuse.rs), which refuses every entry outside package/.

So the same committed tarball is "verified" by one command and "not canonical" for another.

What happens

A project with 40 npm dependencies, 35 of them with a patch, ejs@3.1.6 among them:

  1. socket-patch scan --mode vendored: 35 packages vendored. socket-patch vendor --check: 35 verified, exit 0.

  2. A second socket-patch scan --mode vendored --json: 35 already_vendored events, and one more for ejs alone:

    {"action": "skipped", "purl": "pkg:npm/ejs@3.1.6", "errorCode": "vendor_prebuilt_downloaded",
     "reason": "vendored ejs@3.1.6 from the patch service (…/ejs-3.1.6.tgz)"}
    

    The committed tarball is never reused: every run downloads it again.

  3. Delete the committed tarballs of ejs and next, then socket-patch repair --json, exit 1:

    {"action": "failed", "purl": "pkg:npm/ejs@3.1.6", "errorCode": "vendor_artifact_redownload_failed",
     "error": "entry \"ejs-v3.1.6/LICENSE\" is not canonical"}
    {"action": "rebuilt", "purl": "pkg:npm/next@12.0.0", …}
    

    socket-patch vendor --check then reports, exit 1:

    pkg:npm/ejs@3.1.6: committed artifact .socket/vendor/npm/<uuid>/ejs-3.1.6.tgz is missing
    (vendor_artifact_missing); run `socket-patch repair` to restore it, then commit it
    

    which is the command that just failed.

Who it hurts: a team that vendored the patch for such a package and then loses the tarball (a bad merge, a .gitignore rule, a cleaned checkout). The remedy every message names cannot restore it.

How common

Of the 35 patched tarballs in that project, ejs is the only one whose top directory is not package/. Upstream tarballs with another top directory exist beyond it (@types/node and coffee-script@1.0.0 in a sample of 81 registry tarballs), and package managers strip the first path component whatever it is called, which is why they install.

Possible fixes

  • Let the strict reader take one top directory of any name, as the lenient reader and the installers do, and keep its other rules.
  • Or have the patch service repack under package/. That needs a matching change in Socket's backend, and tarballs already committed would still need the first fix.
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:triagedbugpm:npmpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions