security(webhooks): fail closed when no HMAC secret (closes #99)#120
Merged
Conversation
verify_signature() previously returned True for a webhook with no
hmac_secret ("open mode"). create() auto-mints a secret, but a
hand-written / migrated config (or one whose secret was cleared on disk)
was silently unauthenticated — anonymous POSTs could spawn an AI
assistant with tool access.
- verify_signature now FAILS CLOSED (returns False, logs why) when no
secret is configured.
- KC_ALLOW_UNSIGNED_WEBHOOKS=1 is an explicit opt-in for local/testing.
- _public_view exposes an `unsigned` flag so the dashboard can warn that
a webhook is secret-less and will reject POSTs.
The update path already preserves the prior secret, so normal edits
can't clear it; this closes the hand-edited-config gap.
Tests (tests/server_test.py): fail-closed without secret, open-mode
opt-in, env parsing, and the public-view unsigned flag (webhook suite
18 -> 22). Full suite 470, OK.
Closes #99
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes webhook signature verification fail closed when no HMAC secret is configured. Closes #99 — PR 2 of the reliability-hardening series. (Security)
Why
verify_signature()returnedTruefor a webhook with nohmac_secret("open mode").create()auto-mints a secret, but a hand-written / migrated config — or one whose secret was cleared directly on disk — was silently unauthenticated, so anonymous POSTs could spawn an AI assistant with tool access. That's an RCE-adjacent exposure.Changes
verify_signaturenow fails closed (returnsFalse, logs the reason) when no secret is set.KC_ALLOW_UNSIGNED_WEBHOOKS=1— explicit opt-in to restore open mode for local/testing (off by default)._public_viewexposes anunsignedflag so the dashboard can warn that a webhook is secret-less and will reject POSTs.The update path already preserves the prior secret, so a normal edit can't clear it — this specifically closes the hand-edited-config / migration gap.
Tests
tests/server_test.py: fail-closed without secret, open-mode opt-in,KC_ALLOW_UNSIGNED_WEBHOOKSparsing, and the public-viewunsignedflag (webhook suite 18 → 22). Full Python suite 470, OK.Closes #99
🤖 Generated with Claude Code