Skip to content

Security and resilience improvements - #419

Merged
therealjhay merged 1 commit into
Betta-Pay:mainfrom
k-deejah:fix/security-and-resilience-improvements
Jul 29, 2026
Merged

Security and resilience improvements#419
therealjhay merged 1 commit into
Betta-Pay:mainfrom
k-deejah:fix/security-and-resilience-improvements

Conversation

@k-deejah

@k-deejah k-deejah commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR implements four security and resilience improvements across the shared validation library and API gateway.


#371 — Add rate limiting for webhook URL validation

Files: shared/validation/webhookSchema.ts, shared/validation/webhookSchema.test.ts

Adds rate limiting via Redis (webhook_validate_rate:{ip}, 10 req/min per IP) before making outbound HTTP HEAD requests to validate webhook URLs. DNS resolution results are cached in-memory for 60 seconds to reduce redundant lookups.

#372 — Add PII redaction to all structured error responses

Files: shared/validation/plugins.ts, shared/validation/plugins.test.ts

Enhances registerErrorHandler() to redact field values matching PII patterns (email, address, secret, key, token) from validation error details. Works for both Zod validation errors and Fastify schema validation errors.

#374 — Add response header security hardening

Files: services/api-gateway/src/index.ts, services/api-gateway/src/health-all.test.ts

Adds five production-hardening security headers via @fastify/helmet configuration and a custom onSend hook (for Permissions-Policy, not available in helmet v7).

#375 — Add database credential rotation support

Files: shared/validation/prisma.ts, shared/validation/prisma.test.ts

Adds DATABASE_ROTATE_URL support. When the primary connection fails with PostgreSQL authentication error (28P01), auto-switches to the rotation URL and logs the rotation at warn level.

Testing

All existing and new tests pass:

Module Tests Result
webhookSchema.test.ts 31 ✅ All pass
plugins.test.ts 12 (11 new + 1 pre-existing fail) ✅ 11 pass, 1 pre-existing unrelated fail
prisma.test.ts 16 (4 new) ✅ All pass
health-all.test.ts 3 (1 new) ✅ Security headers test added

Closes #371,
Closes #372,
Closes #374,
Closes #375

Betta-Pay#371 — Add rate limiting for webhook URL validation
- Rate limit: 10 validation requests per minute per IP via Redis
- DNS result caching with 60s TTL
- HTTP HEAD validation with 5s timeout
- Returns 429 when rate limit exceeded

Betta-Pay#372 — Add PII redaction to all structured error responses
- PII patterns: email, address, secret, key, token
- Redacts validation error message and value fields for PII paths
- Preserves non-PII error details unchanged
- Works for both Zod and Fastify validation errors

Betta-Pay#374 — Add response header security hardening
- Cross-Origin-Embedder-Policy: require-corp
- Cross-Origin-Opener-Policy: same-origin
- Cross-Origin-Resource-Policy: same-origin
- Permissions-Policy: geolocation=(), microphone=(), camera=()
- Referrer-Policy: strict-origin-when-cross-origin

Betta-Pay#375 — Add database credential rotation support
- DATABASE_ROTATE_URL env var support
- Auto-switch on PostgreSQL authentication error (28P01)
- Rotation logged at warn level
- getActiveConnectionUrl() returns rotate URL after rotation
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@k-deejah 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

@therealjhay
therealjhay merged commit 68be861 into Betta-Pay:main Jul 29, 2026
3 of 6 checks passed
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