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

Create plugin to detect Twilio API keys. #267

Merged
merged 4 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ 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`

* **RegexBasedDetector**: checks for any keys matching certain regular expressions (Artifactory, AWS, Slack, Stripe, Mailchimp).
* **RegexBasedDetector**: checks for any keys matching certain regular expressions (Artifactory, AWS, Slack, Stripe, Mailchimp, Twilio).

* **JwtTokenDetector**: checks for formally correct JWTs.

Expand Down
24 changes: 24 additions & 0 deletions detect_secrets/plugins/twilio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
This plugin searches for Twilio API keys
"""
from __future__ import absolute_import

import re

import requests

from .base import RegexBasedDetector
from detect_secrets.core.constants import VerifiedResult


class TwilioKeyDetector(RegexBasedDetector):
"""Scans for Twilio API keys."""
secret_type = 'Twilio API Key'

denylist = [
# Account SID (ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
re.compile(r'AC[a-z0-9]{32}'),

# Auth token (SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
re.compile(r'SK[a-z0-9]{32}'),
]
28 changes: 28 additions & 0 deletions tests/plugins/twilio_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import absolute_import

import pytest

from detect_secrets.plugins.twilio import TwilioKeyDetector


class TestTwilioKeyDetector(object):

@pytest.mark.parametrize(
'payload, should_flag',
[
(
'SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
True
),
(
'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
True
),
],
)

def test_analyze(self, payload, should_flag):
logic = TwilioKeyDetector()

output = logic.analyze_line(payload, 1, 'mock_filename')
assert len(output) == int(should_flag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably can just do:

assert output

as that will make sure that it is a non-empty dictionary.