Skip to content

On a core.autocrlf checkout, hosted rollback and remove keep allow-remote=all in .npmrc and Maven's resolver settings and an empty <repositories>: the undo compares the files hosted mode wrote byte for byte #2377

Backlog

Description

[agent] Found by the architecture refactor routine on main at cfc870f, with real git 2.43.0, npm 12.2.3 and Maven 3.9.11, and the real npm registry.

The problem

When a project's last hosted pin goes, the undo also takes away what hosted mode created for it: the .npmrc that holds allow-remote=all, pnpm's pnpm-workspace.yaml, Maven's .mvn/maven.config, and the <repositories> section it wrote into pom.xml. rollback, remove and the restore a vendored takeover runs first all do this. Hosted mode keeps no ledger, so the undo recognises each file by comparing it with what hosted mode writes.

Three of those comparisons are byte for byte against LF text. Git for Windows checks text files out with CRLF by default (core.autocrlf=true), and a * text=auto eol=crlf rule does the same anywhere. In such a checkout of a project that was scanned and committed, the undo takes hosted mode's own files for someone else's:

  • npm. .npmrc stays, with allow-remote=all. The project has no hosted patch any more, and npm 12 goes on accepting lock entries from outside the registry for it: npm config get allow-remote prints all, where the LF checkout prints none. The run exits 0 and warns that hosted mode "may have added" the line.
  • Maven. .mvn/maven.config stays with the six resolver settings, under the same kind of warning, and pom.xml keeps an empty <repositories> section with no message. Maven still runs.

