Skip to content

Commit

Permalink
Applied optional filter_type for rule.
Browse files Browse the repository at this point in the history
Removed unused filter for PEM PRIVATE KEY
  • Loading branch information
babenek committed Dec 5, 2023
1 parent dd6575d commit 80ea705
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 0 additions & 2 deletions credsweeper/rules/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@
type: pem_key
values:
- (?P<value>-----BEGIN\s(?!ENCRYPTED|EC)[^-]*PRIVATE[^-]*KEY[^-]*-----(.+-----END[^-]+-----)?)
filter_type:
- LineSpecificKeyCheck
min_line_len: 27

- name: Picatic API Key
Expand Down
6 changes: 3 additions & 3 deletions credsweeper/rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Rule:
SEVERITY = "severity"
TYPE = "type"
VALUES = "values"
FILTER_TYPE = "filter_type"
MIN_LINE_LEN = "min_line_len"

# auxiliary fields
FILTER_TYPE = "filter_type"
USE_ML = "use_ml"
REQUIRED_SUBSTRINGS = "required_substrings"
REQUIRED_REGEX = "required_regex"
Expand All @@ -65,7 +65,7 @@ def __init__(self, config: Config, rule_dict: Dict) -> None:
self._malformed_rule_error(rule_dict, Rule.TYPE)
self.__patterns = self._init_patterns(rule_dict[Rule.VALUES])
# auxiliary fields
self.__filters = self._init_filters(rule_dict.get(Rule.FILTER_TYPE))
self.__filters = self._init_filters(rule_dict.get(Rule.FILTER_TYPE, []))
self.__use_ml = bool(rule_dict.get(Rule.USE_ML))
self.__validations = self._init_validations(rule_dict.get(Rule.VALIDATIONS))
self.__required_substrings = set(i.strip().lower() for i in rule_dict.get(Rule.REQUIRED_SUBSTRINGS, []))
Expand Down Expand Up @@ -214,7 +214,7 @@ def _assert_rule_mandatory_fields(rule_template: Dict) -> None:
ValueError if missing fields is present
"""
mandatory_fields = [Rule.NAME, Rule.SEVERITY, Rule.TYPE, Rule.VALUES, Rule.FILTER_TYPE, Rule.MIN_LINE_LEN]
mandatory_fields = [Rule.NAME, Rule.SEVERITY, Rule.TYPE, Rule.VALUES, Rule.MIN_LINE_LEN]
missing_fields = [field for field in mandatory_fields if field not in rule_template]
if len(missing_fields) > 0:
raise ValueError(f"Malformed rule config file. Contain rule with missing fields: {missing_fields}.")
Expand Down

0 comments on commit 80ea705

Please sign in to comment.