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(server): Apply filters for IgnoreCves and PkgsRegexps on server mode #1270

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Collaborator

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?


// IgnoreUnscoredCves
if h.IgnoreUnscoredCves {
Copy link
Collaborator

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.IgnoreUnscoredCves?

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() {
Expand Down
20 changes: 12 additions & 8 deletions subcmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 config.Conf.IgnoreUnfixed and config.Conf.IgnoreUnscoredCves.
https://github.com/qwexvf/vuls/blob/93729c6e73fef787c2d349e1ee1a404a32824d6c/config/config.go#L77-L78

f.StringVar(&config.Conf.HTTPProxy, "http-proxy", "",
"http://proxy-url:port (default: empty)")

Expand All @@ -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")
Expand Down