Skip to content

[MNG] Warn or fail when an external-model profile repository shadows central #13146

Closed as not planned

Description

@gnodet

Problem

When a dependency POM contributes a repository through a JDK/OS/activeByDefault-activated profile (the legitimate path, see #13100 / #13116 / #13141), that repository can declare a URL that shadows central or another well-known repository with a different (potentially malicious) URL.

Maven currently has no defense against this: the repository is accepted as-is and used for artifact resolution.

Proposed Solution

Implement a WARN (or optionally FAIL with a flag) policy that triggers when:

  • A repository contributed by an external-model profile has the same <id> as a repository already registered in the effective repository list (e.g. central), but a different URL.

This is a repository URL-mismatch check, scoped to the dependency resolution path.

Non-goals

Notes

Activity

  1. added
    enhancement
    on Sep 15, 2026
  2. added 5 commits that reference this issue on Sep 15, 2026
  3. arturobernalg commented on Oct 10, 2026

    @arturobernalg
    Member

    I looked into this on current master and found that the behavior depends on the repository merge mode.

    With an external dependency POM whose active profile declares central with a different URL:

    • REQUEST_DOMINANT (used by DefaultArtifactDescriptorReader): the existing central repository wins and the conflicting external repository is dropped. A repository with a unique id is still accepted.
    • POM_DOMINANT: the external central declaration replaces the existing one.

    So the normal artifact descriptor resolution path already prevents the shadowing described here, but does so silently.

    Adding a generic same-id/different-url warning also looks problematic because many existing POMs redeclare central using legacy URLs, which could generate a large number of warnings.

    For the remaining POM_DOMINANT case, making external models recessive would change the existing precedence semantics.

    Would you prefer this issue to:

    1. add a warning for conflicts that are already discarded in the REQUEST_DOMINANT path, or
    2. change the POM_DOMINANT semantics so external models cannot override an existing repository id?
  4. gnodet commented on Oct 20, 2026

    @gnodet
    ContributorAuthor

    After analysis, the current REQUEST_DOMINANT merge mode (used by DefaultArtifactDescriptorReader for all dependency resolution) already fully mitigates this concern:

    1. Same-id shadowing is blocked: when a dependency POM declares a repository with an id that already exists in the request (e.g. central from the super POM), the dependency's declaration is silently dropped. The existing URL is preserved.

    2. The scope is limited: each dependency is resolved in its own derived ModelBuilderSessionState. Repository changes during dependency resolution don't propagate back to the parent state — they are subtree-scoped.

    3. A warning would not be actionable:

      • If the user has already redeclared the repository in their POM (the natural "fix"), it's already overridden — no warning needed.
      • If the user has not redeclared it, the dependency's repository (with a new id) is legitimately needed for resolving that dependency's transitive dependencies — no warning needed either.
      • For central specifically, it's always present from the super POM, so the shadow is always blocked without any user action.

    The POM_DOMINANT case (raised in the earlier comment) only applies to the project's own parent chain during project building, where overriding central is expected behavior (since central comes from the super POM's defaults).

    Closing as already mitigated.

    Claude Code on behalf of Guillaume Nodet

  5. added a commit that references this issue on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions