Compare commits

..

No commits in common. "TestDevelop" and "TestProduction" have entirely different histories.

View File

@ -29,17 +29,11 @@ SECRET = CONFIG.get("webhook_secret", "").encode()
def verify_signature(payload: bytes, signature: str) -> bool: 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: if not SECRET:
return True # No secret configured — accept all return True # No secret configured — accept all
expected = hmac.new(SECRET, payload, hashlib.sha256).hexdigest() expected = hmac.new(SECRET, payload, hashlib.sha256).hexdigest()
provided = signature[len("sha256="):] if signature.startswith("sha256=") else signature return hmac.compare_digest(f"sha256={expected}", signature)
return hmac.compare_digest(expected, provided)
class WebhookHandler(BaseHTTPRequestHandler): class WebhookHandler(BaseHTTPRequestHandler):