Skip to content

fix(vulnfeeds): use canonical URLs for repository comparison in GitVersionsToCommits - #5791

Open
jess-lowe wants to merge 2 commits into
google:masterfrom
jess-lowe:fix/canonical-link
Open

fix(vulnfeeds): use canonical URLs for repository comparison in GitVersionsToCommits#5791
jess-lowe wants to merge 2 commits into
google:masterfrom
jess-lowe:fix/canonical-link

Conversation

@jess-lowe

Copy link
Copy Markdown
Contributor

Should help fix: #4489

Fixes an issue where repository redirects (e.g., facebook/react -> react/react) caused version ranges to remain unresolved.

Previously, GitVersionsToCommits compared raw repository URLs from version ranges against candidate repositories. If a range used a non-canonical URL (e.g., sourced from the CPE dictionary) but the candidate list used the canonicalized URL (or vice versa), the comparison would fail, leaving the range unresolved.

Changes

  • Updated GitVersionsToCommits to canonicalize repository URLs before populating claimedRepos and before comparing ranges with candidate repositories.
  • Introduced a local in-function cache to minimize redundant external lookups (e.g., Redis or network calls) for the same repository URL during a single invocation.

@jess-lowe
jess-lowe requested review from a team and michaelkedar August 6, 2026 01:05
another-rex
another-rex previously approved these changes Aug 6, 2026

@another-rex another-rex 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.

Just use redis

metrics.Outcome = models.Error
return nil, nil, nil
}
claimedRepos[vr.Range.GetRepo()] = true

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.

Can you add a detailed comment on claimedRepo explaining what it does?

Also, we want to claim the raw range repo (vr.Range.GetRepo()) no matter if we canonicalized it or not right?


// GitVersionsToCommits examines repos and tries to convert versions to commits by treating them as Git tags.
// Returns the resolved ranges, unresolved ranges, and successful repos involved.
func GitVersionsToCommits(versionRanges []models.RangeWithMetadata, repos []string, metrics *models.ConversionMetrics, cache git.RepoTagsCache) ([]models.RangeWithMetadata, []models.RangeWithMetadata, []string) {

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.

Could add some tests too to verify this behavior change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants