Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix: case-insensitive ext check (#2383)
Richard Gomez8104611d6e2e
diff --git a/pkg/common/vars.go b/pkg/common/vars.goindex c674bd9da..fc00f97c8 100644--- a/pkg/common/vars.go+++ b/pkg/common/vars.go@@ -7,46 +7,65 @@ import (var (KB, MB, GB, TB, PB = 1e3, 1e6, 1e9, 1e12, 1e15- IgnoredExtensions = []string{- // multimedia/containers- "mp4",- "avi",- "mpeg",- "mpg",- "mov",- "wmv",- "m4p",- "swf",- "mp2",- "flv",- "vob",- "webm",- "hdv",- "3gp",- "ogg",- "mp3",- "wav",- "flac",- "webp",- "pdf",-+ ignoredExtensions = map[string]struct{}{// images- "png",- "jpg",- "jpeg",- "gif",- "tiff",+ "apng": {},+ "avif": {},+ "bmp": {},+ "gif": {},+ "icns": {}, // Apple icon image file+ "ico": {}, // Icon file+ "jpg": {},+ "jpeg": {},+ "png": {},+ "svg": {},+ "svgz": {}, // Compressed Scalable Vector Graphics file+ "tga": {},+ "tif": {},+ "tiff": {},++ // audio+ "fev": {}, // video game audio+ "fsb": {},+ "m2a": {},+ "m4a": {},+ "mp2": {},+ "mp3": {},+ "snag": {},++ // video+ "264": {},+ "3gp": {},+ "avi": {},+ "flac": {},+ "flv": {},+ "hdv": {},+ "m4p": {},+ "mov": {},+ "mp4": {},+ "mpg": {},+ "mpeg": {},+ "ogg": {},+ "qt": {},+ "swf": {},+ "vob": {},+ "wav": {},+ "webm": {},+ "webp": {},+ "wmv": {},- "fnt", // Windows font file- "fon", // Generic font file- "ttf", // TrueType font- "otf", // OpenType font- "woff", // Web Open Font Format- "woff2", // Web Open Font Format 2- "eot", // Embedded OpenType font- "svgz", // Compressed Scalable Vector Graphics file- "icns", // Apple icon image file- "ico", // Icon file+ // documents+ "pdf": {},+ "psd": {},++ // fonts+ "eot": {}, // Embedded OpenType font+ "fnt": {}, // Windows font file+ "fon": {}, // Generic font file+ "otf": {}, // OpenType font+ "ttf": {}, // TrueType font+ "woff": {}, // Web Open Font Format+ "woff2": {}, // Web Open Font Format 2}binaryExtensions = map[string]struct{}{@@ -86,13 +105,11 @@ var (})+// SkipFile returns true if the file extension is in the ignoredExtensions list.func SkipFile(filename string) bool {- for _, ext := range IgnoredExtensions {- if strings.TrimPrefix(filepath.Ext(filename), ".") == ext {- return true- }- }- return false+ ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(filename), "."))+ _, ok := ignoredExtensions[ext]+ return ok}// IsBinary returns true if the file extension is in the binaryExtensions list.diff --git a/pkg/common/vars_test.go b/pkg/common/vars_test.goindex 58b06c61e..1c1e74e34 100644--- a/pkg/common/vars_test.go+++ b/pkg/common/vars_test.go@@ -1,6 +1,9 @@package common-import "testing"+import (+ "strings"+ "testing"+)func TestSkipFile(t *testing.T) {type testCase struct {@@ -9,12 +12,17 @@ func TestSkipFile(t *testing.T) {}// Add a test case for each ignored extension.- testCases := make([]testCase, 0, len(IgnoredExtensions)+1)- for _, ext := range IgnoredExtensions {+ testCases := make([]testCase, 0, (len(ignoredExtensions)+1)*2)+ for ext := range ignoredExtensions {testCases = append(testCases, testCase{file: "test." + ext,want: true,})++ testCases = append(testCases, testCase{+ file: "test." + strings.ToUpper(ext),+ want: true,+ })}// Add a test case for a file that should not be skipped.