refactor(api): enhance donation creation with rate limiting, Zod validation, and secure logging

- Add rate limiting to prevent abuse on /api/donations/create endpoint
- Replace manual input validation with Zod schema for better error handling and type safety
- Switch from console.log to secureLogger to comply with LGPD and avoid exposing sensitive data
- Remove sensitive request body logging in AbacatePay client for improved security
This commit is contained in:
Evandro Fonseca Junior committed 2025-10-26 23:01:19 -03:00
1 parent bb6b320d1f
commit a1800227a7
11 files changed
+876 -138

No files matched your search

+12
View File
@@ -1,8 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { getPaymentStatus } from "@/lib/payment-cache";
import {
checkRateLimit,
getClientIP,
createRateLimitResponse,
} from "@/lib/rate-limiter";
export async function GET(request: NextRequest) {
try {
// Rate limiting
const ip = getClientIP(request);
const rateLimit = checkRateLimit(ip, "/api/donations/status");
if (!rateLimit.allowed) {
return createRateLimitResponse(rateLimit.resetAt);
}
const { searchParams } = new URL(request.url);
const pixId = searchParams.get("pixId");