Skip to content

Commit

Permalink
Improve handle of un-scannable files
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>

Fix style

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>

Improve style

Signed-off-by: Daniel González Lopes <danielgonzalezlopes@gmail.com>
  • Loading branch information
dgzlopes committed May 15, 2019
1 parent 38b559c commit 5cb6074
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions detect_secrets/core/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# We don't scan files with these extensions.
# NOTE: We might be able to do this better with
# `subprocess.check_output(['file', filename])`
# and look for "ASCII text", but that might be more expensive.
#
# Definitely something to look into, if this list gets unruly long.
IGNORED_FILE_EXTENSIONS = {
'7z',
'bmp',
'bz2',
'dmg',
'exe',
'gif',
'gz',
'ico',
'jar',
'jpg',
'jpeg',
'png',
'rar',
'realm',
's7z',
'tar',
'tif',
'tiff',
'webp',
'zip',
}
4 changes: 3 additions & 1 deletion detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from time import strftime

from detect_secrets import VERSION
from detect_secrets.core.constants import IGNORED_FILE_EXTENSIONS
from detect_secrets.core.log import log
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.plugins.common import initialize
Expand Down Expand Up @@ -200,7 +201,8 @@ def scan_file(self, filename, filename_key=None):

if os.path.islink(filename):
return False

if os.path.splitext(filename)[1] in IGNORED_FILE_EXTENSIONS:
return False
try:
with codecs.open(filename, encoding='utf-8') as f:
self._extract_secrets_from_file(f, filename_key)
Expand Down

0 comments on commit 5cb6074

Please sign in to comment.