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

Add flag to ignore problematic file extensions #643

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/mal/mal.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
fileRiskChangeFlag bool
fileRiskIncreaseFlag bool
formatFlag string
ignoreExtsFlag string
ignoreSelfFlag bool
ignoreTagsFlag string
includeDataFilesFlag bool
Expand Down Expand Up @@ -243,6 +244,7 @@ func main() {
Concurrency: concurrencyFlag,
ExitFirstHit: exitFirstHitFlag,
ExitFirstMiss: exitFirstMissFlag,
IgnoreExts: ignoreExtsFlag,
IgnoreSelf: ignoreSelfFlag,
IgnoreTags: ignoreTags,
IncludeDataFiles: includeDataFiles,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pkg/action/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "<unknown>"
kind, err := programkind.File(path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/malcontent/malcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
ExitFirstMiss bool
FileRiskChange bool
FileRiskIncrease bool
IgnoreExts string
IgnoreSelf bool
IgnoreTags []string
IncludeDataFiles bool
Expand Down