From 15701df6d09adf4e8ce2073c73238aaa3381d2fc Mon Sep 17 00:00:00 2001 From: Calvin Li Date: Thu, 6 Dec 2018 15:27:41 -0800 Subject: [PATCH 1/2] check the whitelist regex in the base plugin class --- detect_secrets/plugins/base.py | 4 ++++ test_data/config.ini | 2 ++ 2 files changed, 6 insertions(+) diff --git a/detect_secrets/plugins/base.py b/detect_secrets/plugins/base.py index 457625d9a..0ce60809a 100644 --- a/detect_secrets/plugins/base.py +++ b/detect_secrets/plugins/base.py @@ -1,6 +1,8 @@ from abc import ABCMeta from abc import abstractmethod +from detect_secrets.plugins.core.constants import WHITELIST_REGEX + class BasePlugin(object): """This is an abstract class to define Plugins API""" @@ -23,6 +25,8 @@ def analyze(self, file, filename): """ potential_secrets = {} for line_num, line in enumerate(file.readlines(), start=1): + if WHITELIST_REGEX.search(line): + continue secrets = self.analyze_string(line, line_num, filename) potential_secrets.update(secrets) diff --git a/test_data/config.ini b/test_data/config.ini index 2304d2fdd..97f5e14b4 100644 --- a/test_data/config.ini +++ b/test_data/config.ini @@ -22,3 +22,5 @@ keyB = 456789123 567891234 keyC = + +password = 12345678901234 # pragma: whitelist secret From 5b45888257f1c3250a1412d4a0a0df317da3bd64 Mon Sep 17 00:00:00 2001 From: Calvin Li Date: Thu, 6 Dec 2018 16:03:46 -0800 Subject: [PATCH 2/2] remove whitelist check from keyword plugin, this functionality moved to the base class --- detect_secrets/plugins/keyword.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/detect_secrets/plugins/keyword.py b/detect_secrets/plugins/keyword.py index 5ce4d461b..aa865f93c 100644 --- a/detect_secrets/plugins/keyword.py +++ b/detect_secrets/plugins/keyword.py @@ -28,7 +28,6 @@ from .base import BasePlugin from detect_secrets.core.potential_secret import PotentialSecret -from detect_secrets.plugins.core.constants import WHITELIST_REGEX BLACKLIST = ( @@ -54,9 +53,6 @@ class KeywordDetector(BasePlugin): def analyze_string(self, string, line_num, filename): output = {} - if WHITELIST_REGEX.search(string): - return output - for identifier in self.secret_generator(string): secret = PotentialSecret( self.secret_type,