-
Notifications
You must be signed in to change notification settings - Fork 19
Pr/GitHub security #1783
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
base: main
Are you sure you want to change the base?
Pr/GitHub security #1783
Changes from all commits
b335958
d600c63
4e94b2f
71904a8
219dae2
7aeb942
ed8e91d
4387422
11d830e
9cc0c08
cdf3c86
cd3a3f5
0fc3ff1
6922ccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,4 +25,8 @@ external/diffgen/target | |
|
|
||
| # For AI agents | ||
| TODO.md | ||
| .envrc | ||
| .db/ | ||
| db/ | ||
| .DS_Store | ||
| out/ | ||
| bin/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package v1 | ||
|
|
||
| type AzureAD struct { | ||
| BaseScraper `json:",inline"` | ||
| AzureConnection `yaml:",inline" json:",inline"` | ||
| Users AzureUsers `yaml:"users,omitempty" json:"users,omitempty"` | ||
| Groups AzureGroups `yaml:"groups,omitempty" json:"groups,omitempty"` | ||
| AppRegistrations AzureAppRegistrations `yaml:"appRegistrations,omitempty" json:"appRegistrations,omitempty"` | ||
| Logins AzureLogins `yaml:"logins,omitempty" json:"logins,omitempty"` | ||
| } | ||
|
|
||
| type CELFilter string | ||
|
|
||
| type MsGraphFilter struct { | ||
| Filter []CELFilter `yaml:"filter,omitempty" json:"filter,omitempty"` | ||
| // MS.Graph query string | ||
| Query string `yaml:"query,omitempty" json:"query,omitempty"` | ||
| } | ||
|
|
||
| type AzureLogins struct { | ||
| MsGraphFilter `yaml:",inline" json:",inline"` | ||
| } | ||
|
|
||
| type AzureUsers struct { | ||
| MsGraphFilter `yaml:",inline" json:",inline"` | ||
| } | ||
|
|
||
| type AzureGroups struct { | ||
| MsGraphFilter `yaml:",inline" json:",inline"` | ||
| } | ||
|
|
||
| type AzureAppRegistrations struct { | ||
| MsGraphFilter `yaml:",inline" json:",inline"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/flanksource/duty/types" | ||
| ) | ||
|
|
||
| // GitHubSecurity scraper fetches security alerts from GitHub repositories | ||
| // including Dependabot alerts, code scanning alerts, secret scanning alerts, | ||
| // and security advisories. | ||
| type GitHubSecurity struct { | ||
| BaseScraper `json:",inline" yaml:",inline"` | ||
|
|
||
| // Repositories is the list of repositories to scan | ||
| Repositories []GitHubSecurityRepository `yaml:"repositories" json:"repositories"` | ||
|
|
||
| // PersonalAccessToken for GitHub API authentication | ||
| // Required scopes: repo (full) or security_events (read) | ||
| PersonalAccessToken types.EnvVar `yaml:"personalAccessToken,omitempty" json:"personalAccessToken,omitempty"` | ||
|
|
||
| // ConnectionName, if provided, will be used to populate personalAccessToken | ||
| ConnectionName string `yaml:"connection,omitempty" json:"connection,omitempty"` | ||
|
|
||
| // Filters for security alerts | ||
| Filters GitHubSecurityFilters `yaml:"filters,omitempty" json:"filters,omitempty"` | ||
| } | ||
|
|
||
| // GitHubSecurityRepository specifies a repository to scan | ||
| type GitHubSecurityRepository struct { | ||
| Owner string `yaml:"owner" json:"owner"` | ||
| Repo string `yaml:"repo" json:"repo"` | ||
| } | ||
|
|
||
| // GitHubSecurityFilters defines filtering options for security alerts | ||
| type GitHubSecurityFilters struct { | ||
| // Severity filters: critical, high, medium, low | ||
| Severity []string `yaml:"severity,omitempty" json:"severity,omitempty"` | ||
|
|
||
| // State filters: open, closed, dismissed, fixed | ||
| State []string `yaml:"state,omitempty" json:"state,omitempty"` | ||
|
|
||
| // MaxAge filters alerts by age (e.g., "90d", "30d") | ||
| MaxAge string `yaml:"maxAge,omitempty" json:"maxAge,omitempty"` | ||
| } | ||
|
|
||
| // ParseMaxAge converts the MaxAge string to a time.Duration | ||
| func (f GitHubSecurityFilters) ParseMaxAge() (time.Duration, error) { | ||
| if f.MaxAge == "" { | ||
| return 0, nil | ||
| } | ||
| return time.ParseDuration(f.MaxAge) | ||
| } | ||
|
Comment on lines
+47
to
+53
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. Fix duration parsing to support documented format. The Consider implementing custom parsing or updating the documentation to use hours (e.g., "2160h" for 90 days): // ParseMaxAge converts the MaxAge string to a time.Duration
func (f GitHubSecurityFilters) ParseMaxAge() (time.Duration, error) {
if f.MaxAge == "" {
return 0, nil
}
- return time.ParseDuration(f.MaxAge)
+ // Support days suffix (e.g., "90d")
+ if strings.HasSuffix(f.MaxAge, "d") {
+ days, err := strconv.Atoi(strings.TrimSuffix(f.MaxAge, "d"))
+ if err != nil {
+ return 0, fmt.Errorf("invalid duration format: %w", err)
+ }
+ return time.Duration(days) * 24 * time.Hour, nil
+ }
+ return time.ParseDuration(f.MaxAge)
} |
||
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.
Add nil guard to prevent panic.
Both
IsDebug()andIsTrace()(line 162) accessctx.scrapeConfig.Specwithout checking ifctx.scrapeConfigis nil. SinceScrapeConfig()(line 140) can return nil, calling these methods will panic if the scrape config hasn't been set.Apply this diff to add nil guards:
func (ctx ScrapeContext) IsTrace() bool { + if ctx.scrapeConfig == nil { + return false + } return ctx.scrapeConfig.Spec.IsTrace() } func (ctx ScrapeContext) IsDebug() bool { + if ctx.scrapeConfig == nil { + return false + } return ctx.scrapeConfig.Spec.IsDebug() }🤖 Prompt for AI Agents