Repository navigation
fix(security)!: sign the webhook delivery id and event, dedupe GitHub deliveries on the signed body - #694
Merged
Conversation
…iveries on the signed body (wip)
# Conflicts: # CHANGELOG.md
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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
A captured webhook delivery can no longer be replayed as a new delivery under a fresh id. Native deliveries now sign the delivery id and the event (scheme v2). GitHub deliveries, which sign only the body, are deduplicated on the signed body instead of the unsigned delivery header.
Why
#678 (audit of #594):
webhook::verifyreturned the id fromX-Tole-Delivery/X-GitHub-Delivery, and neither signature covered it. Idempotency (hook_seen) was keyed on that attacker-chosen id. So one captured request fired the route's cron job again under each new id:The
eventsallowlist also read unsigned headers.Changes
tole_core::webhook, native scheme:X-Tole-Signature: v2=<hex>, an HMAC-SHA256 overv2\n<timestamp>\n<delivery id>\n<event>\n<body>. The event is theX-Tole-Eventvalue, empty when the header is absent. The 300 s window is unchanged.[A-Za-z0-9._:-]and[A-Za-z0-9._-]), so neither contains a newline. An invalid event header is400(Reject::BadEvent).sha256=over<timestamp>.<body>) is refused with401(Reject::OutdatedScheme), with a reason naming the v2 form.tole_core::webhook, GitHub scheme: the idempotency key isgh:plus the SHA-256 of the body, the only signed material.tole_core::webhook, API:verifyreturnsVerified { key, delivery, event }.keyis what the ledger records;deliveryis the header id, used in answers and the run's context.signtakes the delivery id and the event.Headersgainsevent, which readsX-Tole-EventorX-GitHub-Event.tole serve:verified.key;eventslist;tole hook test --firesigns v2.automation-design.md§6, a README note onevents, and a BREAKING CHANGELOG entry with a migration note.Decisions to check
v2. Native senders must update;tole hook test --firealready signs v2.hook_seenretention, a capture verifies again, because GitHub signs no timestamp.X-GitHub-Eventstays unsigned, soeventsis a convenience for GitHub routes, not a boundary;filter(on the signed body) is the boundary.tole serveforallow_writesroutes.400before the signature is computed, because the id is part of the signed message. The status codes are unchanged.Testing
webhook_core::a_captured_delivery_cannot_be_replayed_under_a_new_id(the audit's reproduction):BadSignature.webhook_core::the_native_event_is_signed_and_the_fields_cannot_shift:.between the id and the event fails.BadEvent(400).webhook_core::a_v1_native_signature_is_refused_as_outdated.webhook_core,serve_hooks,serve_hook_fire,hook_cli).serve_hooks::a_signed_delivery_is_accepted_once_even_across_a_restartgains an end-to-end replay check against the realtole serve:200 duplicate;401.cargo fmt --all --check,cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo test --workspace,cargo test -p tole-core --no-default-features, the no-mcp CI profile, andcora review --no-llm --base origin/develop(no issues).Closes #678