Skip to content

Stop the Maven Trusted Checksums line breaking -f builds on Maven 3.9.2 to 3.9.8 - #2145

Merged
Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
fix/maven-hosted-f-outside-root
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
fix/maven-hosted-f-outside-root

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Based on main, independent of the hosted Maven stack (#2114, #2133, #2135) so it can land first.

What was wrong

When the patch server supplies both hashes, scan --mode hosted writes Maven Trusted Checksums settings into .mvn/maven.config, among them the directory of the summary file:

-Daether.trustedChecksumsSource.summaryFile.basedir=${session.rootDirectory}/.mvn/checksums

On Maven 3.9.2 to 3.9.8, session.rootDirectory is undefined when the build is started with -f <project>/pom.xml from outside the project, and Maven then refuses to start: Illegal use of undefined property: session.rootDirectory. That is a common CI invocation. A hosted scan with the released CLI therefore broke the build of a project that built before.

What I measured

Real Maven, a reactor wired as hosted mode wires it, each cell run twice: once with the genuine patched jar and once with a tampered jar whose .sha1 matches (so only the trusted checksum can catch it). "enforced" means the genuine build succeeds and the tampered one fails on the trusted checksum.

Maven ${session.rootDirectory} (released) ${maven.multiModuleProjectDirectory} a relative path
3.6.3, 3.8.9, 3.9.0 builds, not enforced builds, not enforced builds, not enforced
3.9.2, 3.9.3 root, module: builds, not enforced. -f from outside: does not start builds everywhere, not enforced (these two check SHA-1 only) builds, not enforced
3.9.4 to 3.9.8 root, module: enforced. -f from outside: does not start enforced in all three builds, not enforced
3.9.9, 3.9.16 enforced in all three enforced in all three builds, not enforced
4.0.0-rc-7 enforced in all three builds, not enforced (Maven 4 does not interpolate it) builds, not enforced
  • Invocations: from the project root, from a module directory, and mvn -f <project>/pom.xml from another directory. The -f column was run on every release from 3.9.2 to 3.9.9; the boundary is exactly 3.9.8 / 3.9.9.
  • With the Maven Wrapper (only-script, pinning 3.9.4), ./mvnw behaves as Maven 3.9.4 does in all three invocations, for both forms.
  • A relative path is read from the local repository, so no form without a property reaches the checkout.

No single form satisfies every version: one breaks Maven 3.9.2 to 3.9.8, the other is inert on Maven 4.

Which model a pom declares, measured for the review (Maven 3.9.9 and 4.0.0-rc-7, mvn validate on a pom-packaged root with a child/pom.xml beside it):

namespace <modelVersion> Maven 3.9.9 Maven 4.0.0-rc-7
4.1.0 4.0.0 builds builds as a 4.0.0 pom: no subproject discovery
4.1.0 none fails: 'modelVersion' is missing builds as 4.1.0: discovers the child
4.0.0 4.1.0 fails: model newer than supported builds as 4.1.0: discovers the child
4.0.0 none fails: 'modelVersion' is missing builds as a 4.0.0 pom
4.1.0 4.1.0 fails: model newer than supported builds as 4.1.0

So a pom's model is its <modelVersion>, else the version its namespace names; a 4.0.0 model under the 4.1.0 namespace is a pom Maven 3 builds.

What changes

The form is chosen per project, from what the project itself declares.

  • ${maven.multiModuleProjectDirectory}/.mvn/checksums by default. It breaks no build in any of the invocations on any Maven, and is enforced from 3.9.4 on, wherever the build is started.
  • ${session.rootDirectory}/.mvn/checksums for a project that declares Maven 4: its Maven Wrapper pins Apache Maven 4 or later, or its root pom.xml is of a model newer than 4.0.0. Maven 4 defines the property in every invocation.

A project wired by an earlier release is healed by any hosted scan that reads its .mvn/maven.config. The six settings standing together as hosted mode wrote them, in the spelling that is not this project's, get that one line rewritten in place (redirect_maven_config, rewritten, key: "trustedChecksumsDirectory"), every other byte kept. The block alone is the evidence, so the heal no longer depends on anything else:

  • a scan with no Maven patch, or with nothing to redirect at all (the patched dependency was bumped past the patch): such a scan now reads .mvn/maven.config for this alone;
  • a reactor root, or a root another rewriter owns;
  • no checksum line left for a hosted artifact, or no checksum file;
  • a config that no longer enforces the pin (a later line switches it off);
  • rollback / remove that leave the block beside the user's own settings heal it too.

A directory line that stands apart from the other five is the user's and is never rewritten.

The heal never fails a run. A scan with nothing to redirect takes the write lock for it when it can; when the lock is held elsewhere, or the file is a symbolic link (which a write would replace), the line is left as it is and nothing is reported.

The heal never trades enforcement away silently. Taking ${session.rootDirectory} out of a project that declares no Maven means a Maven 4 build of it stops enforcing the pin. The run that changes the line warns redirect_maven_trusted_checksums_maven3_only (maven_trusted_checksums_maven3_only from rollback / remove): what the line stopped, that Maven 3.9.4 and later 3.x enforce the checksums as before, that a Maven 4 build no longer does, and the remedy (declare Maven 4; the next scan writes the form Maven 4 reads). A heal that trades nothing (the wrapper names a Maven 3, the config enforces nothing, the heal goes towards the Maven 4 form) is silent.

One function says whether the Maven a project declares enforces a spelling, from the wrapper and the model (trusted_checksums::form_enforcement), with three answers where there used to be two: enforced, not enforced (and why), and enforced by Maven 3 only when the project declares no Maven and carries the default form. The conflict check, the heal, the unenforced warning and vex all use it:

  • A launcher-spelled directory line the user wrote, in a project that declares Maven 4 (by wrapper or by model), names no directory on Maven 4. It is left as written and reported as redirect_maven_trusted_checksums_conflict again, and redirect_maven_trusted_checksums_unenforced says so on every scan, with the remedy that works on Maven 4 instead of "upgrade the wrapper to 3.9.4".
  • vex takes a pin's checksum as the content the project pins only when the pin is known to be enforced. A project that declares no Maven and carries the default form is enforced by Maven 3 only, so its checksum is no longer taken. The statement itself does not depend on it: the suffixed version is the pin.

Outcomes that change

  • A hosted scan with nothing to redirect, in a project whose .mvn/maven.config holds the block in the other spelling, now writes that file (and takes the write lock, creating .socket/ if it is not there). Exit code unchanged. With nothing to heal such a scan reads one more file and writes nothing, as before.
  • redirect_maven_trusted_checksums_maven3_only and maven_trusted_checksums_maven3_only are new warning codes. Neither changes a status or an exit code.
  • redirect_maven_trusted_checksums_conflict is reported again for a launcher-spelled user line in a Maven 4 project (the first version of this PR dropped it for both spellings).
  • redirect_maven_trusted_checksums_unenforced now also fires for a project that declares Maven 4 by its model alone, and its text differs for the Maven 4 case.
  • Discovery no longer records the checksum of a default-form pin in a project that declares no Maven (locked_integrity). No Maven statement depends on it, so no vex output changes.
  • The heal's edit has its own key, so a consumer can tell it from the merge of the settings.
  • Vendored mode: a pom that says <modelVersion>4.0.0</modelVersion> under the 4.1.0 namespace is read as the 4.0.0 pom it is by both of its model readers. Before, one of them (parent inference) took it for 4.1.0 and the other (subproject discovery) for 4.0.0.

Decisions for the owner

  1. The default stays the launcher's property, and Maven 4 loses enforcement in projects that do not declare Maven 4. The alternative keeps it and stops Maven 3.9.2 to 3.9.8 from starting with -f from outside. A build that starts everywhere ranks above a pin enforced on a release-candidate Maven; see the first table. What is traded is now said by the run that trades it, and nothing reports such a pin as enforced.
  2. A fresh wiring of a project that declares no Maven does not warn. The scan says nothing about Maven 4 unless it changes an existing line: the same rule as for a Maven older than 3.9.4, which is also warned about only when the wrapper names it. The alternative is a warning on every hosted scan of every Maven project without a wrapper, nearly all of which are built with Maven 3. The docs and the contract state where the pin is enforced; vex does not take the checksum. Say so if every such scan should carry the note: it is one more arm in unenforced_detail, and it changes the warnings of about fifteen golden cases.
  3. Vendored mode's -Dmaven.repo.local.tail=${session.rootDirectory}/… has the same failure on the same versions and is not changed here. There the launcher's property on Maven 4 would break the build rather than skip a check. It stays reported as vendor_jvm_degraded (maven_f_outside_root). The choice of property is now a general helper (RootDirectory::for_maven), so vendored mode and the repository scoping PR can take it without a second copy.

Golden fixtures that change

The cases under crates/socket-patch-core/tests/fixtures/redirect/maven/pom/ are a contract shared with the rewriter's other implementation, in Socket's backend, which has to follow on its next update of this repository.

Expected output changed (15). In each, the summaryFile.basedir line of expected/.mvn/maven.config now reads ${maven.multiModuleProjectDirectory}/.mvn/checksums; nothing else differs:
basic, classifier-only-transitive-main, classifier-sources-sibling, comment-dependency, commented-repositories, depmgmt-comment, existing-depmgmt, existing-repositories, mvn-config-merge, plugin-dependency, profile-depmgmt, profile-repositories, self-closed-depmgmt, self-closed-repositories, transitive-depmgmt.

Input changed (1). rerun-noop: its input/.mvn/maven.config carries the new line, so a re-run of this release's wiring is still a no-op.

New (4).

  • rerun-heals-basedir: the wiring an earlier release left of basic (the session's form). Expected: only .mvn/maven.config, that one line rewritten; one redirect_maven_config / rewritten edit with key: "trustedChecksumsDirectory"; warnings ["redirect_maven_trusted_checksums_maven3_only"].
  • heals-basedir-without-a-patch: the same wiring after the dependency was bumped past the patch, with an empty overrides.json. Expected as above: the heal needs no patch.
  • maven4-model: basic with a 4.1.0 model. Expected as basic, with the session's form kept in maven.config; warnings [].
  • maven4-launcher-line-conflict: a wrapper that pins Maven 4.0.0 and the user's own directory line in the launcher's spelling. Expected: the pin and the checksums as in basic, the user's line kept with the five other settings appended; warnings ["redirect_maven_trusted_checksums_conflict", "redirect_maven_trusted_checksums_unenforced"].

Unchanged (4). no-suffix-fallback, profile-literal, property-version-warn, version-mismatch-skip.

Outside that directory: tests/fixtures/sbt/redirect/pom-also-present changes like the fifteen. The discovery golden gains the entries of the four new cases, and in 15 existing entries (the default-form cases, which declare no Maven) locked_integrity goes from the jar's sha256 to null.

Review findings

/code-review high returned nine. Each was confirmed against the code first.

# Finding Outcome Test
1 The heal is gated more narrowly than the failure Fixed: the block alone gates it, in the rewriter before every early return, in a scan with nothing to redirect, and in rollback / remove maven_checksums_block_is_healed_whatever_the_run_redirects, the_block_is_healed_whatever_else_the_config_sets, a_block_the_rollback_leaves_is_healed, a_run_with_nothing_to_redirect_heals_the_maven_config, scan_hosted_with_nothing_to_redirect_heals_the_maven_config, golden heals-basedir-without-a-patch
2 The heal drops enforcement silently while enforced() and vex still say enforced Fixed: the trade warning, and a third state that nothing reports as enforced maven_checksums_directory_follows_the_maven_the_project_declares (the warning and its text), enforcement_follows_the_maven_the_project_declares, checksums_attest_only_what_maven_enforces, golden rerun-heals-basedir
3 Conflict check, unenforced warning and enforced() look only at the wrapper; wrong remedy Fixed: one function over wrapper and model, used by all four; both cases of the finding are tests maven_checksums_launcher_line_conflicts_in_a_project_that_declares_maven_4, golden maven4-launcher-line-conflict
4 No CI leg runs Maven 4 against the default form Fixed: capstone step 4c, on every leg e2e_redirect_maven_build
5 The choice of property lives in trusted_checksums Fixed: declared_maven::{DeclaredMaven, RootDirectory}; Basedir is that type. Vendored behaviour unchanged (decision 3) A move, so nothing fails without it; pinned by the_root_directory_property_follows_the_declared_maven
6 A third reader of a pom's model version, with another rule Fixed: declared_maven::model_version_of, used by all three the_model_is_the_model_version_else_the_namespace, the_directory_is_spelled_for_the_maven_the_project_declares, the vendored discovery test's new cases
7 hosted_sums repeats other_hosted Fixed: the heal no longer needs the test at all (finding 1), and the restore's copy is trusted_checksums::names_hosted_artifact A move; pinned by a_checksum_file_names_a_hosted_artifact_by_its_suffixed_version
8 Two hand-copied six-line arrays; heal_basedir re-derives an index; stale expect text Fixed: one macro generates both, BASEDIR_AT names the line, config_settings owns the split A refactor; pinned by the_two_spellings_differ_in_the_directory_line_alone
9 maven.config parsed several times per scan Fixed: heal_basedir tests a substring before it splits anything and never parses; a run with no Maven patch and no block returns before it reads the pom; the settings are merged once per run instead of once per dependency; the final verdict parses once (Settings); discovery parses once and reads the wrapper only for a config that enforces Output is unchanged, so nothing fails without it; maven_checksums_conflict_is_reported_for_each_dependency pins that the one merge still reports per dependency

For findings 1 to 4 and 6 each named test asserts behaviour the previous head does not have.

Found while fixing, and fixed: the first version read a 4.0.0 model under the 4.1.0 namespace as a Maven 4 project and would have written the session's form for a pom Maven 3.9.2 to 3.9.8 build (the measured table above; the_directory_is_spelled_for_the_maven_the_project_declares).

Two ways the wider heal could have harmed a run are closed and tested. Every hosted write through a symbolic link is refused whole, so a heal of a linked .mvn/maven.config would have refused a run that had nothing to refuse before: it is withheld instead (a_symlinked_maven_config_is_left_unhealed_and_refuses_nothing). And a scan with nothing to redirect never fails for want of the write lock (scan_hosted_heal_waits_when_the_lock_is_held).

Bugbot findings (on 263eefab1)

  1. "Heal lock can bypass rollout cap" (High): not a defect, now pinned by a test. The claim was that a capped run which takes the write lock for a heal can then commit the pins the cap forbade. The lock never was what kept a capped run from committing: the rollout plan is. It defers every new row the budget cannot admit, and the rewrite runs again without them, whether or not the run holds the lock (a capped run without the lock committed whatever the plan left, exactly as it does with it). a_cap_of_zero_with_a_maven_config_to_heal_writes_nothing_but_the_heal (scan_rollout_e2e) runs a nine-package project with a block to heal under --max-new-patches 0: all nine rows are deferred, no pin lands, every file but .mvn/maven.config is byte-identical, and that file is healed. No code changed for this one.
  2. "Rollback heal can refuse restores" (Medium): real, fixed. The restore's flush is all or nothing and will not write through a symbolic link, so staging the heal for a linked .mvn/maven.config left every pin unrestored where the restore used to complete. Two commits close it. ecedf7505 (pushed to this branch by another session) returns before the heal when the config is a link, with a_linked_config_the_rollback_leaves_is_not_healed. 67d555f95 stages the heal only where the flush could write it (View::write_if_writable asks the flush's own preflight for that one file), which also covers a directory that does not take the write and a file edited since it was read: a_config_the_flush_could_not_write_is_not_healed fails without it. rollback and remove both restore through that function. The scan side now asks the same question instead of testing for a link alone (a_symlinked_maven_config_is_left_unhealed_and_refuses_nothing, extended with an unwritable directory).

Review findings not fixed

  • Part of finding 2, as read strictly: a scan that wires a project fresh with the default form does not warn that Maven 4 would not enforce it. Decision 2 above. The capstone's Maven 4 step asserts the report on the path that has one, the heal.
  • A config in which hosted mode appended only some of the six settings (the user had set one of them) is not healed. The directory line there is spelled exactly as Maven's own documentation spells it, so it cannot be told from one the user wrote, and rewriting a user's line could take their own pin's enforcement away on Maven 4.
  • Vendored mode infers omitted parent coordinates only for a pom of a newer model. Maven 4 infers them whatever the model (measured: an empty <parent/> under a 4.0.0 model builds on 4.0.0-rc-7). That rule is vendored mode's and predates this PR; only the reading of the model version is shared here.
  • The in-memory engine does not read .mvn/maven.config for a project with no candidate. It heals whenever it rewrites a project; a heal-only change with no patch to redirect is the CLI's.
  • With a symbolic link for .mvn/maven.config the heal is withheld after the rewriter has run, so that one run's unenforced warning is judged on the text the heal would have left. It affects only a linked config that holds the block in the other spelling.

Tests

  • Real Maven, e2e_redirect_maven_build (the capstone). Step 4b: the fresh checkout is built with -f <checkout>/pom.xml from another directory; every Maven must start and resolve the patched jar, and the re-signed tampered jar must be rejected from there by exactly the Mavens that enforce the pin elsewhere. Step 4c (new): the same checkout without the wrapper pin is scanned again and takes the default form; on the Maven 4 leg the scan must report redirect_maven_trusted_checksums_maven3_only, Maven 4 must start and resolve the patched jar from outside and from the root, and the re-signed jar must not be rejected there, as measured. On a Maven 3 leg nothing changes and the pin is enforced as in 4b.
  • Unit and golden: the tests named in the table, the restore in either form, and the round trip of every invertible golden case.

What I ran

On macOS, head 2ad7ef808 (main at 4fe085929 merged in):

  • cargo fmt --all -- --check: clean.
  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --tests --no-fail-fast: 8668 passed, 0 failed, 1 ignored (the discovery golden regenerated first, with no change).
  • The 17 Maven-related CLI suites and scan_rollout_e2e: 1303 passed, 0 failed.
  • e2e_redirect_maven_build with real Maven, required and not skipped: 2 passed on 3.9.16 and 4.0.0-rc-7. On the head before the last merge (67d555f95, which differs only in the restore): 2 passed on 3.9.4, 3.9.16 and 4.0.0-rc-7. On 263eefab1: also 3.6.3.
  • e2e_vendor_maven_build with real Maven on 3.9.16 (at 263eefab1; nothing vendored changed since): 5 passed. On 4.0.0-rc-7: 3 passed, 2 failed (maven_vendored_reactor_pins_each_module_at_the_version_it_selects, maven_vendored_parent_pin_goes_when_a_module_moves_on_and_reverts_clean), both on the assertion that .mvn/ is gone after vendor --revert. The same two fail on the same assertions on main (4fe085929) with that Maven, so they do not come from this change.
  • The model-version table comes from 16 mvn validate runs with an isolated home and local repository; the first table from about 190 builds against a logging server.

Not run: Linux and Windows (CI), the rest of the CLI suites.

For the hosted stack

#2114 moves this code (pin_maven_checksums), so merging main into it after this lands will conflict there; the resolution is to pass the declared Maven through and keep the heal ahead of every return. #2133 adds two more maven.config lines that name a directory through ${session.rootDirectory} and would bring the same failure back on Maven 3.9.2 to 3.9.8: they must take the property from RootDirectory::for_maven when main is merged forward. I will carry it that way and not by hand.


Generated by Claude Code

….2 to 3.9.8

A hosted scan writes, among its Trusted Checksums settings, the directory
of the summary file:

  -Daether.trustedChecksumsSource.summaryFile.basedir=${session.rootDirectory}/.mvn/checksums

On Maven 3.9.2 to 3.9.8 that property is undefined when the build is
started with `-f <project>/pom.xml` from outside the project, and Maven
then does not start at all (`Illegal use of undefined property:
session.rootDirectory`). A project that built before the scan stopped
building in a common CI invocation.

Measured with real Maven (3.6.3, 3.8.9, 3.9.0, every release from 3.9.2
to 3.9.9, 3.9.16, 4.0.0-rc-7; from the project root, from a module
directory and with -f from outside; plain and through the wrapper; each
with a genuine jar and with a tampered one whose .sha1 matches):

- `${session.rootDirectory}`: does not start with -f from outside on
  3.9.2 to 3.9.8; enforced everywhere from 3.9.9 and on Maven 4.
- `${maven.multiModuleProjectDirectory}`: starts everywhere on every
  Maven, enforced in all three invocations from 3.9.4; Maven 4 does not
  interpolate it, so nothing is enforced there and the build is
  unaffected.
- A path without a property is read from the local repository: never
  enforced.

No form is right on every Maven, so the form follows what the project
declares: the launcher's property by default, which breaks no build, and
the session's for a project that declares Maven 4 (its wrapper pins
Apache Maven 4, or its root pom is of model 4.1.0 or later). A Maven 4
build of a project that declares neither loses the content pin; the
suffixed version and the transport checksum still hold.

A project an earlier release wired is healed on its next scan: the one
line is rewritten in place when the six settings stand together as
hosted mode wrote them and a hosted pin's checksum line is there. A
directory line that stands apart was the user's before hosted mode
appended the rest: it is left as written, and no longer reported as a
conflict, since both forms name the same directory. Rollback, remove and
vex recognise either form, and the unenforced warning weighs the form in
place against the wrapper's Maven.

The capstone now also builds the fresh checkout with -f from another
directory, and checks that the re-signed jar is rejected from there by
the Mavens that enforce the pin. Its wrapper pins the Maven under test,
so its Maven 4 leg gets the session's form and stays enforced.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in main's public-wording pass. No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…trades

Review of the `mvn -f` fix found the heal gated more narrowly than the
failure, silent about what it trades away, and judged by the wrapper alone.

The heal. The six settings hosted mode wrote, standing together in the
spelling that is not this project's, are now the whole evidence. The
rewriter respells the line before any of its returns, so a run with no
Maven patch, a reactor root, a root another rewriter owns, a config with no
checksum line left or one a later line switches off are all healed. A scan
with nothing to redirect reads `.mvn/maven.config` for this alone, and
rollback and remove heal a block they leave in place. A directory line that
stands apart stays the user's.

The heal never fails a run. A scan that would write nothing else takes the
write lock for it when it can; when the lock is held elsewhere, or the file
is a symbolic link a write would replace, the line is left as it is.

The trade. Taking `${session.rootDirectory}` out of a project that declares
no Maven means a Maven 4 build of it stops enforcing the pin. The run that
changes the line now warns (`redirect_maven_trusted_checksums_maven3_only`,
`maven_trusted_checksums_maven3_only` from rollback and remove) with what
the line stopped, what still enforces the checksums and the remedy.

One verdict. `form_enforcement` answers whether the Maven a project
declares enforces a spelling, from the wrapper and the model, and has a
third answer: enforced by Maven 3 only, for the default spelling in a
project that declares no Maven. The conflict check, the heal, the
unenforced warning and discovery all ask it. So a launcher-spelled line the
user wrote in a Maven 4 project is a conflict again and is reported
unenforced with the remedy that works on Maven 4, whether the wrapper or
only the model declares Maven 4; and discovery records a checksum as the
content a project pins only where the pin is known to be enforced.

Shared helpers. `formats::maven::declared_maven` holds what a project says
about its Maven: the wrapper's release, the model of a pom
(`<modelVersion>`, else the namespace's version, as measured on Maven 3.9.9
and 4.0.0-rc-7), and the property that names the root directory on that
Maven. The vendored planner's two readers of a pom's model go through it,
so a 4.0.0 model under the 4.1.0 namespace is one thing to every reader.
The two six-line arrays come from one macro, the checksum-path test is one
function, and `maven.config` is parsed once per use: the heal tests a
substring before it splits anything, and the settings are merged once per
run instead of once per dependency.

The capstone gains a step that scans the checkout again without its
wrapper pin and builds it with the Maven under test: on the Maven 4 leg
that is Maven 4 against the default spelling, which must start and resolve,
with the trade reported by the scan.

Golden fixtures: `rerun-heals-basedir` now expects the trade warning and
the heal's own edit key; `heals-basedir-without-a-patch` and
`maven4-launcher-line-conflict` are new. The discovery golden follows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 00:37
@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted Maven config rewriting and checksum enforcement semantics across Maven 3 vs 4, but behavior is guarded by tests, optional heal-on-no-op scans, and non-fatal lock/symlink handling.

Overview
Hosted Maven Trusted Checksums now pick the .mvn/maven.config summaryFile.basedir property from what the project declares: ${maven.multiModuleProjectDirectory} by default (so Maven 3.9.2–3.9.8 no longer refuse to start with -f from outside the tree), and ${session.rootDirectory} when the wrapper or root POM indicates Maven 4.

Any scan --mode hosted that reads a legacy six-line block can respell only that directory line in place—even with no patches to redirect—including dry-run preview, rollback/remove, and a best-effort write that does not fail the run if the lock is held or the config is a symlink. Respelling to the launcher form in an undeclared Maven project emits redirect_maven_trusted_checksums_maven3_only (and the rollback twin) because Maven 4 then stops enforcing the pin.

Shared logic lives in new declared_maven plus refactored trusted_checksums (enforcement, heal, both spellings). CLI contract, fixtures, and e2e/in-process Maven tests cover -f from outside, undeclared-Maven rescans, and heal-without-redirect.

Reviewed by Cursor Bugbot for commit 263eefa. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 263eefa. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review and removed Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review labels Nov 19, 2026
main moved under files this branch touches (the redirect rewriter, the CLI
contract, the ecosystem docs). No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The restore's flush refuses a write through a symbolic link, and the
whole restore with it. Healing a leftover Trusted Checksums block in a
linked config therefore refused a rollback that wrote nothing to the
config before. Withhold the heal for a linked config, as hosted scan
already does.

Assisted-by: Claude Code:claude-opus-5-5
Review found that rollback and remove, which now respell a block they
leave in `.mvn/maven.config`, could fail a restore they used to complete:
the restore's flush is all or nothing and will not write through a
symbolic link, so staging the heal for a linked config left every pin
unrestored.

The heal is now staged only where the flush could write it
(`View::write_if_writable` asks the flush's own preflight for that one
file): a symbolic link, anything else that is not a regular file, a
directory that does not take the write or a file edited since it was read
keeps its line, and the pins are restored as before. The scan side asks the
same question instead of testing for a link alone, so a heal is not planned
into a directory the commit could not write either.

A second review comment said the heal's write lock lets a rollout-capped
scan commit pins the cap forbids. It does not: the cap is the rollout
plan's, which defers every new row the budget cannot admit and rewrites
again without them, with or without the lock. A test now pins that: under
a cap of zero, a project with a block to heal gets the heal and nothing
else, and no pin lands.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both fix the same review comment: a heal staged for a linked
.mvn/maven.config refused the whole restore. The pushed commit tests for a
link before the heal; the local one stages the heal only where the flush
could write it. Kept both: the link test returns early, and the flush's own
preflight covers what a link test cannot (a directory that does not take
the write, a file edited since it was read). The pushed test stays as it
is; the local one now covers the unwritable directory.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 19, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does: A hosted scan used to write the Trusted Checksums directory into .mvn/maven.config as ${session.rootDirectory}/.mvn/checksums. That stops Maven 3.9.2 to 3.9.8 from starting when a build runs mvn -f <project>/pom.xml from outside the project. It now writes ${maven.multiModuleProjectDirectory}/…, and keeps the session form only where a project declares Maven 4 (through its wrapper or a 4.1.0 model). Hosted scan, rollback and remove also heal the exact block that earlier releases wrote. The heal warns when it costs enforcement on Maven 4, and it never fails a run.

Risk: medium.

  • The code is careful and well tested, and it fixes a real build break.
  • But it rewrites a user-owned file in projects that were already wired, even when there is nothing to patch, and a no-op scan now takes the lock.
  • It deliberately drops enforcement on Maven 4 for projects that don't declare Maven 4 (decision 1 in the description).

Look here:

  • [declared_maven.rs:26-61](https://github.com/SocketDev/socket-patch/blob/2ad7ef808820d2d8930d17bf907ed877eebbd941/crates/socket-patch-core/src/formats/maven/declared_maven.rs#L26-L61): how a project's declared Maven, and so the property, is chosen
  • [trusted_checksums.rs heal_basedir](https://github.com/SocketDev/socket-patch/blob/2ad7ef808820d2d8930d17bf907ed877eebbd941/crates/socket-patch-core/src/formats/maven/trusted_checksums.rs#L162-L192): byte-preserving rewrite of the one line (CRLF and a missing final newline are kept)
  • [redirect/mod.rs:9006-9029](https://github.com/SocketDev/socket-patch/blob/2ad7ef808820d2d8930d17bf907ed877eebbd941/crates/socket-patch-core/src/patch/redirect/mod.rs#L9006-L9029): the heal runs before every early return
  • [scan/hosted.rs:1244-1271](https://github.com/SocketDev/socket-patch/blob/2ad7ef808820d2d8930d17bf907ed877eebbd941/crates/socket-patch-cli/src/commands/scan/hosted.rs#L1244-L1271) and [:1706-1718](https://github.com/SocketDev/socket-patch/blob/2ad7ef808820d2d8930d17bf907ed877eebbd941/crates/socket-patch-cli/src/commands/scan/hosted.rs#L1706-L1718): the lock for a scan that only heals, and when the heal is held back
  • hosted/engine.rs:2798-2810: the writability check (open question 2)

Verified:

  • Ran 90 targeted core unit tests on the head (filters declared_maven, trusted_checksums, upstream::maven, heal, maven_checksums): all pass.
  • The golden fixtures and the unit tests named in the description would fail without the change.
  • Both Bugbot findings are handled. The rollout cap holds (pinned by a test), and the rollback heal no longer refuses restores.
  • CRLF and Windows paths are handled.
  • CHANGELOG.md is untouched; there is no debug code.
  • CI is green on 2ad7ef8 (ci-ok, clippy).

Changes I made: none.

Open questions:

  1. The Maven versions this PR fixes did not run in PR CI. e2e-full was skipped. The only Maven e2e leg that ran was 3.9.16, which never had the bug. The 3.9.3, 3.9.4 and 4.0.0-rc-7 legs are in the extended matrix (ci.yml around 2196-2206), so so far the evidence is the author's local runs. Consider a full e2e run of e2e_redirect_maven_build on this SHA before approving. e2e_vendor_maven_build on 4.0.0-rc-7 also fails on main (Nightly: maven_reactor_implicit_subprojects fails on Maven 4.0.0-rc-7 ("the root is pinned") since 4fe0859 #2158).
  2. When .mvn/ is read-only and the root is writable, the scan may still fail. maven_config_writable goes through staged::preflight, which skips the directory check for a path a group commit is capturing, and scan always has a group open. So the heal is planned and its commit fails a scan that wrote nothing before this PR. This is rare. A follow-up fix: check .mvn/ directly, and add a case with a group open.
  3. Two messages are slightly off:
    • redirect_maven_multimodule_unsupported still says ".mvn/ was left as it is" when the heal may have rewritten maven.config.
    • The maven3_only warning still talks about checksums.sha256 after a rollback has just deleted that file.
  4. The golden fixtures are shared with Socket's backend, which needs a matching change. That should ship close to this release, or the backend will report pins it doesn't recognise as conflicts.
  5. Decisions 1-3 in the description need the owner's agreement. They look defensible. One more observation: the heal also rewrites projects whose wrapper pins Maven 3.9.9 or later, which never had the bug. That is harmless, but it churns a file users own.

Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed at 2ad7ef8. The heal, the form choice and the three enforcement states read correctly and are covered by the new golden cases and unit tests; both Bugbot threads are settled. Non-blocking: (1) maven_config_writable uses staged::preflight, which skips the directory-writable check for group-captured paths, and scan opens its group before the rewrite, so with a read-only .mvn/ a heal-only scan can plan the heal and then fail the commit with lockfile_write_failed where it used to exit 0 (from reading, not reproduced; the engine test for this runs with no group open); (2) the affected Maven versions (3.9.2 to 3.9.8) did not run in PR CI, since e2e-full and e2e-extended were skipped; (3) the shared golden fixtures change, so the backend rewriter needs the matching change.

Merged via the queue into main with commit 74718d6 Nov 19, 2026
50 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/maven-hosted-f-outside-root branch November 19, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants