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

[Java.Interop.Tools.Maven] Assert resolved cache paths stay under CacheDirectory - #1480

Merged
jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-harden-cache-path
Jun 23, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-harden-cache-path

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Adds a path-staying-under-CacheDirectory assertion to
CachedMavenRepository. Exposes a new public API,
GetArtifactFilePath (Artifact, string), that returns the on-disk
path where an artifact + filename would be cached and throws
InvalidOperationException if the resolved path would not be
under CacheDirectory. TryGetFile, TryGetFilePath, and
GetFilePathAsync all route through this single method so there
is exactly one place that knows the cache layout.

The new public API lets callers (such as dotnet/android's
MavenExtensions.DownloadPayload) stop reconstructing the cache
path themselves with their own Path.Combine logic and get the
assertion for free.

Not security enforcement.

…heDirectory

Adds a path-staying-under-CacheDirectory assertion to
`CachedMavenRepository`. Exposes a new public API,
`GetArtifactFilePath (Artifact, string)`, that returns the on-disk
path where an artifact + filename would be cached and throws
`InvalidOperationException` if the resolved path would not be
under `CacheDirectory`. `TryGetFile`, `TryGetFilePath`, and
`GetFilePathAsync` all route through this single method so there
is exactly one place that knows the cache layout.

The new public API lets callers (such as dotnet/android's
`MavenExtensions.DownloadPayload`) stop reconstructing the cache
path themselves with their own `Path.Combine` logic and get the
assertion for free.

Defense-in-depth, hardening. Not security enforcement.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 22, 2026 17:50

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

This PR hardens Java.Interop.Tools.Maven’s caching layer by centralizing cache path resolution in CachedMavenRepository.GetArtifactFilePath (Artifact, string) and asserting that resolved artifact paths remain under CacheDirectory (throwing InvalidOperationException on escape attempts). This supports defense-in-depth and helps external callers avoid re-implementing cache layout logic.

Changes:

  • Added CachedMavenRepository.GetArtifactFilePath (Artifact, string) and routed existing file/path retrieval APIs through it.
  • Added guard logic to detect resolved cache paths escaping CacheDirectory.
  • Added a new NUnit test suite validating expected cache layout and escape-path failure behavior across multiple entry points.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/Java.Interop.Tools.Maven-Tests/CachedMavenRepositoryTests.cs New tests covering cache layout and escape-path exceptions (including ensuring inner repo isn’t consulted on invalid paths).
src/Java.Interop.Tools.Maven/Repositories/CachedMavenRepository.cs Introduces centralized cache path resolver with “must stay under CacheDirectory” assertion; updates existing APIs to use it.

Comment thread src/Java.Interop.Tools.Maven/Repositories/CachedMavenRepository.cs
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, thanks! label Jun 22, 2026
@jonathanpeppers
jonathanpeppers merged commit fa9ccfb into main Jun 23, 2026
3 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-harden-cache-path branch June 23, 2026 14:14
@GrabYourPitchforks

Copy link
Copy Markdown
Member

Oh no, I'm going to be one of those "well, actually!" people...

This does not qualify as a defense-in-depth change, as it is not attempting to provide any type of protection against a trusted operator being abused into performing a malicious action. It is strictly a correctness "not security enforcement" change, per Jonathan's upthread comment. (Any attack vector here assumes a hostile operator, which defense-in-depth changes cannot meaningfully counter.)

I'm just entering this into the record so that people don't misread the intent and don't go through the security reporting channels if there's a bug here.

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

ready-to-review This PR is ready to review/merge, thanks!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants