Compare commits
1 Commits
TestProduc
...
TestDevelo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29621c8837 |
@ -29,11 +29,17 @@ SECRET = CONFIG.get("webhook_secret", "").encode()
|
||||
|
||||
|
||||
def verify_signature(payload: bytes, signature: str) -> bool:
|
||||
"""Verify Gitea webhook HMAC signature."""
|
||||
"""Verify Gitea webhook HMAC signature.
|
||||
|
||||
Gitea sends X-Gitea-Signature as a bare hex digest. GitHub-style senders
|
||||
prefix it with "sha256=". Accept either form — the HMAC comparison itself
|
||||
is unchanged, so this does not loosen verification.
|
||||
"""
|
||||
if not SECRET:
|
||||
return True # No secret configured — accept all
|
||||
expected = hmac.new(SECRET, payload, hashlib.sha256).hexdigest()
|
||||
return hmac.compare_digest(f"sha256={expected}", signature)
|
||||
provided = signature[len("sha256="):] if signature.startswith("sha256=") else signature
|
||||
return hmac.compare_digest(expected, provided)
|
||||
|
||||
|
||||
class WebhookHandler(BaseHTTPRequestHandler):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user