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
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 12 additions & 2 deletions 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 @@ -129,7 +130,16 @@ func (c Config) update(ecosystem SecurityAdvisoryEcosystem) error {

bar := pb.StartNew(len(ghsaJsonMap))
for _, ghsaJson := range ghsaJsonMap {
dir := filepath.Join(c.vulnListDir, ghsaDir, strings.ToLower(string(ecosystem)), strings.Replace(ghsaJson.Package.Name, ":", "/", -1))
pkgName := strings.Replace(ghsaJson.Package.Name, ":", "/", -1)
// Part Swift advisories 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 get correct directory
if ecosystem == Swift {
pkgName = strings.TrimPrefix(pkgName, "https///")
pkgName = strings.TrimSuffix(pkgName, ".git")
}
dir := filepath.Join(c.vulnListDir, ghsaDir, strings.ToLower(string(ecosystem)), pkgName)
err := c.saveGSHA(dir, ghsaJson.Advisory.GhsaId, ghsaJson)
if err != nil {
return xerrors.Errorf("failed to save github security advisory: %w", err)
Expand Down
72 changes: 72 additions & 0 deletions ghsa/ghsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,78 @@ func TestConfig_Update(t *testing.T) {
},
expectedErrorMsg: "",
},
{
name: "happy path with correct swift dir name",
appFs: afero.NewMemMapFs(),
inputEcosystem: Swift,
goldenFiles: map[string]string{
"/tmp/ghsa/swift/github.com/grpc/grpc-swift/GHSA-r6ww-5963-7r95.json": "testdata/swift/github.com/grpc/grpc-swift/GHSA-r6ww-5963-7r95.json",
},
inputResponse: map[githubql.String]GetVulnerabilitiesQuery{
githubql.String(""): {
SecurityVulnerabilities: SecurityVulnerabilities{
Nodes: []GithubSecurityAdvisory{
{
Severity: "HIGH",
UpdatedAt: "2023-06-09T19:33:17Z",
Package: Package{
Ecosystem: "SWIFT",
Name: "https://github.com/grpc/grpc-swift.git",
},
Advisory: Advisory{
DatabaseId: 212034,
Id: "GSA_kwCzR0hTQS1yNnd3LTU5NjMtN3I5Nc4AAzxC",
GhsaId: "GHSA-r6ww-5963-7r95",
References: []Reference{
{
Url: "https://github.com/grpc/grpc-swift/security/advisories/GHSA-r6ww-5963-7r95",
},
{
Url: "https://nvd.nist.gov/vuln/detail/CVE-2022-24777",
},
{
Url: "https://github.com/grpc/grpc-swift/commit/858f977f2a51fca2292f384cf7a108dc2e73a3bd",
},
{
Url: "https://github.com/advisories/GHSA-r6ww-5963-7r95",
},
},
Identifiers: []Identifier{
{
Type: "GHSA",
Value: "GHSA-r6ww-5963-7r95",
},
{
Type: "CVE",
Value: "CVE-2022-24777",
},
},
Description: "A grpc-swift server is vulnerable to a denial of service attack via a reachable assertion. This was due to incorrect logic when handling `GOAWAY` frames.\n\nThe attack is low-effort: it takes very little resources to construct and send the required sequence of frames. The impact on availability is high as the server will crash, dropping all in flight connections and requests.\n\nThe issue was discovered by automated fuzz testing and is resolved by fixing the relevant state handling code.",
Origin: "UNSPECIFIED",
PublishedAt: "2023-06-09T19:33:16Z",
Severity: "HIGH",
Summary: "Denial of Service via reachable assertion",
UpdatedAt: "2023-06-19T16:45:07Z",
WithdrawnAt: "",
CVSS: GithubCVSS{
Score: 7.5,
VectorString: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
},
},
FirstPatchedVersion: FirstPatchedVersion{
Identifier: "1.7.2",
},
VulnerableVersionRange: "\u003c 1.7.2",
},
},
PageInfo: PageInfo{
EndCursor: githubql.String(""),
HasNextPage: false,
},
},
},
},
},
{
name: "read only filesystem test",
appFs: afero.NewReadOnlyFs(afero.NewOsFs()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"Severity": "HIGH",
"UpdatedAt": "2023-06-09T19:33:17Z",
"Package": {
"Ecosystem": "SWIFT",
"Name": "https://github.com/grpc/grpc-swift.git"
},
"Advisory": {
"DatabaseId": 212034,
"Id": "GSA_kwCzR0hTQS1yNnd3LTU5NjMtN3I5Nc4AAzxC",
"GhsaId": "GHSA-r6ww-5963-7r95",
"References": [
{
"Url": "https://github.com/grpc/grpc-swift/security/advisories/GHSA-r6ww-5963-7r95"
},
{
"Url": "https://nvd.nist.gov/vuln/detail/CVE-2022-24777"
},
{
"Url": "https://github.com/grpc/grpc-swift/commit/858f977f2a51fca2292f384cf7a108dc2e73a3bd"
},
{
"Url": "https://github.com/advisories/GHSA-r6ww-5963-7r95"
}
],
"Identifiers": [
{
"Type": "GHSA",
"Value": "GHSA-r6ww-5963-7r95"
},
{
"Type": "CVE",
"Value": "CVE-2022-24777"
}
],
"Description": "A grpc-swift server is vulnerable to a denial of service attack via a reachable assertion. This was due to incorrect logic when handling `GOAWAY` frames.\n\nThe attack is low-effort: it takes very little resources to construct and send the required sequence of frames. The impact on availability is high as the server will crash, dropping all in flight connections and requests.\n\nThe issue was discovered by automated fuzz testing and is resolved by fixing the relevant state handling code.",
"Origin": "UNSPECIFIED",
"PublishedAt": "2023-06-09T19:33:16Z",
"Severity": "HIGH",
"Summary": "Denial of Service via reachable assertion",
"UpdatedAt": "2023-06-19T16:45:07Z",
"WithdrawnAt": "",
"CVSS": {
"Score": 7.5,
"VectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
}
},
"Versions": [
{
"FirstPatchedVersion": {
"Identifier": "1.7.2"
},
"VulnerableVersionRange": "\u003c 1.7.2"
}
]
}