Validate coordinates and repository precedence during artifact resolution - #12944
Validate coordinates and repository precedence during artifact resolution#12944slachiewicz wants to merge 5 commits into
Conversation
Repositories declared by a resolved model no longer replace a same-id repository supplied by the request or session; the ids supplied at resolver construction keep their precedence on the replace pass. A repository the model itself declared is still refreshed in place, e.g. once its URL has been interpolated.
Relocation groupId/artifactId/version taken from a resolved model are checked against the artifact-coordinate character set before a RelocatedArtifact is built; invalid components fail the descriptor read instead of entering resolution.
Version and snapshot tokens adopted from downloaded repository metadata are checked before they are spliced into a resolved coordinate, in the version resolver and version range resolver (both the native resolver stack and the maven-compat resolver-provider path), and in relocation coordinates read from a resolved project's distribution management. Metadata carrying a token that is not a valid coordinate component is treated as invalid, so resolution falls back to the requested base version and other repositories still resolve normally.
Follow-up to the previous commit: the rejection message now names which field (latest version, release version, snapshot version, snapshot timestamp) carried the invalid token, in both the native resolver stack and the maven-compat resolver-provider path, matching the message shape used elsewhere for this class of check.
e404686 to
59bd9f7
Compare
gnodet
left a comment
There was a problem hiding this comment.
Well-structured security-hardening PR that correctly validates artifact coordinates and repository precedence during resolution. The validations are applied consistently across both compat and impl layers, and the test coverage is thorough — all CI checks pass.
Minor suggestions (non-blocking):
MavenMetadataSourceRelocationTest(line 198–199):assertEquals(true, expression)could be replaced withassertTrue(expression)for more idiomatic JUnit 5 style and clearer failure messages.- The
isInvalidCoordinateComponent/validateVersionTokenlogic is duplicated across several files. While defensible for a security fix (self-contained validation), a shared utility could reduce maintenance burden in the future. - The
ProjectModelResolver.addRepositoryprecedence gap (noted in the PR description) is a sensible follow-up item.
Overall this is solid work — the validation rules (reject .., /, \, :, ISO control chars) cover the key attack vectors well, and the metadata-rejection strategy (reject entire document on any invalid token) is the right call.
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
|
Related work in The overlap is deliberate for now. This PR checks in Maven because the pinned resolver does not, and a Maven line only picks up the resolver-side change when its Worth a reviewer decision on whether the check should stay in both places once that pin lands, or move down to the resolver. This comment was created with AI assistance. |
Coordinates and repository lists arriving from a resolved artifact descriptor are validated before use.
groupId/artifactId/versionare checked against the artifact-coordinate character set before aRelocatedArtifactis built; malformed components fail the descriptor read rather than entering resolution. A follow-up commit covers the remaining rejected character classes.maven-metadata.xmlare validated before being spliced into a resolved version, so malformed metadata fails the read rather than producing a malformed coordinate. The rejection message names the field.Each change is a separate commit.
Draft while related code paths are reviewed — the same validation may be needed in sibling implementations of these interfaces, and I would rather establish that before asking for review time.
A
systemPathchange was removed from this PR: it brokeMavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest, which covers deliberate MNG-4379 behaviour — a dependency resolved from a repository declaring its ownsystem-scope dependency with the path interpolated from an environment variable.