Skip to content

Signature verification raises TypeError (HTTP 500) on non-ASCII signature headers #27

Closed

Description

@Nitjsefnie

Description

verify_hmac_sha256_signature (api/webhook_auth.py) compares two strs with hmac.compare_digest(expected, signature). Python's compare_digest only supports ASCII when given str arguments — a non-ASCII byte in the attacker-controlled signature header raises:

TypeError: comparing strings with non-ASCII characters is not supported

(reproduced on Python 3: hmac.compare_digest('sha256=abc', 'sha256=\xff\xfe')). HTTP headers are latin-1-decodable, so non-ASCII values are reachable from the wire. An unauthenticated request with a garbage signature header turns into an unhandled TypeError → HTTP 500 instead of a clean 401/403 on every endpoint that calls verify_webhook_request (github/alertmanager/manual webhooks), and the same pattern exists in verify_slack_signature's final compare.

Suggested fix

Either compare bytes (hmac.compare_digest(expected.encode(), signature.encode('latin-1', 'ignore'))-style after validation), or guard the compare with a try/except TypeError: return False. One or two lines in verify_hmac_sha256_signature and verify_slack_signature.

Note

This was first spotted during the PR #24 work (the pre-consolidation verify_github_signature had the same flaw); re-verified today against current main after the webhook_auth.py refactor — it carried over.

Happy to submit a PR with the fix + regression tests once your develop-branch migration and #20 consolidation settle — just say the word.

Filed with AI assistance (Claude); the TypeError was reproduced by execution before filing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions