Skip to content

Commit

Permalink
Catch Slack webhook with 10 char (Yelp#325)
Browse files Browse the repository at this point in the history
We were getting report that slack custom application webhook will contain a different foramt
for webhooks. In particualar the B+8 chars could become B+10 chars format

User reprot https://ibm-cio-gi.slack.com/archives/CDMGJ9QG2/p1591018601323500?thread_ts=1590777088.301300&cid=CDMGJ9QG2

We also noticed the response error message is differnet, this commit tried to address that issue and allow us to catch webhook for custom Slack applications
  • Loading branch information
XIANJUN ZHU authored and justineyster committed Jun 24, 2020
1 parent b6f7865 commit b8203c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions detect_secrets/plugins/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ class SlackDetector(RegexBasedDetector):
# Slack Webhooks
re.compile(
r"""
https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}
https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8,10}/[a-zA-Z0-9_]{24}
""",
flags=re.IGNORECASE | re.VERBOSE,
),
)

def verify(self, token, **kwargs): # pragma: no cover
def verify(self, token, *args, **kwargs): # pragma: no cover
if token.startswith('https://hooks.slack.com/services/T'):
response = requests.post(
token,
json={
'text': '',
},
)
valid = response.text == 'missing_text_or_fallback_or_attachments'
valid = (
response.text == 'missing_text_or_fallback_or_attachments'
or response.text == 'no_text'
)
else:
response = requests.post(
'https://slack.com/api/auth.test',
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/slack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class TestSlackDetector:
(
'https://hooks.slack.com/services/Txxxxxxxx/Bxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx'
),
(
'https://hooks.slack.com/services/Txxxxxxxx/Bxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx'
),
],
)
def test_analyze(self, file_content):
Expand Down

0 comments on commit b8203c8

Please sign in to comment.