Skip to content

Scope server credentials and validate legacy relocation coordinates - #12977

Merged
gnodet merged 3 commits into
maven-4.0.xfrom
pr/legacy-compat-credential-scope-4.0.x
Sep 2, 2026
Merged

Scope server credentials and validate legacy relocation coordinates#12977
gnodet merged 3 commits into
maven-4.0.xfrom
pr/legacy-compat-credential-scope-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Forward-port of #12954 from maven-3.10.x to maven-4.0.x, adapting all three fixes for the 4.0.x module structure and API differences:

  • OriginBoundAuthenticationSelector (new file in impl/maven-core): scopes server credentials to the declared origins (protocol, host, port) of repositories and mirrors configured in settings, preventing credential leakage to unrelated repositories. Supports three modes via maven.repository.credentialScope: origin (default), strict, and id (legacy).
  • Relocation coordinate validation (compat/maven-compat MavenMetadataSource): validates relocation groupId, artifactId, and version components before applying them, rejecting path traversal characters (/, \, ..) and control characters.
  • Exact server ID matching (compat/maven-compat DefaultWagonManager): uses equals instead of equalsIgnoreCase for server ID matching, consistent with LegacyRepositorySystem.injectAuthentication and the resolver's authentication selector.

Adaptations for 4.0.x

  • Module paths: maven-compat/ -> compat/maven-compat/, maven-core/ -> impl/maven-core/
  • OriginBoundAuthenticationSelector uses org.slf4j.Logger (4.0.x) instead of org.codehaus.plexus.logging.Logger (3.10.x)
  • Credential scope property read from mergedProps (4.0.x property flow) instead of ConfigUtils.getString(configProps, ...) (3.10.x)
  • MavenMetadataSourceRelocationTest uses constructor injection (4.0.x) instead of reflection-based field injection (3.10.x)

Test plan

  • mvn verify -pl impl/maven-core -- 602 tests pass, 0 failures
  • mvn verify -pl compat/maven-compat -- 156 tests pass, 0 failures
  • New OriginBoundAuthenticationSelectorTest covers: declared origin matching, origin scoping, undeclared ID legacy behavior, strict mode refusal, ID scope passthrough, unknown scope rejection, origin normalization
  • New MavenMetadataSourceRelocationTest covers: invalid artifactId rejection, well-formed relocation application

🤖 Generated with Claude Code

@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 forward-port of #12954 from maven-3.10.x to maven-4.0.x. All adaptations are correctly applied:

  • Module paths: impl/maven-core/ and compat/maven-compat/ (4.0.x structure)
  • Logging: org.slf4j.Logger instead of Plexus Logger
  • Property flow: mergedProps.getOrDefault(...) instead of ConfigUtils.getString(configProps, ...)
  • Test injection: Constructor injection instead of reflection-based field injection

CI passes on all 24 checks (ubuntu, macos, windows; JDK 17, 21, 25). One minor style nit noted inline (carried over from the 3.10.x version).

Observations (informational):

  1. The MAVEN_REPOSITORY_CREDENTIAL_SCOPE constant is defined on DefaultRepositorySystemSessionFactory rather than in org.apache.maven.api.Constants where most other user-facing properties live. Could be moved in a follow-up for consistency.

🔀 Backport / Forward-port Status

Branch Status
maven-3.10.x #12954 (merged)
maven-4.0.x 🔄 This PR
maven-3.9.x ⚠️ Still has equalsIgnoreCase bug and lacks credential scoping + relocation validation
master ⚠️ Still has equalsIgnoreCase in compat/maven-compat/.../DefaultWagonManager.java and lacks credential scoping

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

ArtifactMetadataRetrievalException exception =
assertThrows(ArtifactMetadataRetrievalException.class, () -> source.retrieve(request));
assertEquals(true, exception.getMessage().contains("a/b"));
assertEquals(true, exception.getMessage().contains("artifactId"));

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.

Style nit (also noted in the 3.10.x review of #12954): assertEquals(true, ...) is less readable than assertTrue(...) for boolean assertions.

Suggested change
assertEquals(true, exception.getMessage().contains("artifactId"));
assertTrue(exception.getMessage().contains("a/b"));
assertTrue(exception.getMessage().contains("artifactId"));

Forward-port of PR #12954 from maven-3.10.x to maven-4.0.x:

- OriginBoundAuthenticationSelector: scopes server credentials to
  declared origins (protocol, host, port) of repositories and mirrors,
  preventing credential leakage to unrelated repositories
- MavenMetadataSource: validates relocation coordinate components
  (groupId, artifactId, version) before applying them, rejecting
  path traversal characters and control characters
- DefaultWagonManager: uses exact server ID matching (equals instead
  of equalsIgnoreCase) consistent with LegacyRepositorySystem and the
  resolver's authentication selector

Adapted for 4.0.x module structure (compat/maven-compat, impl/maven-core)
and API differences (SLF4J logger, constructor injection, merged properties).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet
gnodet force-pushed the pr/legacy-compat-credential-scope-4.0.x branch from de2b905 to 4b74bb4 Compare September 1, 2026 21:10
Remove unused import left by rebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The relocatedTarget method now declares ArtifactDescriptorException
(added by the relocation validation merge). The test must declare it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet
gnodet merged commit e7b6d36 into maven-4.0.x Sep 2, 2026
23 checks passed
@gnodet
gnodet deleted the pr/legacy-compat-credential-scope-4.0.x branch September 2, 2026 06:16
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.

1 participant