Scope server credentials and validate legacy relocation coordinates - #12976
Scope server credentials and validate legacy relocation coordinates#12976gnodet wants to merge 1 commit into
Conversation
Forward-port of #12954 (maven-3.10.x) to master, adapted for the 4.x module layout (compat/ and impl/ prefixes) and API changes (SLF4J logging, constructor injection, api.Constants). Three fixes: 1. OriginBoundAuthenticationSelector — scopes server credentials to the origins (protocol+host+port) declared for the same server id in settings mirrors/repositories, preventing credential leakage to repositories that merely share a server id. Controlled by the new maven.repository.credentialScope user property (origin | strict | id). 2. Relocation coordinate validation in MavenMetadataSource — rejects relocation groupId / artifactId / version values that contain path-traversal characters (/, \, ..) or control characters before they are applied to the artifact being resolved. 3. Exact server ID matching in DefaultWagonManager — replaces equalsIgnoreCase with equals for consistency with LegacyRepositorySystem.injectAuthentication and the resolver's authentication selector. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet
left a comment
There was a problem hiding this comment.
Clean and correct forward-port of the approved #12954 security-hardening fixes to master. All five adaptations for the 4.x module layout are properly done.
Adaptations verified:
- Module paths correctly use
compat/andimpl/prefixes OriginBoundAuthenticationSelectoruses SLF4J logging instead of Plexus logging- Relocation test uses constructor injection (matching
@Injecton master) instead of 3.10.x reflection-based field setting - Credential scope property read via
mergedProps.getOrDefault()(consistent with other user properties on master) - Session builder variable naming follows master conventions
- All three fixes present: credential scoping, relocation validation, server ID matching
Observation (non-blocking):
requireValidCoordinateComponent / isInvalidCoordinateComponent validation is only applied to legacy MavenMetadataSource in compat/maven-compat. The new resolver-based DistributionManagementArtifactRelocationSource (in both impl/maven-impl and compat/maven-resolver-provider) passes relocation coordinates to RelocatedArtifact without equivalent path-traversal/control-character validation. This is not introduced by this PR, but since the impl path is the primary relocation code path in 4.x non-compat mode, consider hardening it in a follow-up (ideally in RelocatedArtifact's constructor so all relocation sources benefit).
📋 PR Metadata
| Aspect | Current | Suggested |
|---|---|---|
| Labels | (none) | bug |
| Milestone | (none) | 4.1.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
Summary
Forward-port of #12954 (
maven-3.10.x) tomaster, adapted for the 4.x module layout (compat/andimpl/prefixes) and API changes (SLF4J logging, constructor injection).Three fixes:
OriginBoundAuthenticationSelector— scopes server credentials to the origins (protocol+host+port) declared for the same server id in settings mirrors/repositories, preventing credential leakage to repositories that merely share a server id. Controlled by the newmaven.repository.credentialScopeuser property (origin|strict|id).Relocation coordinate validation in
MavenMetadataSource— rejects relocationgroupId/artifactId/versionvalues that contain path-traversal characters (/,\,..) or control characters before they are applied to the artifact being resolved.Exact server ID matching in
DefaultWagonManager— replacesequalsIgnoreCasewithequalsfor consistency withLegacyRepositorySystem.injectAuthenticationand the resolver's authentication selector.Adapted paths
maven-compat/src/…/DefaultWagonManager.javacompat/maven-compat/src/…/DefaultWagonManager.javamaven-core/src/…/DefaultRepositorySystemSessionFactory.javaimpl/maven-core/src/…/DefaultRepositorySystemSessionFactory.javamaven-core/src/…/OriginBoundAuthenticationSelector.javaimpl/maven-core/src/…/OriginBoundAuthenticationSelector.javamaven-core/src/…/MavenMetadataSource.javacompat/maven-compat/src/…/MavenMetadataSource.javaAPI adaptations for master
org.slf4j.Loggerinstead oforg.codehaus.plexus.logging.LoggermergedProps.getOrDefault()instead ofConfigUtils.getString()(not available on master)MavenMetadataSourceconstructor)@since 4.0.0on the new constant (instead of3.10.0)Test plan
OriginBoundAuthenticationSelectorTest— 7 tests covering origin/strict/id scopes, origin normalization, and unknown scope rejectionMavenMetadataSourceRelocationTest— 2 tests verifying invalid relocations are rejected and well-formed relocations are appliedmvn verify -pl impl/maven-core— 642 tests passmvn verify -pl compat/maven-compat— 162 tests pass🤖 Generated with Claude Code