Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CloudantDetector
DiscordBotTokenDetector
GitHubTokenDetector
GitLabTokenDetector
HashiCorpVaultTokenDetector
Base64HighEntropyString
HexHighEntropyString
IbmCloudIamDetector
Expand Down
17 changes: 17 additions & 0 deletions detect_secrets/plugins/hashicorp_vault_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
This plugin searches for HashiCorp Vault tokens
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector


class HashiCorpVaultTokenDetector(RegexBasedDetector):
"""Scans for HashiCorp Vault tokens."""
secret_type = 'HashiCorp Vault Token'

denylist = [
# ref. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
# \b has been added to avoid many false positives when using Vault <=1.9 tokens
re.compile(r'(?:hv|\b)[brs]\.[A-Za-z0-9_-]{24,}'),
]
23 changes: 23 additions & 0 deletions tests/plugins/hashicorp_vault_token_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from detect_secrets.plugins.hashicorp_vault_token import HashiCorpVaultTokenDetector


class TestHashiCorpVaultTokenDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('hvs.wWPw5k4aXcaT4fNP0UcnZwJUVFk6LO0pINUx', True),
('hvs.wWPw5k4aXcaT', False),
('HideMyTokenhvs.wWPw5k4aXcaT4fNP0UcnZwJUVFk6LO0pINUx', True),
('s.wWPw5k4aXcaT4fNP0UcnZwJUVFk6LO0pINUx', True),
('MyClass.atLeast24CharactersField', False),
('MyClas s.atLeast24CharactersField', True),
('foo', False),
],
)
def test_analyze(self, payload, should_flag):
logic = HashiCorpVaultTokenDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)
assert len(output) == int(should_flag)