Skip to content
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

Adds artifactory credential detector to plugins #157

Merged
merged 6 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ The current heuristic searches we implement out of the box include:

* **KeywordDetector**: checks to see if certain keywords are being used e.g. `password` or `secret`

* **ArtifactoryDetector**: checks to see if Artifactory credentials are present.

See [detect_secrets/
plugins](https://github.com/Yelp/detect-secrets/tree/master/detect_secrets/plugins)
for more details.
Expand Down
5 changes: 5 additions & 0 deletions detect_secrets/core/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ class PluginOptions(object):
disable_flag_text='--no-slack-scan',
disable_help_text='Disables scanning for Slack tokens.',
),
PluginDescriptor(
classname='ArtifactoryDetector',
disable_flag_text='--no-artifactory-scan',
disable_help_text='Disable scanning for Artifactory credentials',
),
]

def __init__(self, parser):
Expand Down
17 changes: 17 additions & 0 deletions detect_secrets/plugins/artifactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import absolute_import

import re

from .base import RegexBasedDetector


class ArtifactoryDetector(RegexBasedDetector):

secret_type = 'Artifactory Credentials'

blacklist = [
# artifactory tokens begin with AKC
re.compile(r'(\s|=|"|^)AKC\w{10,}'), # api token
# artifactory encrypted passwords begin with AP6
re.compile(r'(\s|=|"|^)AP6\w{10,}'), # password
]
1 change: 1 addition & 0 deletions detect_secrets/plugins/common/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..keyword import KeywordDetector # noqa: F401
from ..private_key import PrivateKeyDetector # noqa: F401
from ..slack import SlackDetector # noqa: F401
from ..artifactory import ArtifactoryDetector # noqa: F401
KevinHock marked this conversation as resolved.
Show resolved Hide resolved
from detect_secrets.core.log import log
from detect_secrets.core.usage import PluginOptions

Expand Down
1 change: 1 addition & 0 deletions tests/core/usage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_consolidates_output_basic(self):
'PrivateKeyDetector': {},
'AWSKeyDetector': {},
'SlackDetector': {},
'ArtifactoryDetector': {},
}
assert not hasattr(args, 'no_private_key_scan')

Expand Down
14 changes: 14 additions & 0 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_scan_string_basic(
assert main('scan --string'.split()) == 0
assert uncolor(printer_shim.message) == textwrap.dedent("""
AWSKeyDetector : False
ArtifactoryDetector : False
Base64HighEntropyString: {}
BasicAuthDetector : False
HexHighEntropyString : {}
Expand All @@ -111,6 +112,7 @@ def test_scan_string_cli_overrides_stdin(self):
assert main('scan --string 012345'.split()) == 0
assert uncolor(printer_shim.message) == textwrap.dedent("""
AWSKeyDetector : False
ArtifactoryDetector : False
Base64HighEntropyString: False (2.585)
BasicAuthDetector : False
HexHighEntropyString : False (2.121)
Expand Down Expand Up @@ -232,6 +234,9 @@ def test_old_baseline_ignored_with_update_flag(
{
"name": "AWSKeyDetector",
},
{
"name": "ArtifactoryDetector",
},
{
"base64_limit": 1.5,
"name": "Base64HighEntropyString",
Expand Down Expand Up @@ -267,6 +272,9 @@ def test_old_baseline_ignored_with_update_flag(
{
"name": "AWSKeyDetector",
},
{
"name": "ArtifactoryDetector",
},
{
"name": "BasicAuthDetector",
},
Expand Down Expand Up @@ -351,6 +359,9 @@ def test_old_baseline_ignored_with_update_flag(
{
"name": "AWSKeyDetector",
},
{
"name": "ArtifactoryDetector",
},
{
"base64_limit": 5.5,
"name": "Base64HighEntropyString",
Expand Down Expand Up @@ -381,6 +392,9 @@ def test_old_baseline_ignored_with_update_flag(
{
"name": "AWSKeyDetector",
},
{
"name": "ArtifactoryDetector",
},
{
"base64_limit": 2.5,
"name": "Base64HighEntropyString",
Expand Down
37 changes: 37 additions & 0 deletions tests/plugins/artifactory_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import absolute_import

import pytest

from detect_secrets.plugins.artifactory import ArtifactoryDetector


class TestArtifactoryDetector(object):

@pytest.mark.parametrize(
'payload, should_flag',
[
('AP6xxxxxxxxxx', True),
('AKCxxxxxxxxxx', True),
(' AP6xxxxxxxxxx', True),
(' AKCxxxxxxxxxx', True),
('=AP6xxxxxxxxxx', True),
('=AKCxxxxxxxxxx', True),
('\"AP6xxxxxxxxxx\"', True),
('\"AKCxxxxxxxxxx\"', True),
('X-JFrog-Art-Api: AKCxxxxxxxxxx', True),
('X-JFrog-Art-Api: AP6xxxxxxxxxx', True),
('artifactoryx:_password=AKCxxxxxxxxxx', True),
('artifactoryx:_password=AP6xxxxxxxxxx', True),
('testAKCwithinsomeirrelevantstring', False),
('testAP6withinsomeirrelevantstring', False),
('X-JFrog-Art-Api: $API_KEY', False),
('X-JFrog-Art-Api: $PASSWORD', False),
('artifactory:_password=AP6xxxxxxxx', False),
('artifactory:_password=AKCxxxxxxxx', False),
],
)
def test_analyze_string(self, payload, should_flag):
logic = ArtifactoryDetector()

output = logic.analyze_string(payload, 1, 'mock_filename')
assert len(output) == int(should_flag)
3 changes: 3 additions & 0 deletions tests/pre_commit_hook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def test_that_baseline_gets_updated(
{
'name': 'AWSKeyDetector',
},
{
'name': 'ArtifactoryDetector',
},
{
'base64_limit': 4.5,
'name': 'Base64HighEntropyString',
Expand Down