Skip to content

Implement webhook middleware with HMAC validation and replay attack protection #847

Description

@Kingsman-99

Overview

Build Express/Next.js middleware for receiving StellarSplit invoice webhooks with HMAC-SHA256 signature verification, timestamp window validation, and nonce-based replay attack protection.

Requirements

  • createWebhookMiddleware(secret, options?) returns RequestHandler
  • WebhookOptions { toleranceSeconds, nonceWindowSize }
  • Verify X-StellarSplit-Signature header (HMAC-SHA256 of timestamp + body)
  • Reject requests outside toleranceSeconds window
  • Reject replayed nonces using in-memory LRU nonce cache
  • Typed event emitter: on(event: InvoiceEventType, handler)
  • Tests: valid webhook passes, expired timestamp rejected, replayed nonce rejected, tampered signature rejected

Acceptance Criteria

  • Middleware validates signatures correctly
  • Timestamp window enforced
  • Nonce replay rejected
  • Typed event handlers work
  • npm test passes with zero failures
  • TypeScript compiles with zero errors
  • ESLint passes with zero errors

Definition of Done

All CI checks must pass before the PR is reviewed.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions