-
Notifications
You must be signed in to change notification settings - Fork 1
Group CVEs #109
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
Open
eshulman2
wants to merge
1
commit into
main
Choose a base branch
from
gcve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−0
Open
Group CVEs #109
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| jira "github.com/andygrunwald/go-jira" | ||
| ) | ||
|
|
||
| // CVEFieldID is the JIRA custom field ID for the CVE identifier | ||
| const CVEFieldID = "customfield_12324749" | ||
|
|
||
| // CVEGroup represents a group of related CVE issues | ||
| type CVEGroup struct { | ||
| CVEID string | ||
| Component string | ||
| Issues []jira.Issue | ||
| } | ||
|
|
||
| // isVulnerability checks if an issue is of type "Vulnerability" | ||
| func isVulnerability(issue jira.Issue) bool { | ||
| if issue.Fields == nil || issue.Fields.Type.Name == "" { | ||
| return false | ||
| } | ||
| return issue.Fields.Type.Name == "Vulnerability" | ||
| } | ||
|
|
||
| // extractCVEID extracts the CVE identifier from an issue's custom field | ||
| func extractCVEID(issue jira.Issue) string { | ||
| if issue.Fields == nil || issue.Fields.Unknowns == nil { | ||
| return "" | ||
| } | ||
|
|
||
| if cveValue, ok := issue.Fields.Unknowns[CVEFieldID]; ok { | ||
| if cveStr, ok := cveValue.(string); ok { | ||
| return strings.TrimSpace(cveStr) | ||
| } | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // extractComponent extracts the first component name from an issue | ||
| func extractComponent(issue jira.Issue) string { | ||
| if issue.Fields == nil || len(issue.Fields.Components) == 0 { | ||
| return "unknown" | ||
| } | ||
| return issue.Fields.Components[0].Name | ||
| } | ||
|
|
||
| // groupKey creates a unique key for grouping: "CVE-ID|Component" | ||
| func groupKey(issue jira.Issue) string { | ||
| cveID := extractCVEID(issue) | ||
| component := extractComponent(issue) | ||
| return fmt.Sprintf("%s|%s", cveID, component) | ||
| } | ||
|
|
||
| // GroupCVEIssues groups issues by CVE ID + Component | ||
| // Returns a map where key is "CVE-ID|Component" and value is the CVEGroup | ||
| func GroupCVEIssues(issues []jira.Issue) map[string]*CVEGroup { | ||
| groups := make(map[string]*CVEGroup) | ||
|
|
||
| for _, issue := range issues { | ||
| key := groupKey(issue) | ||
|
|
||
| if groups[key] == nil { | ||
| groups[key] = &CVEGroup{ | ||
| CVEID: extractCVEID(issue), | ||
| Component: extractComponent(issue), | ||
| Issues: []jira.Issue{issue}, | ||
| } | ||
| } else { | ||
| groups[key].Issues = append(groups[key].Issues, issue) | ||
| } | ||
| } | ||
|
|
||
| return groups | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| jira "github.com/andygrunwald/go-jira" | ||
|
|
@@ -16,3 +17,30 @@ func notification(issue jira.Issue, slackId string) string { | |
| notification.WriteString(slack.Link(query.JiraBaseURL+"browse/"+issue.Key, issue.Key)) | ||
| return notification.String() | ||
| } | ||
|
|
||
| // cveGroupNotification creates a Slack message for a group of related CVE issues | ||
| func cveGroupNotification(group *CVEGroup, slackId string) string { | ||
| var notification strings.Builder | ||
| notification.WriteByte('<') | ||
| notification.WriteString(slackId) | ||
| notification.WriteString("> ") | ||
|
|
||
| // Format: "CVE-2024-XXXX (Component): ISSUE-1 ISSUE-2 ISSUE-3" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For bugs, the message is: |
||
| notification.WriteString(group.CVEID) | ||
| notification.WriteString(" (") | ||
| notification.WriteString(group.Component) | ||
| notification.WriteString("): ") | ||
|
|
||
| for i, issue := range group.Issues { | ||
| if i > 0 { | ||
| notification.WriteByte(' ') | ||
| } | ||
| notification.WriteString(slack.Link(query.JiraBaseURL+"browse/"+issue.Key, issue.Key)) | ||
| } | ||
|
|
||
| if len(group.Issues) > 1 { | ||
| notification.WriteString(fmt.Sprintf(" (%d related issues)", len(group.Issues))) | ||
| } | ||
|
|
||
| return notification.String() | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did you get this custom field from? Looking at a CVE issue (https://issues.redhat.com/browse/OCPBUGS-70096), I can't find a
customfield_12324749field.See https://confluence.atlassian.com/jirakb/how-to-find-any-custom-field-s-ids-744522503.html for listing the available custom fields.
I suspect we may have to find CVE via the
CVEprefix in the title.