The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webhook): authenticate Linear deliveries via linear-signature HMAC (#87348)
liuhao1024f13f3401a16b
diff --git a/gateway/platforms/webhook.py b/gateway/platforms/webhook.pyindex 7997160008f..bc3ebe0968e 100644--- a/gateway/platforms/webhook.py+++ b/gateway/platforms/webhook.py@@ -1066,7 +1066,7 @@ class WebhookAdapter(BasePlatformAdapter):def _validate_signature(self, request: "web.Request", body: bytes, secret: str) -> bool:- """Validate webhook signature (GitHub, GitLab, Svix, generic HMAC-SHA256)."""+ """Validate webhook signature (GitHub, GitLab, Svix, Linear, generic HMAC-SHA256)."""def _header(name: str) -> str:return (request.headers.get(name, "")@@ -1092,6 +1092,18 @@ class WebhookAdapter(BasePlatformAdapter):signature_header=svix_signature,)+ # Linear: linear-signature = <hex HMAC-SHA256 of the raw body, keyed+ # by the webhook signing key>. Linear's documented scheme signs the+ # body only (no timestamp binding), so this mirrors it exactly;+ # without this branch every Linear delivery to a secret-configured+ # route was rejected as unrecognized (#87348).+ linear_sig = _header("linear-signature")+ if linear_sig:+ expected_linear = hmac.new(+ secret.encode(), body, hashlib.sha256+ ).hexdigest()+ return _hmac_str_equal(linear_sig, expected_linear)+# GitHub: X-Hub-Signature-256 = sha256=<hex>gh_sig = request.headers.get("X-Hub-Signature-256", "")if gh_sig:diff --git a/tests/gateway/test_webhook_adapter.py b/tests/gateway/test_webhook_adapter.pyindex f82fe6af2b8..4f5cdb13900 100644--- a/tests/gateway/test_webhook_adapter.py+++ b/tests/gateway/test_webhook_adapter.py@@ -149,11 +149,33 @@ class TestValidateSignature:"X-Hub-Signature-256","X-Gitlab-Token","X-Webhook-Signature",+ "linear-signature",):req = _mock_request(headers={header: hostile})# Must return False, never raise.assert adapter._validate_signature(req, body, secret) is False+ def test_linear_signature_valid_accepts(self):+ """Linear signs the raw body (hex HMAC-SHA256) in linear-signature."""+ adapter = _make_adapter()+ body = b'{"type": "Issue", "data": {"id": "abc"}}'+ secret = "linear-webhook-key"+ sig = _generic_signature(body, secret) # same math as linear-signature++ req = _mock_request(headers={"linear-signature": sig})++ assert adapter._validate_signature(req, body, secret) is True++ def test_linear_signature_mismatch_rejects(self):+ """A well-formed linear-signature computed with the wrong key fails closed."""+ adapter = _make_adapter()+ body = b'{"type": "Issue"}'+ sig = _generic_signature(body, "attacker-controlled-key")++ req = _mock_request(headers={"linear-signature": sig})++ assert adapter._validate_signature(req, body, "real-secret") is False+def test_non_ascii_svix_signature_rejected(self):"""The Svix branch also runs its `v1,<sig>` comparison through the