From 9629367bc2971d57722e1199c3ee6f992029d0f2 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 5 Apr 2026 15:40:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(webhook):=20Gitea=20=E7=B0=BD=E7=AB=A0?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=AD=A3=20=E2=80=94=20=E7=B4=94=20?= =?UTF-8?q?hex=EF=BC=8C=E7=84=A1=20sha256=3D=20=E5=89=8D=E7=B6=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea X-Gitea-Signature 送出純 hex(與 GitHub X-Hub-Signature-256 不同) - router: 兩種格式皆接受(向後相容) - tests: generate_signature 改為純 hex(符合 Gitea 實際行為) Co-Authored-By: Claude Sonnet 4.6 --- apps/api/tests/test_gitea_webhook.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/api/tests/test_gitea_webhook.py b/apps/api/tests/test_gitea_webhook.py index f158804c..4e2f2859 100644 --- a/apps/api/tests/test_gitea_webhook.py +++ b/apps/api/tests/test_gitea_webhook.py @@ -138,13 +138,16 @@ def ping_payload(): def generate_signature(secret: str, body: bytes) -> str: - """生成 Gitea Webhook 簽章 (X-Gitea-Signature)""" - signature = hmac.new( + """生成 Gitea Webhook 簽章 (X-Gitea-Signature) + + Gitea 送出純 hex(無 sha256= 前綴),與 GitHub 不同。 + 2026-04-05 ogt: 修正為純 hex 格式 + """ + return hmac.new( secret.encode(), body, hashlib.sha256, ).hexdigest() - return f"sha256={signature}" def prepare_request(secret: str, payload: dict) -> tuple[bytes, str]: