Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

fix(security): stop leaking login OTPs and pairing codes

Abhi Pareek36ae12ad2f45
diff --git a/apps/payment-api/src/routes/customer.routes.js b/apps/payment-api/src/routes/customer.routes.js
index 9aa0e30..9c54e28 100644
--- a/apps/payment-api/src/routes/customer.routes.js
+++ b/apps/payment-api/src/routes/customer.routes.js
@@ -1,3 +1,4 @@
+import crypto from 'node:crypto';
import { HttpServer } from '../server.js';
import { normalizeEmail, normalizeMobile, isValidEmail, isValidMobile, isValidPassword } from '@youpi/common';
@@ -112,7 +113,7 @@ export function registerCustomerRoutes(server, ctx) {
}
// Generate 6-digit cryptographic OTP
- const otpCode = Math.floor(100000 + Math.random() * 900000).toString();
+ const otpCode = crypto.randomInt(100000, 1000000).toString();
const expiresAt = new Date(Date.now() + 5 * 60 * 1000).toISOString();
if (existingUser) {
@@ -138,17 +139,18 @@ export function registerCustomerRoutes(server, ctx) {
console.warn(`[CustomerAuth] WhatsApp dispatch notice: ${err.message}`);
}
} else {
- console.log(`[CustomerAuth] Berry service not loaded. Simulated OTP for ${cleanMobile}: ${otpCode}`);
+ console.log(`[CustomerAuth] Berry service not loaded; OTP for ${cleanMobile} was not delivered.`);
}
- console.log(`[CustomerAuth] OTP generated for +91${cleanMobile}: ${otpCode} (Expires: 5 mins)`);
+ console.log(`[CustomerAuth] OTP generated for +91${cleanMobile} (expires in 5 mins)`);
HttpServer.json(res, 200, {
success: true,
message: 'OTP sent to your WhatsApp number.',
mobileNumber: cleanMobile,
expiresInSeconds: 300,
- devOtp: (process.env.NODE_ENV !== 'production' ? otpCode : undefined),
+ // Returning the OTP lets anyone log in as any number: only on explicit opt-in, never in production.
+ devOtp: (process.env.YOUPI_EXPOSE_DEV_OTP === 'true' && process.env.NODE_ENV !== 'production' ? otpCode : undefined),
dispatch: dispatchResult
});
});
diff --git a/apps/payment-api/src/services/whatsapp-berry.service.js b/apps/payment-api/src/services/whatsapp-berry.service.js
index 8f3f9b2..4a26afd 100644
--- a/apps/payment-api/src/services/whatsapp-berry.service.js
+++ b/apps/payment-api/src/services/whatsapp-berry.service.js
@@ -375,7 +375,7 @@ export class WhatsAppBerryService extends EventEmitter {
this.pairingCode = code;
this.pairingPhone = phoneNumber;
this.status = 'PAIRING_CODE_READY';
- console.log(`[WhatsAppBerryService] WhatsApp 8-digit Pairing Code generated: ${code} for phone ${phoneNumber}`);
+ console.log(`[WhatsAppBerryService] WhatsApp 8-digit pairing code generated for phone ${phoneNumber}.`);
this.emit('pairing_code', { code, phoneNumber });
this.emit('status', this.status);
});
@@ -657,7 +657,7 @@ export class WhatsAppBerryService extends EventEmitter {
}
if (this.isSimulatedMode) {
- console.log(`[WhatsAppBerryService] Simulated WhatsApp message to ${to}: "${message.slice(0, 50)}..."`);
+ console.log(`[WhatsAppBerryService] Simulated WhatsApp message to ${to} (${message.length} chars; body not logged).`);
return {
success: true,
delivered: true,