Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ghsa): add swift support #233

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion ghsa/ghsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var (
Rust SecurityAdvisoryEcosystem = "RUST"
Erlang SecurityAdvisoryEcosystem = "ERLANG"
Pub SecurityAdvisoryEcosystem = "PUB"
Ecosystems = []SecurityAdvisoryEcosystem{Composer, Maven, Npm, Nuget, Pip, Rubygems, Go, Erlang, Rust, Pub}
Swift SecurityAdvisoryEcosystem = "SWIFT"
Ecosystems = []SecurityAdvisoryEcosystem{Composer, Maven, Npm, Nuget, Pip, Rubygems, Go, Erlang, Rust, Pub, Swift}

wait = func(i int) time.Duration {
sleep := math.Pow(float64(i), 2) + float64(utils.RandInt()%10)
Expand Down Expand Up @@ -102,6 +103,16 @@ func (c Config) update(ecosystem SecurityAdvisoryEcosystem) error {
}
ghsa.Package.Name = strings.TrimSpace(ghsa.Package.Name)

// Part Swift packages have `https://` prefix or `.git` suffix
// e.g. https://github.com/github/advisory-database/blob/76f65b0d0fdac39c8b0e834ab03562b5f80d5b27/advisories/github-reviewed/2023/06/GHSA-r6ww-5963-7r95/GHSA-r6ww-5963-7r95.json#L21
// https://github.com/github/advisory-database/blob/76f65b0d0fdac39c8b0e834ab03562b5f80d5b27/advisories/github-reviewed/2023/07/GHSA-jq43-q8mx-r7mq/GHSA-jq43-q8mx-r7mq.json#L21
// Trim them to fit the same format
// as in https://github.com/github/advisory-database/blob/76f65b0d0fdac39c8b0e834ab03562b5f80d5b27/advisories/github-reviewed/2023/06/GHSA-qvxg-wjxc-r4gg/GHSA-qvxg-wjxc-r4gg.json#L21
if ecosystem == Swift {
ghsa.Package.Name = strings.TrimLeft(ghsa.Package.Name, "https://")
ghsa.Package.Name = strings.TrimRight(ghsa.Package.Name, ".git")
}

Copy link
Collaborator

@knqyf263 knqyf263 Aug 2, 2023

Choose a reason for hiding this comment

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

Can we trim them in trivy-db rather than vuln-list-update? I'd keep the original data as much as possible in vuln-list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now i only update the directory names (61450fa).
Names in JSON are stored as in GHSA.

ghsaJson, ok := ghsaJsonMap[ghsa.Advisory.GhsaId+ghsa.Package.Name]
if ok {
va := Version{
Expand Down