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

Add a plugin for SendGrid #463

Merged
merged 1 commit into from
Aug 1, 2021
Merged
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
17 changes: 17 additions & 0 deletions detect_secrets/plugins/sendgrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
This plugin searches for SendGrid API keys
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector


class SendGridDetector(RegexBasedDetector):
"""Scans for SendGrid API keys."""
secret_type = 'SendGrid API key'

denylist = [
# SendGrid API key
# ref. https://d2w67tjf43xwdp.cloudfront.net/Classroom/Basics/API/what_is_my_api_key.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case https://d2w67tjf43xwdp.cloudfront.net looks odd to someone reading this, I tried Google-foo'ing and got the same.

https://docs.sendgrid.com/ui/account-and-settings/api-keys doesn't give an example.

re.compile(r'SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}'),
]
20 changes: 20 additions & 0 deletions tests/plugins/sendgrid_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from detect_secrets.plugins.sendgrid import SendGridDetector


class TestSendGridDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('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', True),
('SG.ngeVfQFYQlKU0ufo8x5d1A..TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
('AG.ngeVfQFYQlKU0ufo8x5d1A.TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
('foo', False),
],
)
def test_analyze(self, payload, should_flag):
logic = SendGridDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)
assert len(output) == int(should_flag)