The pnpm half of the same function was fixed for exactly this on 2026-11-11 (354ab99, #2052): "the file hosted mode created is recognised in either line ending […] so a core.autocrlf checkout of it is removed like its LF twin instead of being kept with pnpm_trust_lockfile_left." The npm half sits 47 lines above it and still compares bytes. The contract has one sentence for both files, in the row of npm_allow_remote_left / pnpm_trust_lockfile_left: "A file that is exactly hosted mode's own is deleted silently."

Nothing breaks a build. The harm is a setting left on and files left behind after an undo that says it restored the project, for the checkouts Git for Windows makes by default.

Evidence

One npm project, two clones

A project locked by real npm (left-pad 1.3.0, ms 2.0.0), a stand-in patch API that grants a patched left-pad tarball, the binary built from main:

$ socket-patch scan --mode hosted --yes            # exit 0: rewrites package-lock.json, creates .npmrc
$ git add -A && git commit -m "socket-patch scan"
$ git clone app linux
$ git -c core.autocrlf=true clone app windows      # what Git for Windows does by default

linux$ socket-patch rollback --yes
Restored pkg:npm/left-pad@1.3.0 to its upstream registry entry
Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
                                                   # exit 0
linux$ git status --porcelain
 D .npmrc
 M package-lock.json
linux$ npm config get allow-remote                 # npm 12.2.3
none

windows$ socket-patch rollback --yes
Restored pkg:npm/left-pad@1.3.0 to its upstream registry entry
Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
Warning: .npmrc keeps `allow-remote=all`, which hosted mode may have added; no lock entry needs it any more, so remove the line if nothing else does
                                                   # exit 0
windows$ git status --porcelain
 M package-lock.json
windows$ npm config get allow-remote
all

remove pkg:npm/left-pad@1.3.0 --yes gives the same two results. Under --json the CRLF run is status: success with one rolledBack event and the warning npm_allow_remote_left. In both clones package-lock.json comes back as it was before the scan, in the clone's line ending.

Maven

The bench's Maven project (socket-patch-bench serve maven/hosted), scanned, committed and cloned the same two ways:

linux$ socket-patch rollback --yes                 # exit 0
linux$ git status --porcelain
 D .mvn/checksums/checksums.sha256
 D .mvn/maven.config
 M pom.xml                                         # the pom before the scan

windows$ socket-patch rollback --yes               # exit 0
Warning: .mvn/maven.config keeps the trusted-checksums resolver lines (`-Daether.…`), which hosted mode may have added; no hosted pin needs them any more, so remove them if nothing else does
windows$ git status --porcelain
 D .mvn/checksums/checksums.sha256
 M pom.xml
windows$ diff <(git show HEAD~1:pom.xml) <(tr -d '\r' < pom.xml)
64a65,66
>   <repositories>
>   </repositories>

mvn -o validate (3.9.11) passes over what is left.

A unit test over the Maven undo

A throwaway test beside the_mvn_files_are_removed_in_either_spelling_of_the_directory (core patch/redirect/upstream/maven.rs) runs that test's three files through restore_upstream as written and with every \n as \r\n, and asks the pnpm and Maven predicates about their own file in both spellings. It fails on main:

$ cargo test -p socket-patch-core --lib probe_autocrlf_checkout
CRLF (left) against LF (right)
  left: ("pnpm scaffold is hosted mode's own: true", "maven.config is hosted mode's own: false", "files left: [\".mvn/maven.config\", \"pom.xml\"]", "warnings: [\"maven_trusted_checksums_left\"]", "pom.xml is the pom before the scan: false", "empty <repositories> left: true")
 right: ("pnpm scaffold is hosted mode's own: true", "maven.config is hosted mode's own: true", "files left: [\"pom.xml\"]", "warnings: []", "pom.xml is the pom before the scan: true", "empty <repositories> left: false")
The test
#[tokio::test]
async fn probe_autocrlf_checkout_is_undone_like_its_lf_twin() {
    use super::trusted_checksums::{self, Basedir::Launcher};
    let config = format!("{}\n", trusted_checksums::config_args(Launcher).join("\n"));
    let scaffold = format!("{}\n", crate::hosted::guidance::TRUST_SCAFFOLD_LINES.join("\n"));
    let mut rows = Vec::new();
    for crlf in [false, true] {
        let spell = |s: String| if crlf { s.replace('\n', "\r\n") } else { s };
        let files = vec[
            ("pom.xml", spell(fixture("basic", "expected", "pom.xml"))),
            (".mvn/maven.config", spell(config.clone())),
            (
                ".mvn/checksums/checksums.sha256",
                spell(fixture("basic", "expected", ".mvn/checksums/checksums.sha256")),
            ),
        ];
        let (outcome, after) = run(&files).await;
        rows.push((
            format!("pnpm scaffold is hosted mode's own: {}", crate::hosted::guidance::is_trust_scaffold(&spell(scaffold.clone()))),
            format!("maven.config is hosted mode's own: {}", trusted_checksums::is_written_config(&spell(config.clone()))),
            format!("files left: {:?}", after.keys().collect::<Vec<_>>()),
            format!("warnings: {:?}", outcome.warnings.iter().map(|(c, _)| *c).collect::<Vec<_>>()),
            format!("pom.xml is the pom before the scan: {}", after["pom.xml"] == spell(fixture("basic", "input", "pom.xml"))),
            format!("empty <repositories> left: {}", after["pom.xml"].contains("<repositories>")),
        ));
    }
    assert_eq!(rows[1], rows[0], "\nCRLF (left) against LF (right)");
}

The other ecosystems are clean

Eleven real projects locked by their real tools, and a NuGet project written by hand (its lock holds nuget.org's content hash of Newtonsoft.Json 13.0.3, which the LF undo confirms). Each was scanned in hosted mode against a stand-in patch API and undone against the real registries, in four checkouts: scanned and undone in LF; scanned in LF, committed, undone in a core.autocrlf=true clone; scanned in a core.autocrlf=true clone and undone there; scanned in a core.autocrlf=true clone, committed and checked out LF.

Project Undo in the LF checkout Undo in the CRLF clone of the scanned tree
npm 10.9 (package-lock.json) exact .npmrc left
pnpm 10.28 exact exact (pnpm-workspace.yaml removed)
Yarn 1.22, Bun 1.4 exact exact
Cargo 1.97 exact exact (.cargo/config.toml removed)
Go 1.24, Composer 2.8, Bundler 4.0 exact exact
uv 0.11, a uv pip compile requirements file, Poetry 2.4 exact exact (uv's transitive override comes off pyproject.toml)
NuGet (nuget.config, packages.lock.json) exact exact
Maven, Gradle and Hatch (the bench's projects; their undo needs no registry) exact Maven: as above; Gradle and Hatch exact

"Exact" is byte for byte against the same kind of checkout of the project before the scan. In every project the tree a CRLF clone's scan commits is the tree an LF scan writes, and list prints the same in both clones. On the bench's 21 hosted projects a second scan in the CRLF clone also says and writes what it does in the LF one.

Where

All in crates/socket-patch-core/src, at cfc870f:

File hosted mode wrote How the undo recognises it
pnpm-workspace.yaml hosted::guidance::is_trust_scaffold, which uses utils::line_endings::eol_eq (patch/redirect/upstream/npm.rs, line 3211) either line ending
.npmrc npmrc == NPMRC_CREATED (the same function, cleanup_side_config, line 3164) LF only
.mvn/maven.config config == format!("{}\n", …) in is_written_config (formats/maven/trusted_checksums.rs, lines 142 to 146; called at patch/redirect/upstream/maven.rs, line 640) LF only
the <repositories> and <dependencyManagement> wrappers in pom.xml text.contains(EMPTY_REPOSITORIES) and EMPTY_DEP_MANAGEMENT, two LF literals (patch/redirect/upstream/maven.rs, lines 60 to 62, used at 186 and 227) LF only

The second use (without_repository, line 186) is also what a scan runs when a newer patch replaces a pin, so a scan in a CRLF clone leaves the empty section too. The <dependencyManagement> wrapper I read and did not run.

utils/line_endings.rs states the rule in its header: "is this still our file" checks, "which a core.autocrlf checkout must not defeat, compare with eol_eq".

Earlier fixes of this class

The .npmrc comparison and the two pom literals have been as they are since v5.0.0 (2463257). is_written_config in this form is from #2145, which is not in a release.

Planned fix

  1. cleanup_side_config: compare .npmrc with NPMRC_CREATED through eol_eq.
  2. is_written_config: the same.
  3. without_repository and restore_pom: match the two empty wrappers in the pom's own line ending (respell with terminator(pom)), and replace them with </project> as now.
  4. Tests: the existing cleanup tests of each file run once more in CRLF (the probe above becomes the Maven one; tests/vendor/redirect_npm_allow_remote.rs gets a CRLF case of its "created file is removed" test).
  5. The contract's rows for npm_allow_remote_left and maven_trusted_checksums_left say "in either line ending".

No JSON shape, flag, exit code or file format changes. A file that holds anything else is still kept with its warning.

The same files on the write side

The run also found that two hosted writers end the lines they insert with LF whatever the file uses. Over the bench's 21 hosted projects, with every file the scan edits rewritten as CRLF first, 19 keep one line ending and two do not:

pom.xml         13 bare LF of 78 lines   (the <repositories> block: patch/redirect/maven_index.rs, repository_block and managed_block, lines 93 to 106)
nuget.config     9 bare LF of 16 lines   (the source and its mapping: patch/redirect/mod.rs, add_nuget_source, line 7338)

This class was fixed for the hosted Gemfile (3595c58, #1831), the vendored Gemfile (d04d9df, #1821), .npmrc (2c10f00, #1196) and pnpm-workspace.yaml (#2052), and utils::line_endings::terminator is the shared rule for the ending of an inserted line. The file is mixed only until git commits it, both tools read it, and the undo takes the LF block out of a CRLF pom (crlf_pom_round_trips). I would fix it with the three sites above, since the undo then has to find the block in either spelling anyway.

For a maintainer: the vendored NuGet writer says in a comment that it "inserts LF lines, even into a CRLF file (which then has mixed endings until git converts it)" (vendor/nuget_feed.rs, lines 1856 to 1858, from the review of #537). If that is the wanted behaviour for nuget.config, the write side stays as it is and only the three undo sites change.

Not run

Windows itself; vlt, Yarn berry and sbt; a vendored takeover and the withdrawn-pin sweep, which run the same restore; a transitive Maven pin, which writes the <dependencyManagement> wrapper; a real Maven build over the kept settings beyond validate.

Recipe

The stand-in patch API (papi.py), its catalogs (mkcat.py, mkpypi.py) and the runner (sp.sh) are in the routine's ledger entry of 2026-11-29 14:55Z, and mknpm.py in the entry of 22:55Z. The driver, realcrlf.py <port> <project> …, is in today's entry. Its core:

def checkout(src, dst, autocrlf, commit_autocrlf="false"):
    """Commit src's files (as a checkout with core.autocrlf=<commit_autocrlf> would) and check them out at dst."""
    repo = dst + ".repo"
    shutil.copytree(src, repo, symlinks=True, ignore=shutil.ignore_patterns(".git"))
    git(repo, "init", "-q")
    git(repo, "-c", f"core.autocrlf={commit_autocrlf}", "-c", "core.safecrlf=false", "add", "-A")
    git(repo, "-c", f"core.autocrlf={commit_autocrlf}", "commit", "-q", "-m", "x")
    git(R, "-c", f"core.autocrlf={autocrlf}", "clone", "-q", repo, dst)
    git(dst, "config", "core.autocrlf", autocrlf)    # or `git status` reads every CRLF file as modified
    return dst

lf = checkout(src, "lf", "false");            sp(lf, "scan", "--mode", "hosted", "--yes")
orig_win = checkout(src, "orig-win", "true")  # what the undo should return to
win = checkout(lf, "win", "true");            sp(win, "rollback", "--yes")
# compare tree(win) with tree(orig_win), file by file, bytes

core.autocrlf=true converts on checkout on Linux as it does on Windows, so no Windows machine is needed.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 30, 2026
  2. added a commit that references this issue on Nov 30, 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