Skip to content

Validate the repository key used as a local repository path segment - #2089

Merged
cstamas merged 1 commit into
apache:masterfrom
slachiewicz:repository-id-path-segment
Aug 31, 2026
Merged

cstamas merged 1 commit into
apache:masterfrom
slachiewicz:repository-id-path-segment

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

When the local repository is split, the repository key is spliced directly into the local repository
path prefix by LocalPathPrefixComposerFactorySupport, and into the file name used by
SparseDirectoryTrustedChecksumsSource. The key comes from a configurable
RepositoryKeyFunction, so its shape is not guaranteed to be a usable single path segment.

This validates the key with the existing PathUtils.validatePathComponent before using it, so the
prefix composes a valid relative path.

No public API changes.

stringToPathSegment maps '.' and '..' to explicit tokens (-DOT-,
-DOTDOT-), matching the existing single-character replacements, so
repository keys spliced into split local repository prefixes and
origin-aware trusted checksums paths are always inert path segments.

Add a defensive path-component validation of the repository key at the
split prefix composer and the sparse-directory trusted checksums source.
@slachiewicz slachiewicz changed the title Neutralize dot-only repository ids in path segment conversion Validate the repository key used as a local repository path segment Aug 30, 2026
@slachiewicz slachiewicz added maintenance java Pull requests that update Java code labels Aug 30, 2026
@slachiewicz slachiewicz added this to the 2.0.23 milestone Aug 30, 2026
@slachiewicz
slachiewicz requested review from cstamas and gnodet August 30, 2026 23:42

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well-targeted security hardening that closes a real gap in stringToPathSegment (the . and .. cases pass through unchanged since they contain none of the characters in the replacement map) and adds defense-in-depth validation at the two critical call sites where repository keys are used as standalone directory segments.

The layered approach is sound: stringToPathSegment sanitizes at the source (inside RepositoryIdHelper.idToPathSegment), and validatePathComponent acts as a safety net at the point of use.

Minor observations (not blocking):

  • SummaryFileTrustedChecksumsSource.summaryFile() also uses the repository key in filename construction — could benefit from the same validation in a follow-up (pre-existing, not introduced by this PR).
  • Backward compatibility risk is negligible: only affects repository IDs that are exactly . or ...

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

@cstamas
cstamas merged commit f677489 into apache:master Aug 31, 2026
39 of 40 checks passed
@slachiewicz
slachiewicz deleted the repository-id-path-segment branch August 31, 2026 10:24
cstamas pushed a commit that referenced this pull request Aug 31, 2026
Follow-up to the review notes on #2089 and #2091: `SummaryFileTrustedChecksumsSource` splices the repository key into the summary file name without the point-of-use validation the sparse source received, so this adds the same `PathUtils.validatePathComponent` guard. The built-in key functions already sanitize; the guard matters for custom `RepositoryKeyFunction` implementations, and the new test wires a non-sanitizing key function to exercise it. Also adds the `GAECVNameMapperTest` that was noted as missing.
cstamas pushed a commit that referenced this pull request Aug 31, 2026
The 1.9.x line predates the repository key function layer, so the split local repository prefix (`LocalPathPrefixComposerFactorySupport`, four sites) and the trusted checksums sources (`SummaryFileTrustedChecksumsSource`, `SparseDirectoryTrustedChecksumsSource`) splice the raw repository id into paths. This routes those ids through `PathUtils.stringToPathSegment` and validates the result, matching the 2.x behaviour after #2089 and #2099. Also ports `GAECVNameMapperTest` from master; `GAECVNameMapper` itself needed no change since it inherits the earlier `fieldToSegment` handling from `GAVNameMapper`.

Repository ids that are exactly `.`/`..` or contain path separators now compose to a neutralized segment (e.g. `-DOTDOT-`) instead of being spliced verbatim; well-formed ids are unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants