Skip to content
Open
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
9 changes: 7 additions & 2 deletions python/runinfra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
import hmac
import math
import random
import re
import time
import uuid
Expand Down Expand Up @@ -789,7 +790,7 @@ def verify_webhook_signature(
if abs(current_time - timestamp) > tolerance_seconds:
raise WebhookVerificationError("Webhook signature timestamp is outside the allowed tolerance.")
expected = _webhook_expected_signature(_webhook_payload_bytes(payload), timestamp, secret)
if not any(hmac.compare_digest(expected, signature) for signature in signatures):
if not any(hmac.compare_digest(expected, signature.lower()) for signature in signatures):
raise WebhookVerificationError("Webhook signature verification failed.")
return True

Expand Down Expand Up @@ -1700,7 +1701,11 @@ def create(
idempotent_replay_safe=False,
request_options=request_options,
)
content_type = response.headers.get("content-type", response.headers.get("Content-Type", "application/octet-stream"))
content_type = "application/octet-stream"
for key, value in response.headers.items():
if key.lower() == "content-type":
content_type = value
break
request_id = _request_id_from_headers(response.headers)
return AudioResponse(response.body, content_type, request_id)

Expand Down
19 changes: 19 additions & 0 deletions python/tests/test_runinfra_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,25 @@ def test_construct_webhook_event_uses_secret_exactly(self):

self.assertEqual(event["id"], "evt_123")

def test_construct_webhook_event_accepts_uppercase_hex_signature(self):
payload = b'{"id":"evt_123","type":"deployment.verified"}'
timestamp = 1_700_000_000
secret = "whsec_test_123"
signature = hmac.new(
secret.encode("utf-8"),
str(timestamp).encode("utf-8") + b"." + payload,
hashlib.sha256,
).hexdigest().upper()

event = construct_webhook_event(
payload=payload,
signature_header=f"t={timestamp},v1={signature}",
secret=secret,
now=timestamp + 60,
)

self.assertEqual(event["id"], "evt_123")

def test_construct_webhook_event_rejects_trailing_odd_hex_nibbles(self):
payload = b'{"id":"evt_123","type":"deployment.verified"}'
timestamp = 1_700_000_000
Expand Down