Improve security by adding request signing#34
Conversation
README.rst
Outdated
|
|
||
|
|
||
| slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, endpoint="/slack/events") | ||
| slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, endpoint="/slack_events") |
There was a problem hiding this comment.
hmm...why the move from /slack/events to slack_events?
| # Initialize the Slack event server | ||
| # If no endpoint is provided, default to listening on '/slack/events' | ||
| def __init__(self, verification_token, endpoint="/slack/events", server=None): | ||
| def __init__(self, signing_secret, endpoint="/slack/events", server=None, **kwargs): |
There was a problem hiding this comment.
Is this **kwargs used now that we aren't using any optional flags?
slackeventsapi/server.py
Outdated
| # Each request comes with request timestamp and request signature | ||
| # emit an error if the timestamp is out of range | ||
| req_timestamp = request.headers.get('X-Slack-Request-Timestamp') | ||
| if abs(time() - int(req_timestamp)) > 60 * 10: |
There was a problem hiding this comment.
Should this be 60 * 5? In the docs, we say to make sure the request is no longer than 5 mins (https://api.slack.com/docs/verifying-requests-from-slack#how_to_make_a_request_signature_in_4_easy_steps__an_overview)
slackeventsapi/server.py
Outdated
| req_timestamp = request.headers.get('X-Slack-Request-Timestamp') | ||
| if abs(time() - int(req_timestamp)) > 60 * 10: | ||
| self.emitter.emit('error', Exception('Request timestamp invalid')) | ||
| return make_response("", 200) |
There was a problem hiding this comment.
500 or 404 status code instead of 200?
slackeventsapi/server.py
Outdated
| req_signature = request.headers.get('X-Slack-Signature') | ||
| if not self.verify_signature(req_timestamp, req_signature): | ||
| self.emitter.emit('error', Exception('invalid request signature')) | ||
| return make_response("", 200) |
slackeventsapi/server.py
Outdated
|
|
||
| # Echo the URL verification challenge code | ||
| # Echo the URL verification challenge code back to Slack | ||
| if "challenge" in event_data: |
There was a problem hiding this comment.
It might make sense to move this to after the request signature verification, since we aren't verifying the token in the request body anymore.
example/README.rst
Outdated
| .. image:: https://cloud.githubusercontent.com/assets/32463/24877833/950dd53c-1de5-11e7-984f-deb26e8b9482.png | ||
|
|
||
| Add your app's **Verification Token** to your python environmental variables | ||
| Add your app's **Singing Secret** to your python environmental variables |
There was a problem hiding this comment.
Spelling. Singing -> Signing.
There was a problem hiding this comment.
__
_ ,___,-'",-=-.
__,-- _ _,-'_)_ (""`'-._\ `.
_,' __ |,' ,-' __) ,- /. |
,'_,--' | -' _)/ `\
,',' ,' ,-'_,` :
,' ,-' ,(,-( :
,' ,-' , _ ;
/ ,-._/`---' /
/ (____)(----. ) ,'
/ ( `.__, /\ /,
: ;-.___ /__\/|
| ,' `--. -,\ |
: / \ .__/
\ (__ \ |_
\ ,`-, * / _|,\
\ ,' `-. ,'_,-' \
(_\,-' ,'\")--,'-' __\
\ / // ,'| ,--' `-.
`-. `-/ \' | _,' `.
`-._ / `--'/ \
,' | \
/ | \
,-' | /
/ | -'
slackeventsapi/server.py
Outdated
| req_signature = request.headers.get('X-Slack-Signature') | ||
| if not self.verify_signature(req_timestamp, req_signature): | ||
| self.emitter.emit('error', Exception('invalid request signature')) | ||
| return make_response("", 200) |
tests/test_server.py
Outdated
| } | ||
| ) | ||
|
|
||
| assert res.status_code == 404 |
slackeventsapi/server.py
Outdated
| # emit an error if the timestamp is out of range | ||
| req_timestamp = request.headers.get('X-Slack-Request-Timestamp') | ||
| if abs(time() - int(req_timestamp)) > 60 * 5: | ||
| slack_exception = Exception('Invalid request timestamp') |
slackeventsapi/server.py
Outdated
| # emit an error if the signature can't be verified | ||
| req_signature = request.headers.get('X-Slack-Signature') | ||
| if not self.verify_signature(req_timestamp, req_signature): | ||
| slack_exception = Exception('Invalid request signature') |
…ack-events-api into roach/request-signing
whitespace
…ack-events-api into roach/request-signing
Summary
Replaces request token verification with request signing.
See https://api.slack.com/docs/verifying-requests-from-slack for more info.
Fixes #33
Tests are still in progress.
Requirements (place an
xin each[ ])