File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -89,15 +89,15 @@ def event():
89
89
# Each request comes with request timestamp and request signature
90
90
# emit an error if the timestamp is out of range
91
91
req_timestamp = request .headers .get ('X-Slack-Request-Timestamp' )
92
- if abs (time () - int (req_timestamp )) > 60 * 5 :
92
+ if req_timestamp is None or abs (time () - int (req_timestamp )) > 60 * 5 :
93
93
slack_exception = SlackEventAdapterException ('Invalid request timestamp' )
94
94
self .emitter .emit ('error' , slack_exception )
95
95
return make_response ("" , 403 )
96
96
97
97
# Verify the request signature using the app's signing secret
98
98
# emit an error if the signature can't be verified
99
99
req_signature = request .headers .get ('X-Slack-Signature' )
100
- if not self .verify_signature (req_timestamp , req_signature ):
100
+ if req_signature is None or not self .verify_signature (req_timestamp , req_signature ):
101
101
slack_exception = SlackEventAdapterException ('Invalid request signature' )
102
102
self .emitter .emit ('error' , slack_exception )
103
103
return make_response ("" , 403 )
Original file line number Diff line number Diff line change @@ -56,6 +56,32 @@ def test_url_challenge(client):
56
56
assert bytes .decode (res .data ) == "valid_challenge_token"
57
57
58
58
59
+ def test_no_request_timestamp_header (client ):
60
+ data = pytest .reaction_event_fixture
61
+ with pytest .raises (SlackEventAdapterException ) as excinfo :
62
+ res = client .post (
63
+ '/slack/events' ,
64
+ data = data ,
65
+ content_type = 'application/json' ,
66
+ headers = {}
67
+ )
68
+ assert str (excinfo .value ) == 'Invalid request timestamp'
69
+
70
+ def test_no_request_signature_header (client ):
71
+ data = pytest .reaction_event_fixture
72
+ timestamp = int (time .time ())
73
+ with pytest .raises (SlackEventAdapterException ) as excinfo :
74
+ res = client .post (
75
+ '/slack/events' ,
76
+ data = data ,
77
+ content_type = 'application/json' ,
78
+ headers = {
79
+ 'X-Slack-Request-Timestamp' : timestamp , # valid
80
+ }
81
+ )
82
+ assert str (excinfo .value ) == 'Invalid request signature'
83
+
84
+
59
85
def test_invalid_request_signature (client ):
60
86
# Verify [package metadata header is set
61
87
slack_adapter = SlackEventAdapter ("SIGNING_SECRET" )
You can’t perform that action at this time.
0 commit comments