Skip to content

Compose named lock keys one segment per coordinate field - #2091

Merged
cstamas merged 2 commits into
apache:masterfrom
slachiewicz:named-lock-path-segments
Aug 31, 2026
Merged

cstamas merged 2 commits into
apache:masterfrom
slachiewicz:named-lock-path-segments

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

The named lock mappers build a lock name by concatenating artifact coordinate fields. The fields are
inserted as-is, so a field containing a separator produces a name with more segments than intended.
BasedirNameMapper then resolves that name against the locks base directory, and the file lock
factory creates and deletes a lock file at the resolved path.

Two changes:

  • GAVNameMapper and GAECVNameMapper compose each coordinate field through fieldToSegment, so a
    field always contributes exactly one segment.
  • BasedirNameMapper resolves the delegate-provided name against the base directory and requires the
    result to stay under it, since that is where lock files are created and removed.

Marked @since 2.0.23. No public API changes.

The filesystem-friendly GAV/GAECV name mappers now pass every
coordinate field through PathUtils.stringToPathSegment, and
BasedirNameMapper rejects lock names that do not resolve under the
locks base directory, so the resolved lock path is always contained in
it.
@slachiewicz slachiewicz added bug Something isn't working java Pull requests that update Java code labels Aug 30, 2026
@slachiewicz slachiewicz changed the title Sanitize lock names derived from artifact coordinates Compose named lock keys one segment per coordinate field Aug 30, 2026
@slachiewicz slachiewicz added this to the 2.0.23 milestone Aug 30, 2026
2.0.22 has already been released without these methods.
@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-crafted security hardening with a sound two-layer defense:

  1. fieldToSegment sanitization — PathUtils.stringToPathSegment replaces all illegal path characters, preventing coordinate fields from introducing path separators that could escape the locks directory.
  2. BasedirNameMapper.resolveContained containment check — standard normalize()+startsWith() pattern, correctly marked private static to prevent subclass override. Provides defense-in-depth against any delegate that emits traversal sequences.

The HashingNameMapper path is inherently safe since it hashes the entire name into a fixed hex string before resolution, eliminating attacker-controlled content.

Minor observations (not blocking):

  • Lock names will change for coordinates that previously contained path separator characters (rare/malicious) — worth a release notes mention.
  • No GAECVNameMapperTest exists, though the mechanism is inherited from GAVNameMapper and tested there.

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 ed01f7d into apache:master Aug 31, 2026
20 checks passed
@slachiewicz
slachiewicz deleted the named-lock-path-segments 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants