-
Notifications
You must be signed in to change notification settings - Fork 74
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
Exclusion reasons #286
Exclusion reasons #286
Changes from 6 commits
c669860
38da432
8a2c213
fbac150
93a2a05
518a0f8
99e4bbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -129,6 +129,7 @@ def __bytes__(self) -> bytes: | |||||||||||
return self.__str__().encode("utf8") | ||||||||||||
|
||||||||||||
|
||||||||||||
# pylint: disable=too-many-public-methods | ||||||||||||
class ScannerBase(abc.ABC): # pylint: disable=too-many-instance-attributes | ||||||||||||
"""Provide the base, generic functionality needed by all scanners. | ||||||||||||
|
||||||||||||
|
@@ -149,6 +150,8 @@ class ScannerBase(abc.ABC): # pylint: disable=too-many-instance-attributes | |||||||||||
global_options: types.GlobalOptions | ||||||||||||
logger: logging.Logger | ||||||||||||
_scan_lock: threading.Lock = threading.Lock() | ||||||||||||
_excluded_findings: tuple = () | ||||||||||||
_config_data: MutableMapping[str, Any] = {} | ||||||||||||
|
||||||||||||
def __init__(self, options: types.GlobalOptions) -> None: | ||||||||||||
self.global_options = options | ||||||||||||
|
@@ -336,6 +339,36 @@ def should_scan(self, file_path: str): | |||||||||||
return False | ||||||||||||
return True | ||||||||||||
|
||||||||||||
@property | ||||||||||||
def config_data(self): | ||||||||||||
return self._config_data | ||||||||||||
|
||||||||||||
@config_data.setter | ||||||||||||
def config_data(self, data) -> MutableMapping[str, Any]: | ||||||||||||
self._config_data = data | ||||||||||||
return self._config_data | ||||||||||||
tarkatronic marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Returning data from a setter in Python is generally not a valuable operation, because there's no way to access it. You would need something like... new_data = scanner.config_data = data Which is just confusing. And probably won't even work the way you expect. You can find a bit more of an explanation here, if you're interested: https://stackoverflow.com/a/16615910 |
||||||||||||
|
||||||||||||
@cached_property | ||||||||||||
def excluded_findings(self) -> tuple: | ||||||||||||
configured_signatures = [] | ||||||||||||
signatures = self.config_data.get("exclude_signatures", None) | ||||||||||||
if signatures: | ||||||||||||
warnings.warn( | ||||||||||||
"--exclude-signatures has been deprecated and will be removed in a future version. " | ||||||||||||
"Make sure all the exclusions are moved to exclude-findings section with new format. Example: " | ||||||||||||
"exclude-findings = [{signature='signature', reason='The reason of excluding the signature'}]", | ||||||||||||
DeprecationWarning, | ||||||||||||
) | ||||||||||||
configured_signatures.extend(signatures) | ||||||||||||
findings = self.config_data.get("exclude_findings", None) | ||||||||||||
if findings: | ||||||||||||
configured_signatures.extend([finding["signature"] for finding in findings]) | ||||||||||||
|
||||||||||||
self._excluded_findings = tuple( | ||||||||||||
set(self.global_options.exclude_signatures + tuple(configured_signatures)) | ||||||||||||
) | ||||||||||||
return self._excluded_findings | ||||||||||||
|
||||||||||||
def signature_is_excluded(self, blob: str, file_path: str) -> bool: | ||||||||||||
"""Find whether the signature of some data has been excluded in configuration. | ||||||||||||
|
||||||||||||
|
@@ -344,9 +377,8 @@ def signature_is_excluded(self, blob: str, file_path: str) -> bool: | |||||||||||
""" | ||||||||||||
return ( | ||||||||||||
blob | ||||||||||||
in self.global_options.exclude_signatures # Signatures themselves pop up as entropy matches | ||||||||||||
or util.generate_signature(blob, file_path) | ||||||||||||
in self.global_options.exclude_signatures | ||||||||||||
in self.excluded_findings # Signatures themselves pop up as entropy matches | ||||||||||||
or util.generate_signature(blob, file_path) in self.excluded_findings | ||||||||||||
) | ||||||||||||
|
||||||||||||
@staticmethod | ||||||||||||
|
@@ -660,14 +692,7 @@ def load_repo(self, repo_path: str) -> pygit2.Repository: | |||||||||||
except (FileNotFoundError, types.ConfigException): | ||||||||||||
config_file = None | ||||||||||||
if config_file and config_file != self.global_options.config: | ||||||||||||
signatures = data.get("exclude_signatures", None) | ||||||||||||
if signatures: | ||||||||||||
self.global_options.exclude_signatures = tuple( | ||||||||||||
set(self.global_options.exclude_signatures + tuple(signatures)) | ||||||||||||
) | ||||||||||||
entropy_patterns = data.get("exclude_entropy_patterns", None) | ||||||||||||
if entropy_patterns: | ||||||||||||
self.global_options.exclude_entropy_patterns += tuple(entropy_patterns) | ||||||||||||
self.config_data = data | ||||||||||||
include_patterns = list(data.get("include_path_patterns", ())) | ||||||||||||
repo_include_file = data.get("include_paths", None) | ||||||||||||
if repo_include_file: | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.