-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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(server): Apply filters for IgnoreCves and PkgsRegexps on server mode #1270
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -23,6 +23,8 @@ import ( | |
// VulsHandler is used for vuls server mode | ||
type VulsHandler struct { | ||
ToLocalFile bool | ||
IgnoreUnfixed bool | ||
IgnoreUnscoredCves bool | ||
} | ||
|
||
// ServeHTTP is http handler | ||
|
@@ -95,6 +97,32 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
|
||
detector.FillCweDict(&r) | ||
|
||
// IgnoreCves | ||
ignoreCves := []string{} | ||
if r.Container.Name == "" { | ||
ignoreCves = config.Conf.Servers[r.ServerName].IgnoreCves | ||
} else if con, ok := config.Conf.Servers[r.ServerName].Containers[r.Container.Name]; ok { | ||
ignoreCves = con.IgnoreCves | ||
} | ||
r.ScannedCves = r.ScannedCves.FilterIgnoreCves(ignoreCves) | ||
|
||
// ignorePkgs | ||
ignorePkgsRegexps := []string{} | ||
if r.Container.Name == "" { | ||
ignorePkgsRegexps = config.Conf.Servers[r.ServerName].IgnorePkgsRegexp | ||
} else if s, ok := config.Conf.Servers[r.ServerName].Containers[r.Container.Name]; ok { | ||
ignorePkgsRegexps = s.IgnorePkgsRegexp | ||
} | ||
r.ScannedCves = r.ScannedCves.FilterIgnorePkgs(ignorePkgsRegexps) | ||
|
||
// IgnoreUnfixed | ||
r.ScannedCves = r.ScannedCves.FilterUnfixed(h.IgnoreUnfixed) | ||
|
||
// IgnoreUnscoredCves | ||
if h.IgnoreUnscoredCves { | ||
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. Isn't it possible to use |
||
r.ScannedCves = r.ScannedCves.FindScoredVulns() | ||
} | ||
|
||
// set ReportedAt to current time when it's set to the epoch, ensures that ReportedAt will be set | ||
// properly for scans sent to vuls when running in server mode | ||
if r.ReportedAt.IsZero() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ import ( | |
|
||
// ServerCmd is subcommand for server | ||
type ServerCmd struct { | ||
configPath string | ||
listen string | ||
toLocalFile bool | ||
configPath string | ||
listen string | ||
toLocalFile bool | ||
ignoreUnfixed bool | ||
ignoreUnscoredCves bool | ||
} | ||
|
||
// Name return subcommand name | ||
|
@@ -70,12 +72,12 @@ func (p *ServerCmd) SetFlags(f *flag.FlagSet) { | |
f.Float64Var(&config.Conf.CvssScoreOver, "cvss-over", 0, | ||
"-cvss-over=6.5 means Servering CVSS Score 6.5 and over (default: 0 (means Server all))") | ||
|
||
f.BoolVar(&config.Conf.IgnoreUnscoredCves, "ignore-unscored-cves", false, | ||
"Don't Server the unscored CVEs") | ||
|
||
f.BoolVar(&config.Conf.IgnoreUnfixed, "ignore-unfixed", false, | ||
f.BoolVar(&p.ignoreUnfixed, "ignore-unfixed", false, | ||
"Don't show the unfixed CVEs") | ||
|
||
f.BoolVar(&p.ignoreUnscoredCves, "ignore-unscored-cves", false, | ||
"Don't show the unscored CVEs") | ||
|
||
Comment on lines
-73
to
+80
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. I don't understand why you add it to serverCmd to manage option states instead of |
||
f.StringVar(&config.Conf.HTTPProxy, "http-proxy", "", | ||
"http://proxy-url:port (default: empty)") | ||
|
||
|
@@ -99,7 +101,9 @@ func (p *ServerCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{} | |
} | ||
|
||
http.Handle("/vuls", server.VulsHandler{ | ||
ToLocalFile: p.toLocalFile, | ||
ToLocalFile: p.toLocalFile, | ||
IgnoreUnfixed: p.ignoreUnfixed, | ||
IgnoreUnscoredCves: p.ignoreUnscoredCves, | ||
}) | ||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "ok") | ||
|
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.
Isn't it possible to use
config.Conf.IgnoreUnfixed
?