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

Improve handle of un-scannable files #176

Merged
merged 1 commit into from
May 15, 2019
Merged
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
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turned out to be a sneaky bug I found today, splitext will always have .extension in it, and so we were checking if e.g. .svg == svg. I'll push a fix 👍

Copy link
Collaborator

@KevinHock KevinHock Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we made the same mistake in -server too

return False
try:
with codecs.open(filename, encoding='utf-8') as f:
self._extract_secrets_from_file(f, filename_key)
Expand Down