Skip to content

Commit a12a15e

Browse files
authored
Merge pull request #612 from nimrodkor/don't_filter_out_access_key_id_finding
Don't filter out AWS access key ID with the ID filter
2 parents 9475112 + a91bcdb commit a12a15e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

detect_secrets/filters/heuristic.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
import re
33
import string
44
from functools import lru_cache
5+
from typing import Optional
56
from typing import Pattern
67

8+
from detect_secrets.plugins.base import BasePlugin
9+
from detect_secrets.plugins.base import RegexBasedDetector
10+
711

812
def is_sequential_string(secret: str) -> bool:
913
sequences = (
@@ -57,13 +61,14 @@ def _get_uuid_regex() -> Pattern:
5761
)
5862

5963

60-
def is_likely_id_string(secret: str, line: str) -> bool:
64+
def is_likely_id_string(secret: str, line: str, plugin: Optional[BasePlugin] = None) -> bool:
6165
try:
6266
index = line.index(secret)
6367
except ValueError:
6468
return False
6569

66-
return bool(_get_id_detector_regex().search(line, pos=0, endpos=index))
70+
return (not plugin or not isinstance(plugin, RegexBasedDetector)) \
71+
and bool(_get_id_detector_regex().search(line, pos=0, endpos=index))
6772

6873

6974
@lru_cache(maxsize=1)

tests/filters/heuristic_filter_test.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from detect_secrets import filters
66
from detect_secrets.core.scan import scan_line
7+
from detect_secrets.plugins.aws import AWSKeyDetector
78
from detect_secrets.settings import transient_settings
89

910

@@ -77,23 +78,26 @@ def test_success(self, secret, line):
7778
assert filters.heuristic.is_likely_id_string(secret, line)
7879

7980
@pytest.mark.parametrize(
80-
'secret, line',
81+
'secret, line, plugin',
8182
[
8283
# the word hidden has the word id in it, but lets
8384
# not mark that as an id string
84-
('RANDOM_STRING', 'hidden_secret: RANDOM_STRING'),
85-
('RANDOM_STRING', 'hidden_secret=RANDOM_STRING'),
86-
('RANDOM_STRING', 'hidden_secret = RANDOM_STRING'),
85+
('RANDOM_STRING', 'hidden_secret: RANDOM_STRING', None),
86+
('RANDOM_STRING', 'hidden_secret=RANDOM_STRING', None),
87+
('RANDOM_STRING', 'hidden_secret = RANDOM_STRING', None),
8788
8889
# fail silently if the secret isn't even on the line
89-
('SOME_RANDOM_STRING', 'id: SOME_OTHER_RANDOM_STRING'),
90+
('SOME_RANDOM_STRING', 'id: SOME_OTHER_RANDOM_STRING', None),
9091
9192
# fail although the word david ends in id
92-
('RANDOM_STRING', 'postgres://david:RANDOM_STRING'),
93+
('RANDOM_STRING', 'postgres://david:RANDOM_STRING', None),
94+
95+
# fail since this is an aws access key id, a real secret
96+
('AKIA4NACSIJMDDNSEDTE', 'aws_access_key_id=AKIA4NACSIJMDDNSEDTE', AWSKeyDetector()),
9397
],
9498
)
95-
def test_failure(self, secret, line):
96-
assert not filters.heuristic.is_likely_id_string(secret, line)
99+
def test_failure(self, secret, line, plugin):
100+
assert not filters.heuristic.is_likely_id_string(secret, line, plugin)
97101

98102

99103
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)