Repository navigation
fix: deliver webhook events, authenticate notification channels, settle before modify_rate - #1931
Merged
K1NGD4VID merged 5 commits intoNov 24, 2026
Conversation
dispatchWebhookEvent was exported and never called. Users could create a subscription and the test ping arrived, while no production stream event ever did: the worker broadcast SSE only, and the runway worker's comment promised "SSE and webhooks" while calling SSE alone (LabsCrypt#1854). Both fan-outs now live in one method, so an event type cannot be added to one and forgotten in the other. Subscribers are the stream's recipient and sender; a failed delivery is logged and recorded as a delivery attempt, never rethrown, because a dead endpoint must not turn a processed chain event into a retry. The low-balance alert dispatches the same way.
The notification router trusted the client. POST /link-code took req.body.address, generated the verification code with Math.random() and returned that code in the response, so anyone could mint a code for any wallet, read it from their own HTTP response, and attach their own Telegram chat to a stranger's stream notifications. linkTelegram, setDiscordWebhook and the web-push endpoints trusted the body the same way (LabsCrypt#1855). Every route now requires a session, and the address is the session's; a body that names another wallet is refused with 403 rather than ignored. Codes come from crypto.randomBytes (10 hex characters instead of ~31 predictable bits) and are no longer echoed back - the caller gets the address and expiry. Tests assert the code shape and that two codes differ.
…chor modify_rate set rate and last_update_time with no settlement, contradicting the rationale top_up_stream documents: last_update_time is the accrual anchor, and advancing it discards everything already vested but unwithdrawn. A recipient had to re-accrue tokens they had already earned, and a sender could call this with rate 1 to defer vested wages arbitrarily (LabsCrypt#1862). The vested interval is now paid out at the old rate before the anchor moves. It is a real withdrawal rather than a bookkeeping credit: claimable is elapsed*rate clamped to deposited-withdrawn, so crediting withdrawn_amount without paying would delete the tokens. The payout reuses apply_withdrawal (state committed before transfer) and emits TokensWithdrawn, the event the backend indexer books withdrawals from, so the off-chain figure cannot drift. Three tests: paid-before-change with continuity across the change, nothing taken when nothing vested, and a paused stream settling only up to its pause.
Every handler on this router authenticates a wallet and then writes a per-wallet record, which CodeQL flags as authorization without rate limiting. Apply the shared express-rate-limit factory to the whole router so a flood is rejected before any work happens.
king-daveed
force-pushed
the
fix/webhook-fanout-notification-auth
branch
from
November 24, 2026 14:45
13bbaeb to
4a1253c
Compare
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.
Three separate defects: webhooks that were configured but never fired, a
notification channel flow that trusted the client, and a rate change that
discarded vested tokens.
Closes #1854
Closes #1855
Closes #1862
#1854 — webhooks now fire
dispatchWebhookEventwas exported and never called. A user could create asubscription and get the test ping, and then never hear from the product again:
the indexer broadcast SSE only, and the runway worker's comment said "SSE and
webhooks" while calling SSE alone.
Both fan-outs now happen in one method,
publishStreamEvent, which everystream.*broadcast goes through — so a new event type cannot be added to oneand forgotten in the other. Subscribers are the stream's recipient and sender,
resolved from the row rather than from the event body.
Failure handling: a dead endpoint must not turn a processed chain event into a
retry, so the webhook leg logs and returns; the delivery attempt it records is
what surfaces the failure. The low-balance alert dispatches the same way.
#1855 — notification channel routes are bound to the session
POST /link-codetookreq.body.address, generated the code withMath.random()(~31 bits from a non-cryptographic PRNG whose stream isreproducible from a few outputs) and returned that code in the response — so the
second factor was in the first response. Anyone could mint a code for any
wallet, read it back, and attach their own Telegram chat to a stranger's stream
notifications.
linkTelegram,setDiscordWebhook,/subscribeand/unsubscribetrusted the body the same way.requireAuth.publicKey. A body that names a different walletgets 403 rather than being silently overridden, so a confused client learns.
crypto.randomBytes(5)→ 10 uppercase hex characters, and areno longer echoed; the response carries the address and expiry only.
The router is still not mounted in
app.ts; that is a separate decision aboutwhether the feature ships. The point of this change is that it is no longer
exploitable the moment someone does mount it.
#1862 —
modify_ratesettles before it moves the anchormodify_ratesetrate_per_secondandlast_update_timewith no settlement,contradicting the rationale
top_up_streamdocuments in the same file:last_update_timeis the accrual anchor, and advancing it throws awayeverything already vested but unwithdrawn. The recipient had to wait for the new
rate to re-accrue tokens that were already theirs; a sender could call
modify_rate(1)to defer vested wages arbitrarily.The vested interval is paid out at the old rate before the anchor moves.
It is a real withdrawal, not a bookkeeping credit:
calculate_claimableiselapsed * rateclamped todeposited - withdrawn, so creditingwithdrawn_amountwithout paying would silently delete the tokens rather thanpreserve them — the opposite of the issue. The payout reuses
apply_withdrawal(state committed before the transfer) and emits
TokensWithdrawn, which is whatthe backend indexer books withdrawals from, so the off-chain
withdrawnAmountcannot drift away from the chain.
Tests
cargo test -p stream_contract— 278 passed, 1 ignoredrate 1, then 50s at rate 2 adds exactly 100 more), nothing taken when nothing
has vested, and a paused stream settling only up to its pause point.
vitestonnotification.service.test.ts,soroban-event-worker.test.ts,webhook-delivery.test.ts— 39 passed^[0-9A-F]{10}$and twocodes for the same wallet differ.
tsc --noEmiton the backend — cleanNot included
#802(withdrawnAmount incremented before the dedup guard) is already fixed onmain, and already has the replay regression test atsoroban-event-worker.test.ts:457. I did not touch it or claim it.