Skip to content

Commit 97f2fa6

Browse files
authored
↪️ Merge pull request #176 from dgzlopes/fix-141-handle-unscannable-files
Improve handle of un-scannable files
2 parents 38b559c + 5cb6074 commit 97f2fa6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

detect_secrets/core/constants.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# We don't scan files with these extensions.
2+
# NOTE: We might be able to do this better with
3+
# `subprocess.check_output(['file', filename])`
4+
# and look for "ASCII text", but that might be more expensive.
5+
#
6+
# Definitely something to look into, if this list gets unruly long.
7+
IGNORED_FILE_EXTENSIONS = {
8+
'7z',
9+
'bmp',
10+
'bz2',
11+
'dmg',
12+
'exe',
13+
'gif',
14+
'gz',
15+
'ico',
16+
'jar',
17+
'jpg',
18+
'jpeg',
19+
'png',
20+
'rar',
21+
'realm',
22+
's7z',
23+
'tar',
24+
'tif',
25+
'tiff',
26+
'webp',
27+
'zip',
28+
}

detect_secrets/core/secrets_collection.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from time import strftime
99

1010
from detect_secrets import VERSION
11+
from detect_secrets.core.constants import IGNORED_FILE_EXTENSIONS
1112
from detect_secrets.core.log import log
1213
from detect_secrets.core.potential_secret import PotentialSecret
1314
from detect_secrets.plugins.common import initialize
@@ -200,7 +201,8 @@ def scan_file(self, filename, filename_key=None):
200201

201202
if os.path.islink(filename):
202203
return False
203-
204+
if os.path.splitext(filename)[1] in IGNORED_FILE_EXTENSIONS:
205+
return False
204206
try:
205207
with codecs.open(filename, encoding='utf-8') as f:
206208
self._extract_secrets_from_file(f, filename_key)

0 commit comments

Comments
 (0)