Skip to content

Commit

Permalink
Normalize GitHub repos to lowercase (#2199)
Browse files Browse the repository at this point in the history
Problem: #2182 made checks for existing commits case-insensitive by
repo, but left the underlying repo string alone. There are a lot of
mixed-case GitHub repos in existence, because `cves.extractGitCommit()`
takes the repo verbatim.

`vulns.AddPkgInfo()` aggregates events by repo, case insensitively, so
was producing incorrect GIT events.

GitHub repo names are known to be case insensitive, so this is safe for
them. It's definitively less safe for other URLs, so limit to just them
for now.
  • Loading branch information
andrewpollock committed May 10, 2024
1 parent 0dad37e commit f67f746
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions vulnfeeds/cves/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ type AffectedCommit struct {
}

func (ac *AffectedCommit) SetRepo(repo string) {
// GitHub.com repos are demonstrably case-insensitive, and frequently
// expressed in URLs with varying cases, so normalize them to lowercase.
// vulns.AddPkgInfo() treats repos case sensitively, and this can result in
// incorrect behaviour.
if strings.Contains(strings.ToLower(repo), "github.com") {
repo = strings.ToLower(repo)
}
ac.Repo = repo
}

Expand Down
2 changes: 1 addition & 1 deletion vulnfeeds/cves/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestExtractGitCommit(t *testing.T) {
inputLink: "https://github.com/uWebSockets/uWebSockets/commit/37deefd01f0875e133ea967122e3a5e421b8fcd9",
inputCommitType: Fixed,
expectedAffectedCommit: AffectedCommit{
Repo: "https://github.com/uNetworking/uWebSockets",
Repo: "https://github.com/unetworking/uwebsockets",
Fixed: "37deefd01f0875e133ea967122e3a5e421b8fcd9",
},
},
Expand Down

0 comments on commit f67f746

Please sign in to comment.