Repository navigation
Accept the manifest of a re-signed provider jar - #2137
Conversation
…ream Agent mode and vendored mode read jars through the zip reader written for Python wheels: 10,000 entries and 64 MiB inflated at most, regular-file entries only, both jars held whole in memory. Released jars are past those caps (hive-exec-3.1.3: 23,728 entries, 93 MiB), so agent mode refused them as "the patch service's jar is unreadable", and a vendored one could not be attested, re-vendored online or repaired. Jars now have their own reader (patch/jar_members): member by member, hashing as it inflates, bounded by what is actually inflated and by the archive's own entry count rather than by declared sizes. The limits are 200,000 entries, and per pass 1 GiB inflated and 100 times the jar's size (64 MiB for a small jar). A jar past one is jvm_jar_too_large (agent) or vendor_artifact_too_large (vendored), and the message names the limit. The comparison of a patched jar with the original covers every entry the JVM would load, whatever unix mode it carries: an entry with a symlink's mode bits was skipped, so a class added that way went unseen. Directory entries and signature files stay exempt. A first vendoring makes that comparison too, against the registry-verified upstream jar and before anything is written. It used to run only on an online re-run over a committed tree, so a service jar built from another base was committed and wired. A copy that differs outside the patch now fails with jvm_agent_service_jar_mismatch, naming the members; the per-copy error carried no code. A ~/.m2 jar that another project (or an earlier workspace over a cached repository) patched has no backup in this project. Its rollback now restores the registry's jar when the download matches the registry's checksum and is the jar the copy was patched from, and otherwise says what happened and how to recover, as does an apply over a copy that holds another revision of the patch. -Dmaven.repo.local in the project's .mvn/maven.config names the local repository, between the command line (MAVEN_ARGS) and MAVEN_OPTS, as in Maven 3.6.3, 3.8.9, 3.9.16 and 4.0.0-rc-7. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Read `.mvn/maven.config` only for a Maven build, and as its Maven reads it. A Gradle or Scala-tool build's mavenLocal() never reads the file, so such a project keeps the environment's repository. Maven before 3.9 splits the file on whitespace and interpolates nothing; 3.9 and later take a line as one argument. The Maven Wrapper says which applies; without one the reading whose directory exists is used, and when both exist no repository is guessed at (maven_local_repository_undetermined). An empty value and an undefined placeholder resolve as Maven resolves them, instead of falling through to the settings. A first vendoring no longer fails when the registry cannot be reached while the patch service can. The baseline is the registry-verified jar, else the local repository's jar, else none; the last two are reported (vendor_jvm_upstream_unverified). A mismatch is still a refusal. A rollback reads the copy before it looks for a backup or downloads anything: a `~/.m2` copy past the jar limits fails as that, not as a missing backup, and a Gradle copy's backup is found by its hash directory without reading the copy. The copy is hashed once. The central directory is bounded by what the archive's end records declare, before the zip reader parses it: 200,000 entries, 64 MiB. Also: the Gradle classifier check fails closed on a jar it cannot read; `vendor --check` names the limit a jar is past; the digest passes run on the blocking pool and identical copies are read once; a copy's refusal code travels beside its result instead of being parsed out of the text. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A signed jar's manifest holds each entry's digests, and its signature files vouch for the manifest. Patching a class of a signed security provider therefore means re-signing the jar: the patch service drops upstream's signature files, adds its own, and gives the manifest sections of the patched members new digests. The agent swap and the vendored comparison refused that jar, since META-INF/MANIFEST.MF is a member outside the patch that changed. The manifest may now differ in exactly that way and no other: the jar is signed, the main attributes are byte for byte the original's, every section of a member the record does not touch is present and identical, a changed member's section differs only in its <ALG>-Digest values and each digest is the digest of that member in the patched jar, and a section is added or removed only with a member the record adds or deletes. Anything else stays the coded refusal, now with the reason. A rollback finds the original of a re-signed copy by the same rule. The manifest is parsed as the JAR specification lays it out and its sections are compared as the bytes in the file. The tests use a jar signed by jarsigner and the same jar patched and signed again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The patch service's signer now signs a patched provider as a whole, as jarsigner does, because a current JDK ignores SHA-1 digests: a jar whose manifest held only those left one signed class among unsigned siblings. Untouched sections therefore gain a digest line for the signing digest, and an entry upstream never listed gains a section. The rule required untouched sections to be byte-identical, so it refused those jars. An untouched member's section now keeps every line, byte for byte and in order, and may gain digest attributes, each recomputed from the member in the patched jar. A changed member's section may also change its digest values. A section is added only for a member the record adds or changes, or for an entry both jars hold with the same bytes; it is removed only for a member the record deletes. Only the digest attributes the JDK reads count (SHA-256, SHA-384, SHA-512, SHA-1, MD5). A last line of the original with no terminator is dropped before the comparison. The fixtures are the service's own output for five upstream shapes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
apply_jar_swap and rollback_jar_swap verified a copy's patched members through the zip reader directly, before the bounded reader saw the jar: the central directory was parsed, and allocated for, whatever the end records declared, and a member was inflated with no budget. A copy past the limits, or one with a hostile end record, could exhaust memory there instead of failing as jvm_jar_too_large, and a ~/.m2 rollback could go on to the registry afterwards. The member check now goes through the bounded reader, so the limits on the entry count and the central directory are held to the end records before anything parses the directory, and members are inflated within the pass's budget. A copy past a limit is refused there: jvm_jar_too_large on apply, with the run warning, and on rollback, before any backup is read or anything is downloaded. The unbounded member hasher has no caller left and is removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest # Conflicts: # crates/socket-patch-core/src/patch/jvm_jar.rs
Look a member up by the raw bytes of its name. The zip reader's own lookup is by a name it decodes as CP437 when an entry lacks the UTF-8 flag, so a UTF-8 name written without it was missed and a valid jar refused as holding a section for a member it does not hold. Read the manifest within the jar limits alone: the 16 MiB cap of its own was below them. A jar past a limit while the manifest is read is the caller's too-large refusal, not a difference. Replace the MD5 that computed its constants with f64::sin and held the whole member: a constant table, fed block by block, checked against the RFC 1321 vectors. Take a member's SHA-256 from the digests the comparison already holds instead of inflating it again, open each jar once and parse each section once. Match a changed digest line without regard to the case of its name. Name signing in a refusal only when the patched jar is signed: an unsigned jar whose manifest differs is the ordinary wrong-base case. Remove what no caller reaches: a section dropped with a member the record deletes (every path requires a record member at its afterHash), and the baseline taken from a record that lists the manifest. Such a jar is refused for now, and the contract says so. The docs state the rule as implemented. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview A new
Reviewed by Cursor Bugbot for commit 6ea9c11. Configure here. |
|
[agent] PR shepherd: review brief for the approver What it does. Agent mode and vendored mode now accept a provider jar (such as Risk: medium. It relaxes an integrity check, but the relaxation is narrow and fails closed. I probed it with CR-only line endings, duplicate sections, re-wrapped lines, case tricks, extra sections for entries outside the record, and a changed main section. Every probe was refused. It doesn't verify the signature itself; that stays the JVM's job. Stacked: the base is Look here
Verified
Changes I made: none. Open questions
Updated 2026-11-19: the head moved to Generated by Claude Code |
The check before the parse read the last 64 KiB of the file and the 56 bytes at the zip64 locator's offset. The zip reader does not take the end record from there: it looks for one backwards through the whole file, finds a zip64 record forwards from where the locator points, and falls back to an earlier end record when a directory does not parse. With bytes appended after the end record, an archive of 200,001 entries passed the check and was parsed whole before the count refused it. The check now walks as the reader does. It finds the last end record the reader can take and holds it to the limits. The reader is then shown zeros below that record's central directory while it opens the archive, so the only records it can fall back to are in the directory itself, and each of those is held to the limits as well. A record the reader would pass over is passed over; after 64 of them the archive is given up, since each costs a search of the file. An end record in a member's data, as a jar stored inside a fat jar has, is below the outer directory: the reader cannot take it, so it is not looked at, whatever it declares. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest # Conflicts: # crates/socket-patch-core/src/patch/jar_members.rs
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed at 080e243. The relaxation is narrow and fails closed: member-by-member comparison still runs first, only META-INF/MANIFEST.MF can be lifted out of the changed set, only for a served jar carrying a signature file, with the main section byte-identical and every added or changed digest recomputed from the served member; dropped or duplicate sections, unknown digest algorithms and bad base64 are refused. Non-blocking: resigned does not require the original to be signed, so an unsigned upstream served with a signature would be accepted (no tamper path, but a possible signer mismatch at runtime). Lands after #2132.
Vendoring a Maven or Gradle patch downloaded the original jar from the registry to compare the patch service's jar with, and refused or warned when it could not. It does not need the registry for that: the service's jar is checked as it was served (transfer integrity, the record's members at their afterHash) and committed. One comparison stays, since it costs no network and protects the build. When the original jar is already in the build's local repository, the members the patch does not touch must be that jar's, as agent mode requires before a swap. A difference means the project builds with a jar that is not the one the patch was made from, and the refusal says so. With no local copy nothing is compared and nothing is said. An online re-run over a committed tree makes the same local comparison and no longer needs the registry for the jar. Upstream metadata (pom, parents, module metadata, classifier jars) is read as before. Document that a project's .mvn/maven.config chooses where apply, rollback and remove write, what they do there, and that MAVEN_REPO_LOCAL takes the choice back. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest # Conflicts: # crates/socket-patch-cli/CLI_CONTRACT.md # crates/socket-patch-core/src/vendor/maven_repo.rs
…d-checks main moved wrapper_maven_version into formats::maven::declared_maven and added shared answers to which Maven a project declares and how a maven.config line is read. The local repository lookup now uses them: DeclaredMaven (the wrapper's release, or a root pom only Maven 4 reads) decides how .mvn/maven.config is read, maven_config_line_properties is the reading for Maven 3.9 and later, and RootDirectory says which root directory property the declared Maven fills in. The whitespace reading of Maven before 3.9 and the choice between the two readings stay here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The base PR (#2132) was squash-merged into main, so the branch's copy of its commits conflicted with the squash. Resolved by a three-way merge over the base PR's last head, so the result carries main plus exactly this PR's own changes. Assisted-by: Claude Code:claude-opus-5-5
Stacked on #2132. Lets agent mode and vendored mode accept a signed jar that the patch service patched and signed again, and nothing else that touches the manifest.
Why
A signed jar's
META-INF/MANIFEST.MFholds a section per entry with that entry's digests, and the signature files vouch for the manifest. A JVM that requires a valid signature, as it does for a JCE provider such as Bouncy Castle'sbcprov, refuses the jar once a class changes. So the patch service signs a patched provider again, as a whole, the wayjarsignerdoes: upstream's signature files go,META-INF/SOCKET.SFandSOCKET.RSAare added, and every file entry is listed in the manifest under the signing digest. A current JDK ignores SHA-1 digests, so a manifest that holds only those gains a SHA-256 line in every section, and an entry upstream never listed gains a section of its own.Signature files were already outside the "everything else is the original's" comparison. The manifest was not, so the agent swap refused such a jar with
jvm_agent_service_jar_mismatchand vendoring withvendor_prebuilt_integrity_mismatch.The rule
The served jar must carry a signature file, and its manifest may differ from the installed (agent) or upstream (vendored) manifest only as follows:
Nameand verified digests alone.A digest attribute is one the JDK reads when it verifies a jar:
SHA-256-Digest,SHA-384-Digest,SHA-512-Digest,SHA1-Digest,SHA-1-Digest,MD5-Digest. They are matched without regard to case. An added or changed attribute of any other name is a refusal. Anything else is the existing coded refusal; for a signed jar the reason is appended, and an unsigned jar whose manifest differs keeps the plain wrong-base message.The manifest is parsed as the JAR specification lays it out, and sections are compared as the byte ranges in the file. Blank lines are not compared, so a terminator added before appended sections changes nothing; a last line of the original with no terminator, which a JVM ignores, is dropped before the comparison. Members are matched by the raw bytes of their names. The manifest has no size limit of its own below the jar limits, and a jar past a limit while it is read is
jvm_jar_too_largeorvendor_artifact_too_large, never a mismatch. The signature itself is not verified; that stays the JVM's job.One function (
difference_outside_patch) backs the agent swap, the vendored comparison, and the rollback's search for the original of a patched copy.One thing goes past the five points as first written: a new section is also accepted for a member the record changes, not only for one it adds. The service's output needs it: in its
unlistedfixture the changed class had no section upstream and gets one.Limitation
A jar whose patch record itself lists
META-INF/MANIFEST.MFis refused for now when the service signed it again. The manifest is then a member the record changes, held to itsafterHash, and the signed manifest is that blob with its digests completed, not the blob. Accepting it needs the record's blob wherever a member is held to itsafterHash, androllback,vexand the vendored check do not have it at hand. It is a follow-up;CLI_CONTRACT.mdstates the limitation.Review findings
All ten were confirmed. Nine are fixed; one is fixed in part.
a_member_is_found_by_the_raw_bytes_of_its_name,a_member_with_a_non_ascii_name_and_no_utf8_flag_is_verified).a_large_manifest_is_read_and_a_limit_is_a_limit).a_sha256_digest_is_checked_without_inflating_the_member_again).f64::sin. Fixed: a constant table, fed block by block, checked against the RFC 1321 suite including the 62- and 80-character vectors and members of several blocks (member_digests_are_the_algorithms_a_manifest_names). No MD5 crate was in the lockfile, so none was added.afterHash. The branch, its test and the contract sentence are removed.a_record_that_lists_the_manifest_is_not_accepted_yet).signing_is_named_only_for_a_signed_jar).a_digest_attribute_is_matched_whatever_its_case).Review findings not fixed
SHA-224-Digestand the SHA-3 ones. An added or changed attribute of that kind stays a refusal: it fails closed, and the service writes none of them.Exit status
applyof a re-signed provider jarjvm_agent_service_jar_mismatchvendor_prebuilt_integrity_mismatchCLI_CONTRACT.mdstates the rule under agent mode and points to it from the vendored JVM section.Tests
The fixtures under
crates/socket-patch-core/tests/data/resigned-provider/service/are the patch service's own output for five upstream shapes, upstream and served jar for each (4 to 6 KB). Thejarsignerpair from the first commit stays as the one-digest-changed case.sha256); a SHA-256 line inserted in every section of a SHA-1-only manifest (sha1-only); sections appended for entries upstream never listed (unlisted); an unterminated last line dropped and a section appended for an added member (unterminated-line);\nline endings; a non-ASCII member name without the UTF-8 flag; a 17 MiB manifest; a digest attribute in another case.SHA-224-Digest; an appended section for an entry that is not in the installed jar or the record; a changed existing line on an untouched section; a non-digest attribute or a stale digest on the changed member; a main attribute changed; a dropped section; an unsigned jar; a record that does not change the member.jarsignerpair.I also ran the rule by hand over the service's re-signed
bcprov-jdk15on-1.47(SHA-1 only, 1,718 sections gain a SHA-256 line) andbcprov-jdk18on-1.78. Both are accepted, and both are refused without the record, naming the changed class.Results on macOS (arm64), after merging the base branch, which now includes
mainand vendors a jar without the upstream registry:patch::jar_manifest,patch::jar_members,patch::jvm_jar,vendor::maven_repo,vendor::jvm,vendor::verify,vendor::redownload,crawlers::maven): 597 pass.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --all -- --check: clean.cargo test -p socket-patch-core --tests(8,692 pass), the touched CLI suites (89 pass), the real-Maven vendored suite (6 pass) and the production legs (hosted, vendored and agent pass, Java 26 only).socket-patch-core --tests, the CLI suites,cargo check --all-targets, the real-Maven suites, the production legs, and anything on Linux or Windows.The vendored comparison is now with the jar in the build's local repository, where there is one, not with a jar downloaded from the registry; the manifest rule applies to that comparison unchanged.
For the owner
Generated by Claude Code