mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
fix: case-insensitive ext check (#2383)
This commit is contained in:
parent
901c851698
commit
8104611d6e
2 changed files with 72 additions and 47 deletions
|
@ -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": {},
|
||||
|
||||
"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
|
||||
// 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": {},
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue