Skip to content

Commit 8a14e43

Browse files
authored
Merge pull request #123 from killuazhu/contribute-more-basic-auth-cases
Remove some false positives from basic auth
2 parents 462ade6 + 3e179cd commit 8a14e43

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

detect_secrets/plugins/basic_auth.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from .base import RegexBasedDetector
66

77

8-
SPECIAL_URL_CHARACTERS = ':/?#[]@'
8+
RESERVED_CHARACTERS = ':/?#[]@'
9+
SUB_DELIMITER_CHARACTERS = '!$&\';' # and anything else we might need
910

1011

1112
class BasicAuthDetector(RegexBasedDetector):
@@ -14,8 +15,8 @@ class BasicAuthDetector(RegexBasedDetector):
1415
blacklist = [
1516
re.compile(
1617
r'://[^{}\s]+:([^{}\s]+)@'.format(
17-
re.escape(SPECIAL_URL_CHARACTERS),
18-
re.escape(SPECIAL_URL_CHARACTERS),
18+
re.escape(RESERVED_CHARACTERS + SUB_DELIMITER_CHARACTERS),
19+
re.escape(RESERVED_CHARACTERS + SUB_DELIMITER_CHARACTERS),
1920
),
2021
),
2122
]

tests/plugins/basic_auth_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class TestBasicAuthDetector(object):
1212
[
1313
('https://username:[email protected]', True,),
1414
('http://localhost:5000/<%= @variable %>', False,),
15+
('"https://url:8000";@something else', False,),
16+
('\'https://url:8000\';@something else', False,),
17+
('https://url:8000 @something else', False,),
18+
('https://url:8000/ @something else', False,),
1519
],
1620
)
1721
def test_analyze_string(self, payload, should_flag):

0 commit comments

Comments
 (0)