[Java.Interop.Tools.Maven] Assert resolved cache paths stay under CacheDirectory#1480
Open
jonathanpeppers wants to merge 1 commit into
Open
[Java.Interop.Tools.Maven] Assert resolved cache paths stay under CacheDirectory#1480jonathanpeppers wants to merge 1 commit into
jonathanpeppers wants to merge 1 commit into
Conversation
…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 <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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. |
simonrozsival
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a path-staying-under-CacheDirectory assertion to
CachedMavenRepository. Exposes a new public API,GetArtifactFilePath (Artifact, string), that returns the on-diskpath where an artifact + filename would be cached and throws
InvalidOperationExceptionif the resolved path would not beunder
CacheDirectory.TryGetFile,TryGetFilePath, andGetFilePathAsyncall route through this single method so thereis exactly one place that knows the cache layout.
The new public API lets callers (such as dotnet/android's
MavenExtensions.DownloadPayload) stop reconstructing the cachepath themselves with their own
Path.Combinelogic and get theassertion for free.
Defense-in-depth, hardening. Not security enforcement.