Repository navigation
Read Maven checksums.sha256 one way and never drop user lines - #2016
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Conversation
The hosted Maven merge re-parsed .mvn/checksums/checksums.sha256 on a two-space separator, rebuilt the file from that map and silently dropped every line it could not split that way: a user's single-space or `*` (binary marker) sha256sum line, a tab-separated line, a comment, any stray text. It also normalized a CRLF file to LF and re-sorted it. The file and the maven.config switch were read four different ways (discovery, the hosted merge, its drop filter, the unenforced-pin warning) plus a fifth in the upstream unwind. They now share one pure reader in formats::maven::trusted_checksums: - parse_line / entries: tolerant read of what sha256sum-style tools emit (any run of spaces/tabs, an optional `*`, CRLF, surrounding blanks; a 64-digit hex hash). Each entry records whether it is in the exact `<hash> <path>` shape maven-resolver's own reader honours. - pinned: path -> hash of the lines Maven enforces, a later line winning (as in SummaryFileTrustedChecksumsSource). - edit: rewrites owned paths in place, drops named paths, inserts new entries in sorted position (else appends) with the file's own line ending, and keeps every other line byte for byte. - switch_on: the trusted-checksums switch rule, decided once: read maven.config with the existing shared maven_config_properties reader (one argument per line, `#` comments, -Dk / --define, later wins) and judge the value as the resolver does (Boolean.parseBoolean). Discovery, the hosted merge/drop/warning and the unwind all use it. Discovery now attests integrity only from lines Maven itself enforces; a tolerated spelling is recognised (and replaced or dropped when it names a path hosted owns) but pins nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
|
Labeled Ready for review (burn-down agent).
Generated by Claude Code |
Review fixes on the shared trusted_checksums reader: - The enforcement rule (config_enforces) now needs every setting Maven reads .mvn/checksums/checksums.sha256 by, with the resolver's defaults: the post-processor on, checksumAlgorithms naming SHA-256, the summary-file source on, its basedir at .mvn/checksums and originAware off. Settings are whole-line arguments only (Maven 3.9+, the only line that enforces), never a -Dk=v token inside a longer line; the per-line reading is split out of maven_config_properties as maven_config_line_properties. - enforced() adds the wrapper rule the hosted rewriter already warned on (an Apache Maven < 3.9.4 ignores the files). Discovery attests only through it, so VEX never claims integrity Maven does not check: the mvn-config-merge fixture keeps the user's originAware=true and its golden loses its integrity. - An uppercase-hex line no longer counts as read by Maven (it compares to its own lowercase digest). - Lines for a path hosted mode owns are recognised whatever their hash, so a stale SRI or truncated line is replaced, dropped on re-pin and dropped by the unwind; a grant hash that is not 64 hex digits writes no checksum line (redirect_maven_trusted_checksums_invalid_hash). - edit collapses an owned path to one line, inserts ahead of the comment block directly above the line it lands before, and inserts with the file's dominant line ending; it writes into one buffer. - The written maven.config args and the keys read come from one literal per settings prefix (CONFIG_ARGS, re-exported as MVN_CONFIG_ARGS). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Final review brief (for the human approver)What it does: adds one pure module, Risk: low to medium. The logic is pure, unit-tested and idempotent. VEX output changes on purpose: integrity is no longer attested for Look here
Verified
Changes I made: none. Open questions (nits, none blocking)
Auto-merge is not armed yet because Generated by Claude Code |
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ec69ff3. Configure here.
|
Ready for review re-confirmed at the new head (burn-down agent).
Generated by Claude Code |
Second review round on the Trusted Checksums change. - The hosted writer (`merge_mvn_config`) still keyed settings by the raw `line[..=eq]` prefix, so a user's indented, `--define k=v` or quoted setting was not seen, hosted appended its own line after it, and that later line won, silently overriding the user's value. It now reads the file with `maven_config_line_properties`, the reader discovery judges enforcement with, and reports such a setting as `redirect_maven_trusted_checksums_conflict`. - A grant whose sha256 is not 64 hex digits writes no checksum line, but a line an earlier release wrote for the same suffixed version (its hash mangled) stayed, and Maven fails the build on a mismatched line. Those paths are now dropped, on a fresh pin and on a re-run alike. - The rollback's leftover-settings warning keys on presence again (`maven_config_properties`, which also sees a `-Dk=v` token joined onto a longer line), not on Maven 3.9's enforcement reading. - The discovery module doc and docs/ecosystems.md describe the stricter attestation rule and the invalid-hash warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Hosted Maven merged into
.mvn/checksums/checksums.sha256by splitting every line on two spaces, rebuilding the file from that map, and silently dropping any line it couldn't split that way. That deleted a user's single-space line, a*(binary marker) line, a tab-separated line, comments and stray text. It also rewrote a CRLF file as LF and re-sorted every line.The file and the
.mvn/maven.configsettings were read five different ways (discovery, the hosted merge, the hosted drop filter, the unenforced-pin warning, the upstream unwind), and each judged differently whether Maven enforces the file.Change
One pure module,
formats::maven::trusted_checksums(no I/O, no host policy), used by all five sites.parse_line,entries): tolerant. It accepts what sha256sum-style tools write: one or more spaces or tabs, an optional*, CRLF, blanks around the line.#lines are comments. The first field doesn't have to be a valid hash, so a line for a path hosted mode owns is recognised whatever its hash. Each entry recordsmaven_reads: true only for the exact<64 lowercase hex> <path>shape that maven-resolver'sSummaryFileTrustedChecksumsSourcechecks. Maven splits on exactly two spaces, doesn't strip*, and compares against its own lowercase digest.pinned: path → hash for the lines Maven checks. A later line for the same path wins.edit:config_enforces: the one rule, documented in the code.maven.configis read the way Maven 3.9+ reads it, one argument per line (maven_config_line_properties, split out ofmaven_config_properties). It then requires every setting Maven reads this file by, judged with the resolver's defaults: post-processor on,checksumAlgorithmsnaming SHA-256, summary-file source on,basedirat.mvn/checksums,originAwareoff.enforced:config_enforcesplus the Maven Wrapper rule hosted already warned on. An Apache Maven older than 3.9.4 ignores the files; no wrapper, or another distribution, counts as enforcing.CONFIG_ARGS: themaven.configlines hosted writes. They and the keys read are built from one literal per settings prefix.How each site uses it:
edit. A file is written only when its text changes. A grant hash that isn't 64 hex digits writes no checksum line and warnsredirect_maven_trusted_checksums_invalid_hash; the-socketversion pin still lands.config_enforces+pinned+ the wrapper ruleenforced+pinned. VEX attests integrity only when Maven checks it, and hosted's judgment and discovery's now match.edit. The "resolver lines left" warning usesconfig_has_written_settings(presence).Golden change: in
redirect-maven.json,mvn-config-merge/expectedgoes fromlocked_integrity: Sha256Hex(ccc…)tonull. That fixture keeps the user'soriginAware=true, under which Maven readschecksums-<repoId>.sha256, not this file, so the old attestation was false.Review findings (
/code-review high)Each finding was confirmed with a failing test on the previous head (
26d9d3b) before it was fixed.-Dk=vtoken inside a longer line no longer counts. Only whole-line arguments do.config_enforcesnow checks all five settings Maven reads the file by, not just the switch.failIfMissingdoesn't decide whether a committed line is checked, so it isn't required. The unwind keeps presence semantics on purpose: its warning is about leftover lines hosted mode may have written, and a partial or switched-off set is still worth removing.restore_mvnno longer returns early. Grant hashes are validated when written.maven_reads = falseand doesn't attest.TRUSTED_CHECKSUMS_ONis gone.CONFIG_ARGSand the keys share one literal per prefix.editwrites into one buffer, with no per-lineformat!. It still scans once for which owned paths are present before writing. A true single pass can't know whether an owned path appears later without moving that line, and moving it would churn a file the user ordered. The scan is one cheap parse of a tens-of-lines file.Tests
maven_checksums_merge_keeps_every_user_line: fails before the first commit, passes after. User lines in single-space,*, tab, comment and stray-text form survive a pin and a re-pin.maven_checksums_owned_lines_go_whatever_their_hash: hosted re-pin with stale hashes, and refusal of an invalid grant hash.checksums_unwind_drops_owned_lines_whatever_their_hashandchecksums_unwind_reads_every_spelling_and_keeps_crlf: the unwind.checksums_attest_only_what_maven_enforces: discovery across config, wrapper and spelling cases.formats::maven::trusted_checksums(12 tests).every_fail_closed_rewriter_fixture_yields_the_patch_uuid_not_the_tokennow expects no integrity formvn-config-merge, for theoriginAware=truereason above.cargo test -p socket-patch-core --lib -- formats::maven vex::discover:: patch::redirect:: vendor::jvm::: 1591 passed, golden included.socket-patch-clie2e_vex_lockfile+in_process_get_hosted_ecosystemsfiltered tomaven: 20 passed.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --all -- --checkare clean.Not done
maven.config(merge_mvn_config) is unchanged.SHA256 (path) = hashlines are not interpreted. They are kept verbatim.basedirspelled differently from what hosted writes (for example an absolute path to the same directory) counts as not enforced. That errs toward claiming less.Review findings, round 2 (
/code-review highonec69ff3, cloud routine)Fixed in
a53a056. Each test below failed onec69ff3.maven_checksums_owned_lines_go_whatever_their_hash(extended).maven.configits own way: confirmed and fixed.merge_mvn_configkeyed settings by the rawline[..=eq]prefix. A user's indented,--define k=v,--define=k=vor quoted setting wasn't seen, so hosted appended its own line, and that later line won. The user's value was silently overridden, against the documented contract. The writer now usesmaven_config_line_properties, discovery's reader. Test:maven_config_conflict_in_any_spelling_keeps_the_user_value.config_has_written_settingsis presence-based again (maven_config_properties, which also sees a-Dk=vtoken joined onto a longer line). This matches round 1's "the unwind keeps presence semantics". Test:config_enforces_needs_every_setting_maven_reads_the_file_by(the assertion is flipped).docs/ecosystems.mdnow describe the five-setting and wrapper rule and theredirect_maven_trusted_checksums_invalid_hashwarning.Declined:
basedirspellings (${maven.multiModuleProjectDirectory}/..., trailing/). These still count as not enforced. That errs toward claiming less (owner decision 4), as the "Not done" section already says.maven.configread twice in discovery, and thetrusted_checksumsfn/module name clash. Both are minor and left as is.Tests (cloud run):
cargo test -p socket-patch-core --lib -- formats::maven vex::discover:: patch::redirect:: vendor::jvm::gives 1591 passed. The one failure,vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry, fails only because the container runs as root, where chmod 0555 doesn't block. CLIe2e_vex_lockfileandin_process_get_hosted_ecosystemsfiltered tomavenpass. clippy and fmt are clean.Note
Medium Risk
Touches hosted Maven wiring, rollback/unwind, and VEX attestation for checksum pins; behavior is more conservative (fewer false attestations) but changes long-standing merge semantics.
Overview
Hosted Maven used to merge
.mvn/checksums/checksums.sha256by splitting on two spaces, re-sorting, and dropping lines it could not parse (single-space/sha256sum-style lines, comments, CRLF quirks). That logic lived separately from discovery, unwind, and the “unenforced pin” warning, so the same file was judged inconsistently.This PR adds
formats::maven::trusted_checksums, a pure module shared by the hosted rewriter, rollback/unwind, and VEX discovery. It tolerantly parses user lines but only treats exact<64 lowercase hex> <path>entries as Maven-enforced pins;editrewrites owned paths in canonical form, drops superseded pins, inserts with the file’s dominant line ending, and keeps every other line byte-for-byte.config_enforces/enforcedalign on Maven 3.9+ whole-linemaven.configarguments (via newmaven_config_line_properties) plus wrapper ≥ 3.9.4.Behavior changes: invalid grant SHA-256 (not 64 hex) skips checksum lines with
redirect_maven_trusted_checksums_invalid_hash(version suffix still applies); VEX no longer attests checksum integrity when config/wrapper/spelling means Maven would not enforce (e.g.mvn-config-mergewithoriginAware=true→locked_integrity: nullin golden).Reviewed by Cursor Bugbot for commit ec69ff3. Configure here.
Generated by Claude Code