Skip to content

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

Open
gnodet wants to merge 3 commits into
apache:maven-3.10.xfrom
gnodet:pr/legacy-compat-3.10.x
Open

Honour configured policy and validate inputs on the legacy compat paths#12978
gnodet wants to merge 3 commits into
apache:maven-3.10.xfrom
gnodet:pr/legacy-compat-3.10.x

Conversation

@gnodet

@gnodet gnodet commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport of the path traversal and checksum policy fixes from #12945 (maven-4.0.x) to maven-3.10.x.

  • Path traversal validation on repository keys: AbstractRepositoryMetadata.getLocalFilename and LegacyLocalRepositoryManager.ArtifactMetadataAdapter.getLocalFilename now reject a repository key that is .., contains /, \, :, or an ISO control character before using it in a local file name.
  • Version token validation in metadata: DefaultRepositoryMetadataManager.readMetadata validates every version token carried by parsed repository metadata (latest, release, versions, snapshot versions, snapshot timestamp) for the same path traversal characters.
  • Checksum policy enforcement: DefaultRepositoryMetadataManager.resolve now catches ChecksumFailedException separately and fails metadata resolution under checksumPolicy=fail instead of downgrading to a warning. The update-check file is only touched on success, not-found, or generic transfer failure, so checksum failures are retried on the next build. getArtifactMetadataFromDeploymentRepository and LegacyRepositorySystem.retrieve resolve the effective policy from the repository configuration instead of hardcoding warn.

The proxy clone fix (DefaultSettingsDecrypter) is already present on maven-3.10.x and is therefore not included here.

Adapted for the 3.10.x module structure (no compat/ prefix) and API differences (MetadataXpp3Reader instead of MetadataStaxReader, no pattern matching instanceof).

Test plan

  • AbstractRepositoryMetadataTest (4 tests): repo keys with /, \, .., : are rejected; well-formed key produces correct filename
  • LegacyLocalRepositoryManagerTest (3 tests): repo keys with path separators and .. are rejected in the inner adapter
  • DefaultRepositoryMetadataManagerValidationTest (2 tests): metadata with invalid version token (colon) and invalid snapshot timestamp (colon) are rejected
  • DefaultRepositoryMetadataManagerTest (1 test): resolve() throws RepositoryMetadataResolutionException when checksum policy is fail and checksums do not match
  • LegacyRepositorySystemTest.testRetrieveHonorsConfiguredFailChecksumPolicy: retrieve() throws ArtifactTransferFailedException when checksum policy is fail
  • mvn verify -pl maven-core -B passes
  • mvn verify -pl maven-compat -B passes

🤖 Generated with Claude Code

gnodet and others added 3 commits August 31, 2026 22:38
AbstractRepositoryMetadata.getLocalFilename rejects a repository key that is
the ".." token, contains '/', '\', ':', or an ISO control character, before
using it in a local file name. LegacyLocalRepositoryManager.ArtifactMetadataAdapter
applies the same validation.

Backport of the corresponding fix from PR apache#12945 (maven-4.0.x).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DefaultRepositoryMetadataManager.readMetadata applies validateVersioning to
reject metadata carrying version tokens (latest, release, versions, snapshot
versions, snapshot timestamp) that contain '..', '/', '\', ':', or ISO control
characters.

DefaultRepositoryMetadataManager.resolve now catches ChecksumFailedException
ahead of the generic TransferFailedException handler. Under checksumPolicy=fail
a checksum mismatch fails metadata resolution instead of only logging a warning.
The update-check file is only touched on success, not-found, or a generic
transfer failure, so a checksum failure is retried on the next build.

Backport of the corresponding fixes from PR apache#12945 (maven-4.0.x).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Backport of the corresponding fix from PR apache#12945 (maven-4.0.x).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clean, faithful backport of the approved #12945 security hardening to maven-3.10.x. All adaptations for the 3.10.x module layout and API surface are correct; no logic drift from the source PR.

Adaptations verified:

  • Module paths correctly split between maven-core/ (AbstractRepositoryMetadata, LegacyLocalRepositoryManager) and maven-compat/ (DefaultRepositoryMetadataManager, LegacyRepositorySystem)
  • Java language level adapted: traditional instanceof + cast instead of 4.0.x pattern matching
  • Reader API adapted: ValidatingMetadataXpp3Reader (XPP3-based) instead of 4.0.x MetadataStaxReader (StAX-based)
  • Proxy clone-before-decrypt correctly omitted: confirmed DefaultSettingsDecrypter on 3.10.x already has server.clone() and proxy.clone()
  • ChecksumFailedException extends TransferFailedException catch ordering correct
  • updateCheckManager.touch() relocation from finally to individual paths identical to 4.0.x logic
  • checksumRank() ranking (fail=2, warn=1, ignore=0) identical to 4.0.x

Observation (non-blocking):

  • [low] isInvalidPathToken helper duplicated between AbstractRepositoryMetadata and LegacyLocalRepositoryManager.ArtifactMetadataAdapter — same as 4.0.x, acceptable for backport.

📋 PR Metadata

Aspect Current Suggested
Labels (none) bug
Milestone (none) 3.10.0

🔀 Backport Status

✅ All branches covered:


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

Claude Code on behalf of Guillaume Nodet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant