Repository navigation
fix(security): harden the gateway, verify billing webhooks, keep bots alive on handler errors - #145
Merged
Merged
Conversation
… alive on handler errors
- gateway: validate frames before use, catch async handler errors, listen
for socket errors, and cap frames at 1 MiB (maxPayload option)
- billing: verify Stripe-Signature (stripeWebhookSecret) and Discord's
Ed25519 signature (discord({ publicKey })); refuse unverifiable webhooks
with 503 instead of accepting them; read Discord's ENTITLEMENT_* event
envelope and answer with 204; createDashboard gains discord.publicKey and
billing options
- sdk-js / sdk-py: a throwing handler answers with a JSON-RPC error instead
of crashing the bot or dropping the connection
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DTq83Lht42mpW1KQWJoXPH
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.
Requested by zVapor · project thread
What this changes
These are the three most serious findings from a security review of 3.1.0-beta.0.
Gateway (
packages/core/src/server/gateway/gateway.ts)helloparams to have stringbotId/nonceSig.errorlistener. ws reports broken frames (bad UTF-8, oversize) aserrorevents, which were uncaught.maxPayloadoption. ws's default is 100 MiB.Billing webhooks (
routes/billing.ts,platform-discord/billing.ts)/api/webhooks/stripeverifiesStripe-Signature: HMAC-SHA256 overt.rawBody, anyv1, 5 minute tolerance. Configured withstripeWebhookSecret/STRIPE_WEBHOOK_SECRET./api/webhooks/discordverifies Discord's Ed25519 signature (X-Signature-Ed25519over timestamp + raw body) with the app's public key:discord({ publicKey })/DISCORD_PUBLIC_KEY. It reads Discord's webhook event envelope (ENTITLEMENT_CREATE,_UPDATE,_DELETE, withends_atcarried asexpiresAt) and answers PING and events with an empty 204.PlatformBilling.verifyhook, so other platforms can plug in their own signature check.WEBHOOK_SECRET(thex-webhook-secretheader) remains as a fallback for your own relays when no platform signature is configured. It is never accepted in place of a configured Discord signature.createDashboardgainsdiscord.publicKeyandbilling: { stripeWebhookSecret, webhookSecret }, with env fallbacks. Before this, lite mode had no way to authenticate webhooks at all.Bot SDKs
sdk-js:handle()errors are caught. A throwing handler now answers the dashboard with a JSON-RPC error (-32603) instead of becoming an unhandled rejection that exits the bot process.sdk-py: same JSON-RPC error reply, instead of tearing down and reconnecting the socket. Non-object frames are skipped.Docs:
.env.example, theasctane-dashboardREADME and CHANGELOG.Why
Breaking for the beta: deployments that relied on unauthenticated webhooks must set
STRIPE_WEBHOOK_SECRET/DISCORD_PUBLIC_KEY(orWEBHOOK_SECRETfor a relay). The Discord webhook response is now 204 when the signature is verified.Not in this PR (follow-ups from the same review): server-side validation of role/channel picker values with a role-hierarchy check, declared and gated actions with payload schemas,
trustProxyfor rate limiting, and a Discord replay window.Checklist
gateway/hostile-frames.test.ts,webhook-signatures.test.ts, Discord billing signature/envelope tests, a lite-mode webhook test, a Python SDK error-reply test. The new gateway and SDK tests fail against the old code. Old tests that posted unsigned webhooks now send the shared secret or expect 503.pnpm lint,pnpm typecheck,pnpm test(283 passed),pytest(14 passed),pnpm build,pnpm smoke:pack(22 packages).Generated by Claude Code