Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

[release/10.0.1xx] Backport Maven hardening - #1495

Closed
jonathanpeppers wants to merge 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-maven-hardening
Closed

jonathanpeppers wants to merge 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-maven-hardening

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Backports the complete Java.Interop.Tools.Maven hardening set from main onto the Java.Interop commit currently pinned by dotnet/android's release/10.0.1xx branch (33992194b9373e9322244612c94ed9941b9bc2fd):

The two consecutive main changes are combined into exactly one backport commit. No other Maven implementation, test, or documentation changes exist between the release baseline and main.

Validation:

  • dotnet test tests\Java.Interop.Tools.Maven-Tests\Java.Interop.Tools.Maven-Tests.csproj --configuration Release
  • 106 passed, 0 failed

Backport cache path containment from #1480 and Maven artifact coordinate validation from #1479, including their targeted tests.

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings August 20, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Backports hardening for Java.Interop.Tools.Maven onto release/10.0.1xx, tightening Maven coordinate validation (Artifact) and ensuring cached artifact paths cannot resolve outside the configured cache directory (CachedMavenRepository). This aligns downstream consumers (e.g., dotnet/android) with the hardened behaviors from main.

Changes:

  • Add stricter validation for Maven artifact coordinates in Artifact (reject malformed group/artifact/version inputs; keep ctor allowance for empty version).
  • Centralize cache-path computation in CachedMavenRepository.GetArtifactFilePath() and assert resolved paths remain under CacheDirectory.
  • Add/extend unit tests for both coordinate validation and cache path hardening.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/Java.Interop.Tools.Maven-Tests/CachedMavenRepositoryTests.cs Adds coverage for cache-path resolution, including escaping/relative-path scenarios.
tests/Java.Interop.Tools.Maven-Tests/ArtifactTests.cs Adds coverage for valid/invalid Maven coordinates and ctor behavior (incl. empty-version allowance).
src/Java.Interop.Tools.Maven/Repositories/CachedMavenRepository.cs Introduces GetArtifactFilePath() and routes caching through it with a cache-directory containment assertion.
src/Java.Interop.Tools.Maven/Models/Artifact.cs Implements stricter coordinate/version validation and updates TryParse behavior/signature.
Suppressed comments (2)

src/Java.Interop.Tools.Maven/Models/Artifact.cs:94

  • IsValidVersion also permits "."/"..". Since version is used as a directory name in the cache layout, a value of ".." will traverse upward when combined and normalized (even without any path separators present in the string). Consider rejecting these special segments to keep cache layout deterministic and avoid collisions.
	static bool IsValidVersion (string value)
	{
		if (string.IsNullOrWhiteSpace (value))
			return false;
		foreach (var c in value) {

tests/Java.Interop.Tools.Maven-Tests/ArtifactTests.cs:111

  • Similarly, the constructor-invalid coverage should include "."/".." for groupId/artifactId/version so the cache-path traversal edge case stays blocked for direct ctor calls too.
	[TestCase ("com.example", "lib", "1.0/../")]
	[TestCase ("com.example", "lib", "..\\1.0")]
	[TestCase ("com/example", "lib", "1.0")]
	public void Ctor_Invalid_Throws (string groupId, string artifactId, string version)

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +73 to +77
static bool IsValidCoordinate (string value)
{
if (string.IsNullOrWhiteSpace (value))
return false;
foreach (var c in value) {
Comment on lines +52 to +55
[TestCase ("a/../b:c:1")]
[TestCase ("..\\a:b:1")]
[TestCase ("a:b:..\\1.0")]
public void TryParse_Invalid (string value)
}

public static bool TryParse (string value, [NotNullWhen (true)]out Artifact? artifact)
public static bool TryParse (string? value, [NotNullWhen (true)]out Artifact? artifact)
@jonathanpeppers

Copy link
Copy Markdown
Member Author

Superseded by #1498, which contains the complete release-applicable hardening and approved-feed routing as one commit on the pinned release baseline.

jonathanpeppers added a commit that referenced this pull request Aug 21, 2026
…1498)

Supersedes #1495 with the complete release-applicable Maven backport as exactly one commit on top of the Java.Interop commit pinned by dotnet/android `release/10.0.1xx` (`33992194b9373e9322244612c94ed9941b9bc2fd`).

Backports:

- #1480: assert resolved Maven cache paths remain under `CacheDirectory`
- #1479: validate Maven artifact coordinates
- Route Maven integration-test resolvers through `dotnet-public-maven`
- Remove java-source-utils' project-local `mavenCentral()` and use Android's shared approved repository settings when embedded, with an equivalent standalone Java.Interop fallback
- Coupled Maven hardening tests

The Kotlin Gradle fixture from Android main is intentionally excluded because it does not exist at this release pin.

Validation:

- Java.Interop.Tools.Maven tests: 106 passed, 0 failed
- java-source-utils assembly: succeeded
- java-source-utils standalone CI-mode settings evaluation: succeeded
- Fresh-cache java-source-utils `compileJava`: succeeded entirely through `dotnet-public-maven`
- java-source-utils legacy suite: 16 passed before two existing missing-resource NPEs (`JavaType.java`) unrelated to repository routing

Feed prerequisite: the release JavaParser `3.18.0` dependency graph must be mirrored into `dotnet-public-maven` for anonymous CI resolution. The complete graph has been seeded and fresh-cache resolution is confirmed.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants