Skip to content

Honour configured policy and validate inputs on the legacy compat paths - #12945

Open
slachiewicz wants to merge 5 commits into
apache:maven-4.0.xfrom
slachiewicz:pr/legacy-compat-4.0.x
Open

Honour configured policy and validate inputs on the legacy compat paths#12945
slachiewicz wants to merge 5 commits into
apache:maven-4.0.xfrom
slachiewicz:pr/legacy-compat-4.0.x

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 30, 2026

Copy link
Copy Markdown
Member

Fixes on the legacy compatibility paths.

  • Checksum policy. Three legacy metadata paths ignored the configured checksum policy and defaulted to a warning regardless of a fail setting; the configured policy is now threaded through and honoured.
  • Repository key and metadata tokens. The repository key is validated before it becomes part of a local file name, and version tokens from downloaded metadata are validated at the single point all metadata passes through, which also covers the latest/release/snapshot transformations.
  • Proxy decryption. DefaultSettingsDecrypter now clones each proxy before setting its decrypted password, mirroring the existing behaviour for servers, so decryption no longer mutates the caller's settings objects. Maven 3 already clones here.

Each change is a separate commit.


Draft while related code paths are reviewed — the same guard may be needed in sibling implementations of these interfaces, and I would rather establish that before asking for review time.

DefaultRepositoryMetadataManager.resolve() caught ChecksumFailedException
through the generic TransferFailedException handler, so a checksum mismatch
under checksumPolicy=fail only logged a warning and kept the previously
cached metadata, and the finally block touched the update-check file
regardless, deferring the next check for a full update interval. Catch
ChecksumFailedException ahead of the generic handler and fail resolution
instead, and only touch the update-check file on success, not-found, or a
generic transfer failure, so a checksum failure is retried on the next
build rather than cached.
…ches

DefaultRepositoryMetadataManager.getArtifactMetadataFromDeploymentRepository
and LegacyRepositorySystem.retrieve hardcoded checksumPolicy=warn for every
transfer, so a repository configured with checksumPolicy=fail (or the
global -C/--strict-checksums flag) was not honored on the deploy-metadata
fetch or on generic retrieve() calls. Resolve the effective policy from the
repository instead: the metadata fetch uses the same per-metadata policy
resolution the download path already uses, and retrieve() takes the
stricter of the repository's release and snapshot policies since a generic
path cannot be classified as either.
AbstractRepositoryMetadata.getLocalFilename rejects a repository key that is
the ".." token, contains '/', '\', ':', or an ISO control character, before
using it in a local file name. DefaultRepositoryMetadataManager.readMetadata
applies the same check to every version token carried by parsed repository
metadata (latest, release, versions, snapshot versions, snapshot timestamp)
before the metadata is merged and used to resolve a version.

Matches the check already used for relocation and version-range coordinates
elsewhere in the resolver.
The proxy loop in DefaultSettingsDecrypter.decrypt mutated the
caller's live Proxy objects directly, unlike the server loop just
above it which already clones before mutating. Since compat model
objects propagate setter changes up into their parent Settings
delegate, this meant a decrypted proxy password could end up written
back into the session-wide Settings object. Clone the proxy first,
mirroring the server handling, so decryption only ever touches the
copies returned in the result.
@slachiewicz slachiewicz added the bug Something isn't working label Aug 30, 2026
@slachiewicz slachiewicz added this to the 4.0.0-rc-7 milestone Aug 30, 2026
@slachiewicz
slachiewicz marked this pull request as draft August 30, 2026 19:05
@slachiewicz
slachiewicz marked this pull request as ready for review August 30, 2026 21:49

@gnodet gnodet left a comment

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.

Well-crafted security-hardening PR that correctly threads configured checksum policies through three legacy metadata paths, adds input validation for repository keys and metadata version tokens, and fixes a proxy-cloning inconsistency.

Highlights:

  • The checksum policy fix is well-reasoned: resolve() properly fails on ChecksumFailedException under the strict policy, getArtifactMetadataFromDeploymentRepository now uses the configured policy, and LegacyRepositorySystem.retrieve() takes the stricter of release/snapshot policies.
  • The catch ordering (ChecksumFailedException before TransferFailedException) is essential and correctly placed.
  • The proxy cloning fix in DefaultSettingsDecrypter correctly mirrors the existing server-cloning pattern.
  • validateVersioning provides comprehensive validation at the single metadata read entry point.
  • Test coverage is thorough across all changes.
  • Clean commit structure with descriptive messages.

Minor observations (non-blocking):

  • isInvalidPathToken / validateRepositoryKey are duplicated in LegacyLocalRepositoryManager and AbstractRepositoryMetadata — acceptable for deprecated compat code.
  • getArtifactMetadataFromDeploymentRepository still touches the update tracker in finally (even on checksum failures), unlike resolve() which deliberately skips it — minor inconsistency on the deployment path.

Consistent with the already-approved 3.10.x variant (#12954), well-adapted for the Maven 4 compat model.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit to slachiewicz/maven that referenced this pull request Aug 31, 2026
The legacy metadata manager and repository system hardcoded
CHECKSUM_POLICY_WARN, silently ignoring the operator's
--strict-checksums / -C flag and per-repository checksumPolicy
settings. This brings the master branch in line with the
maven-4.0.x fix (PR apache#12945):

- Catch ChecksumFailedException in resolve() and propagate it as a
  RepositoryMetadataResolutionException under CHECKSUM_POLICY_FAIL
- Move updateCheckManager.touch() out of the finally block so that
  failed transfers do not suppress retries for a full update interval
- Use the repository's configured checksum policy for deployment
  metadata retrieval instead of hardcoded WARN
- Pick the stricter of release/snapshot policies in
  LegacyRepositorySystem.retrieve() instead of hardcoded WARN

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants