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:
1 parent
bb6b320d1f
commit
a1800227a7
11 files changed
+876
-138
No files matched your search
+6
-21
@@ -57,7 +57,8 @@ class AbacatePayClient {
|
||||
requestBody.customer = params.customer;
|
||||
}
|
||||
|
||||
console.log("🔍 PIX Request:", JSON.stringify(requestBody, null, 2));
|
||||
// Request body logging removido para segurança LGPD
|
||||
// Dados sensíveis não devem aparecer em logs
|
||||
|
||||
const response = await fetch(`${this.config.baseUrl}/pixQrCode/create`, {
|
||||
method: "POST",
|
||||
@@ -68,16 +69,13 @@ class AbacatePayClient {
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
console.log("🔍 PIX Response Status:", response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
console.error("🔍 PIX Error:", errorData);
|
||||
console.error("PIX Error:", errorData);
|
||||
throw new Error(`Failed to create PIX: ${JSON.stringify(errorData)}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log("🔍 PIX Success:", result);
|
||||
|
||||
if (result.error) {
|
||||
throw new Error(result.error);
|
||||
@@ -177,20 +175,10 @@ const apiKey = isProduction
|
||||
? process.env.ABACATE_APIKEY || "demo_key"
|
||||
: process.env.ABACATE_TEST_APIKEY || "demo_key";
|
||||
|
||||
// Log completo das variáveis de ambiente configuradas
|
||||
console.log("\n🔧 ==========================================");
|
||||
console.log("🔧 VARIÁVEIS DE AMBIENTE DO ABACATEPAY");
|
||||
console.log("🔧 ==========================================");
|
||||
console.log(`📊 NODE_ENV: ${process.env.NODE_ENV || "não definido"}`);
|
||||
// Log das variáveis de ambiente (sem expor valores sensíveis)
|
||||
console.log("\n🔧 Configuração do AbacatePay:");
|
||||
console.log(`📊 Environment: ${isProduction ? "PRODUCTION" : "TEST"}`);
|
||||
console.log(
|
||||
`📊 API Key: ${apiKey ? "✅ Configurada (masqueada)" : "❌ NÃO CONFIGURADA"}`
|
||||
);
|
||||
console.log(
|
||||
`📊 API Key preview: ${
|
||||
apiKey ? apiKey.substring(0, 10) + "..." : "não definida"
|
||||
}`
|
||||
);
|
||||
console.log(`📊 API Key: ${apiKey ? "✅ Configurada" : "❌ NÃO CONFIGURADA"}`);
|
||||
console.log(
|
||||
`📊 Webhook Secret: ${
|
||||
process.env.ABACATEPAY_WEBHOOK_SECRET
|
||||
@@ -198,9 +186,6 @@ console.log(
|
||||
: "❌ NÃO CONFIGURADA"
|
||||
}`
|
||||
);
|
||||
console.log(
|
||||
`📊 Base URL: ${process.env.NEXT_PUBLIC_BASE_URL || "não definido"}`
|
||||
);
|
||||
console.log("🔧 ==========================================\n");
|
||||
|
||||
export const abacatePay = new AbacatePayClient({
|
||||
|
||||
Reference in new issue
Block a user