Skip to content

feat: add webhook secret rotation, prisma query scrubbing utilities, … - #1317

Merged
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
Agbelomo:migrations
Sep 25, 2026
Merged

nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
Agbelomo:migrations

Conversation

@Agbelomo

Copy link
Copy Markdown
Contributor

Summary

Resolves multiple security, webhook reliability, and database migration issues across the backend:


Changes by Issue

1. Database & Security (#1252)

  • Added and exported scrubQuery(query: string): string in src/database/prisma.service.ts to redact literals, emails, IPs, phone numbers, and $n placeholders.
  • Query logger checks VERBOSE_QUERY_LOGGING / ENABLE_QUERY_LOGGING before emitting non-slow queries in non-production.
  • Added comprehensive unit tests with PII fixtures in src/database/prisma.service.spec.ts.

2. Webhook Secret Rotation (#1255)

  • Added rotateSecret(id, userId) in src/webhooks/webhooks.service.ts and POST /webhooks/:id/rotate-secret in src/webhooks/webhooks.controller.ts.
  • Rotation persists a WEBHOOK_SECRET_ROTATED audit record in ActivityLog.
  • Retries and subsequent deliveries fetch the updated secret from the database, invalidating the old secret immediately.
  • Added E2E tests in test/e2e/webhooks.e2e.spec.ts asserting self-service rotation, audit trail creation, and rejection of old signatures.

3. Webhook Retry Backoff & Idempotency (#1256)

  • Implemented 0-based mapping for RETRY_DELAYS_MS ([1000, 5000, 15000, 60000, 300000]) in src/webhooks/webhooks.service.ts.
  • Included X-Webhook-Idempotency-Key and X-Webhook-Event-Id headers in webhook delivery requests.
  • Reused delivery records during retries in retryFailedDeliveries.
  • Added daily @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT) task pruneOldDeliveryLogs(30) to purge expired logs.
  • Documented full retry semantics, headers, and lifecycle in docs/WEBHOOKS.md.
  • Added unit and E2E coverage for retry delay calculation and header presence.

4. Prisma Migrations & CI Alignment (#1257)

  • Converted 7 loose .sql files into valid migration directories:
    • 001_add_export_jobs/migration.sql
    • 20260330000000_add_seo_and_soft_delete_fields/migration.sql
    • 20260422000000_add_auth_security_foundation/migration.sql
    • 20260422170000_add_session_management/migration.sql
    • 20260422180000_add_trust_score/migration.sql
    • 20260423000000_add_api_key_permissions_and_usage/migration.sql
    • 20260424000000_add_document_features/migration.sql
  • Removed all loose .sql files from the root of prisma/migrations/.
  • Updated Property model in prisma/schema.prisma with metaTitle, metaDescription, metaKeywords, and @map("is_deleted").
  • Updated .github/workflows/ci.yml test database step from npx prisma db push --skip-generate --accept-data-loss to npx prisma migrate deploy.

Closes Issues

@drips-wave

drips-wave Bot commented Sep 25, 2026

Copy link
Copy Markdown

@Agbelomo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit 2f543ea into MettaChain:main Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants