Skip to content

fix: accept locally cached artifacts via same-id fallback when tracking URL changes - #2133

Merged
cstamas merged 4 commits into
apache:masterfrom
gnodet:fix/legacy-tracking-key-fallback
Sep 8, 2026
Merged

cstamas merged 4 commits into
apache:masterfrom
gnodet:fix/legacy-tracking-key-fallback

Conversation

@gnodet

@gnodet gnodet commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

When the tracking key function is URL-qualified (nid_hurl, the default since 2.0.23 / commit 339161b), tracked artifacts become unavailable in two situations:

  1. Legacy entries: tracking file written by an older resolver using ID-only keys (nid format, e.g. artifact>central=).
  2. URL mismatch: artifact downloaded from a repo with the same ID but a different URL (e.g. real Central tracked as central-<sha1(realUrl)>= vs ITs overriding central to file:target/null which produces a different sha1).

In both cases the artifact IS present and WAS downloaded from a repository with the same logical identity (same repo ID). The resolver currently forces a full re-download, which fails in CI environments and integration tests that use fake/file-based repository URLs — see apache/maven#13078 (comment).

All 9 IT jobs fail (4229 failures) because ITs override central to file:target/null to prevent remote access, but nid_hurl treats sha1(file:target/null)sha1(https://repo.maven.apache.org/maven2) as a different repository.

Fix

Add a two-stage fallback in applyTracking():

  • Stage 1: try the system-wide key function (nid, ID-only) — catches legacy tracking entries from older resolvers.
  • Stage 2: prefix-based match on repoId- — catches same-id entries written with a different URL hash (the IT scenario where central is redirected to file:target/null).

The entry will be upgraded to the current key format on the next download.

Note: This effectively makes nid_hurl a recording-only mechanism: tracking entries are written with URL-qualified keys, but lookups fall back to repo-ID-only matching. The f013 security protection (rejecting same-id-different-URL repositories) is relaxed in favor of backward compatibility and the widely-used IT pattern of overriding repository URLs. A stricter model would require all downstream consumers (including hundreds of ITs) to stop relying on URL-stable repository identities.

Tests

  • Updated testUrlQualifiedTrackingDistinguishesSameIdDifferentUrltestUrlQualifiedTrackingSameIdDifferentUrlAcceptedViaFallback: same-id-different-URL now accepted
  • testUrlQualifiedTrackingAcceptsLegacyIdOnlyEntriesViaFallback: legacy nid entries accepted via stage 1
  • testUrlQualifiedTrackingRejectsLegacyIdOnlyEntriesFromDifferentRepo: different repo ID still rejected
  • testUrlQualifiedTrackingAcceptsSameIdDifferentUrlEntries: IT scenario (Central → file:target/null) verified
  • Updated factory tests to reflect relaxed behavior

…allback

When the tracking key function is URL-qualified (nid_hurl, the default
since 2.0.23), tracking entries written by an older resolver using
ID-only keys (nid format, e.g. 'artifact>central=') are invisible to
the new lookup which expects 'artifact>central-<sha1>='.

This causes all artifacts cached in the local repository before the
upgrade to appear as 'present but unavailable', triggering full
re-downloads from remote repositories. In CI environments and
integration tests that use fake/file-based repositories, this breaks
resolution entirely.

Add a backward-compatible fallback in applyTracking(): when the
URL-qualified lookup misses, try the system-wide key function (which
defaults to nid) as a fallback. If that matches, accept the artifact
and log a debug message. The legacy entry will be upgraded to the new
key format on the next download.

This preserves the f013 security improvement (URL-qualified tracking
prevents same-id-different-URL repository poisoning) while providing a
smooth upgrade path from older resolvers.
@cstamas
cstamas merged commit 18753da into apache:master Sep 8, 2026
1 check passed
@gnodet gnodet changed the title fix: accept legacy ID-only tracking entries via backward-compatible fallback fix: accept locally cached artifacts via same-id fallback when tracking URL changes Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

@cstamas Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 2.0.23 milestone Sep 8, 2026
@cstamas cstamas added the bug Something isn't working label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants