Repository navigation
Stop the Maven Trusted Checksums line breaking -f builds on Maven 3.9.2 to 3.9.8 - #2145
Conversation
….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>
PR SummaryMedium Risk Overview Any Shared logic lives in new Reviewed by Cursor Bugbot for commit 263eefa. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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.
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>
|
[agent] PR shepherd: review brief for the approver What it does: A hosted scan used to write the Trusted Checksums directory into Risk: medium.
Look here:
Verified:
Changes I made: none. Open questions:
Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[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.

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 hostedwrites Maven Trusted Checksums settings into.mvn/maven.config, among them the directory of the summary file:On Maven 3.9.2 to 3.9.8,
session.rootDirectoryis undefined when the build is started with-f <project>/pom.xmlfrom 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
.sha1matches (so only the trusted checksum can catch it). "enforced" means the genuine build succeeds and the tampered one fails on the trusted checksum.${session.rootDirectory}(released)${maven.multiModuleProjectDirectory}-ffrom outside: does not start-ffrom outside: does not startmvn -f <project>/pom.xmlfrom another directory. The-fcolumn was run on every release from 3.9.2 to 3.9.9; the boundary is exactly 3.9.8 / 3.9.9.only-script, pinning 3.9.4),./mvnwbehaves as Maven 3.9.4 does in all three invocations, for both forms.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 validateon apom-packaged root with achild/pom.xmlbeside it):<modelVersion>'modelVersion' is missing'modelVersion' is missingSo 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/checksumsby 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/checksumsfor a project that declares Maven 4: its Maven Wrapper pins Apache Maven 4 or later, or its rootpom.xmlis 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:.mvn/maven.configfor this alone;rollback/removethat 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 warnsredirect_maven_trusted_checksums_maven3_only(maven_trusted_checksums_maven3_onlyfromrollback/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 andvexall use it:redirect_maven_trusted_checksums_conflictagain, andredirect_maven_trusted_checksums_unenforcedsays so on every scan, with the remedy that works on Maven 4 instead of "upgrade the wrapper to 3.9.4".vextakes 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
.mvn/maven.configholds 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_onlyandmaven_trusted_checksums_maven3_onlyare new warning codes. Neither changes a status or an exit code.redirect_maven_trusted_checksums_conflictis 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_unenforcednow also fires for a project that declares Maven 4 by its model alone, and its text differs for the Maven 4 case.locked_integrity). No Maven statement depends on it, so novexoutput changes.key, so a consumer can tell it from the merge of the settings.<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
-ffrom 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.vexdoes not take the checksum. Say so if every such scan should carry the note: it is one more arm inunenforced_detail, and it changes the warnings of about fifteen golden cases.-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 asvendor_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.basedirline ofexpected/.mvn/maven.confignow 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: itsinput/.mvn/maven.configcarries 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 ofbasic(the session's form). Expected: only.mvn/maven.config, that one line rewritten; oneredirect_maven_config/rewrittenedit withkey: "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 emptyoverrides.json. Expected as above: the heal needs no patch.maven4-model:basicwith a 4.1.0 model. Expected asbasic, with the session's form kept inmaven.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 inbasic, 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-presentchanges 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_integritygoes from the jar's sha256 tonull.Review findings
/code-review highreturned nine. Each was confirmed against the code first.rollback/removemaven_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, goldenheals-basedir-without-a-patchenforced()andvexstill say enforcedmaven_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, goldenrerun-heals-basedirenforced()look only at the wrapper; wrong remedymaven_checksums_launcher_line_conflicts_in_a_project_that_declares_maven_4, goldenmaven4-launcher-line-conflicte2e_redirect_maven_buildtrusted_checksumsdeclared_maven::{DeclaredMaven, RootDirectory};Basediris that type. Vendored behaviour unchanged (decision 3)the_root_directory_property_follows_the_declared_mavendeclared_maven::model_version_of, used by all threethe_model_is_the_model_version_else_the_namespace,the_directory_is_spelled_for_the_maven_the_project_declares, the vendored discovery test's new caseshosted_sumsrepeatsother_hostedtrusted_checksums::names_hosted_artifacta_checksum_file_names_a_hosted_artifact_by_its_suffixed_versionheal_basedirre-derives an index; staleexpecttextBASEDIR_ATnames the line,config_settingsowns the splitthe_two_spellings_differ_in_the_directory_line_alonemaven.configparsed several times per scanheal_basedirtests 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 enforcesmaven_checksums_conflict_is_reported_for_each_dependencypins that the one merge still reports per dependencyFor 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.configwould 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)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.configis byte-identical, and that file is healed. No code changed for this one..mvn/maven.configleft 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, witha_linked_config_the_rollback_leaves_is_not_healed.67d555f95stages the heal only where the flush could write it (View::write_if_writableasks 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_healedfails without it.rollbackandremoveboth 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
<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..mvn/maven.configfor 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..mvn/maven.configthe 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
e2e_redirect_maven_build(the capstone). Step 4b: the fresh checkout is built with-f <checkout>/pom.xmlfrom 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 reportredirect_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.What I ran
On macOS, head
2ad7ef808(mainat4fe085929merged 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).scan_rollout_e2e: 1303 passed, 0 failed.e2e_redirect_maven_buildwith 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. On263eefab1: also 3.6.3.e2e_vendor_maven_buildwith real Maven on 3.9.16 (at263eefab1; 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 aftervendor --revert. The same two fail on the same assertions onmain(4fe085929) with that Maven, so they do not come from this change.mvn validateruns 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 mergingmaininto 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 moremaven.configlines 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 fromRootDirectory::for_mavenwhenmainis merged forward. I will carry it that way and not by hand.Generated by Claude Code