Skip to content

fix(webhooks): fail-closed Yapeal key check + drop Alchemy cache log line#3873

Draft
TaprootFreak wants to merge 1 commit into
developfrom
fix/webhook-auth-hardening
Draft

fix(webhooks): fail-closed Yapeal key check + drop Alchemy cache log line#3873
TaprootFreak wants to merge 1 commit into
developfrom
fix/webhook-auth-hardening

Conversation

@TaprootFreak

Copy link
Copy Markdown
Collaborator

Hintergrund

Zwei Medium-Findings aus dem branch-weiten Security-Review, beide an anonym erreichbaren Webhook-Endpoints.

1. Yapeal-Webhook fail-open → fail-closed

bank/yapeal/webhook (yapeal-webhook.controller.ts) prüft einen x-api-key-Header. validateApiKey kehrte bei fehlendem erwarteten Key vorzeitig zurück (if (!expectedKey) return;) und akzeptierte damit jeden unauthentifizierten Request — auf einem Endpoint, der Bank-Zahlungseingänge als erhalten markiert (processWebhook). Verstösst gegen die No-Fallbacks-Regel.

Fix: Fail-closed — ein fehlender erwarteter Key lehnt jetzt jeden Request ab. Verifiziert: YAPEAL_WEBHOOK_API_KEY ist auf DEV und PRD gesetzt, die strengere Prüfung trifft also keine Umgebung.

2. Alchemy-Webhook: Cache-Log-Zeile entfernt

alchemy-webhook.service.ts isValidWebhookSignature loggte bei unbekannter webhookId Webhook cache: ${JSON.stringify(this.webhookCache)}.

Klarstellung zum Review: Die Zeile leakt die Signing-Keys aktuell nichtJSON.stringify eines Map ergibt {}, die Map-Einträge werden nicht serialisiert (per node verifiziert). Sie ist aber (a) anonym auslösbares, nutzloses Log-Rauschen und (b) ein latenter Secret-Leak, falls der Cache-Typ je auf ein Plain-Object umgestellt wird. Daher entfernt; die webhookId has no signing key-Warnung (kein Secret) bleibt.

Tests

Neuer YapealWebhookController-Spec: korrekter Key → verarbeitet, falscher Key → ForbiddenException, kein Key konfiguriert → lehnt jeden Request ab (fail-closed). format:check, type-check, lint sauber; Yapeal-Spec 3/3 grün.

Teil des Security-Backlogs; verbleibend: Lightning-Sign-in-Bypass bei leerer Signatur, SDK x-kyc-code ohne Origin-Check.

…line

Two anonymous webhook endpoints, hardened:

- Yapeal (bank/yapeal/webhook): validateApiKey returned early when no
  expected key was configured, accepting every unauthenticated request
  on an endpoint that marks bank payments as received. Fail closed: a
  missing expected key now rejects every request. Both DEV and PRD have
  the key set, so no environment is affected by the stricter check.

- Alchemy (isValidWebhookSignature): dropped the
  'Webhook cache: ${JSON.stringify(this.webhookCache)}' line. It is
  anonymously triggerable log noise (always prints {} since a Map does
  not JSON-serialize its entries) and a latent secret leak if the cache
  type ever changes to a plain object. The webhookId warn stays.

Added a YapealWebhookController spec covering match / wrong-key /
fail-closed-when-unconfigured.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant