From 2e20422d73cf719d93f31147648954dc3e1a4162 Mon Sep 17 00:00:00 2001 From: egibs <20933572+egibs@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:27:03 -0600 Subject: [PATCH] Add flag to ignore problematic file extensions Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --- cmd/mal/mal.go | 8 ++++++++ pkg/action/scan.go | 11 +++++++++++ pkg/malcontent/malcontent.go | 1 + 3 files changed, 20 insertions(+) diff --git a/cmd/mal/mal.go b/cmd/mal/mal.go index 523e2b726..517db9ab6 100644 --- a/cmd/mal/mal.go +++ b/cmd/mal/mal.go @@ -52,6 +52,7 @@ var ( fileRiskChangeFlag bool fileRiskIncreaseFlag bool formatFlag string + ignoreExtsFlag string ignoreSelfFlag bool ignoreTagsFlag string includeDataFilesFlag bool @@ -243,6 +244,7 @@ func main() { Concurrency: concurrencyFlag, ExitFirstHit: exitFirstHitFlag, ExitFirstMiss: exitFirstMissFlag, + IgnoreExts: ignoreExtsFlag, IgnoreSelf: ignoreSelfFlag, IgnoreTags: ignoreTags, IncludeDataFiles: includeDataFiles, @@ -284,6 +286,12 @@ func main() { Usage: "Output format (json, markdown, simple, strings, terminal, yaml)", Destination: &formatFlag, }, + &cli.StringFlag{ + Name: "ignore-exts", + Value: "", + Usage: "Ignore specific file extensions when scanning", + Destination: &ignoreExtsFlag, + }, &cli.BoolFlag{ Name: "ignore-self", Value: true, diff --git a/pkg/action/scan.go b/pkg/action/scan.go index e4a524c02..aff8ffdef 100644 --- a/pkg/action/scan.go +++ b/pkg/action/scan.go @@ -97,6 +97,17 @@ func scanSinglePath(ctx context.Context, c malcontent.Config, path string, ruleF isArchive := archiveRoot != "" + var exts []string + if c.IgnoreExts != "" { + exts = strings.Split(c.IgnoreExts, ",") + for _, ext := range exts { + if ext == getExt(path) { + logger.Infof("skipping %s [%s]: ignored file extension", path, ext) + return &malcontent.FileReport{Skipped: "ignored file extension", Path: path}, nil + } + } + } + mime := "" kind, err := programkind.File(path) if err != nil { diff --git a/pkg/malcontent/malcontent.go b/pkg/malcontent/malcontent.go index 480bf0ce0..bf0c821ec 100644 --- a/pkg/malcontent/malcontent.go +++ b/pkg/malcontent/malcontent.go @@ -26,6 +26,7 @@ type Config struct { ExitFirstMiss bool FileRiskChange bool FileRiskIncrease bool + IgnoreExts string IgnoreSelf bool IgnoreTags []string IncludeDataFiles bool