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 exposing webhook secrets as API keys
surenuxui668b6fce19e1
diff --git a/apps/merchant-admin/src/views/admin.html b/apps/merchant-admin/src/views/admin.htmlindex bbf2b45..7b76626 100644--- a/apps/merchant-admin/src/views/admin.html+++ b/apps/merchant-admin/src/views/admin.html@@ -4930,7 +4930,7 @@};setVal('settingMerchantId', mData.publishableKey || mData.merchantId || currentMerchantId);- setVal('settingMerchantApiKey', mData.merchantKey || branding.merchantApiKey || mData.webhookSecret || '');+ setVal('settingMerchantApiKey', mData.merchantKey || branding.merchantApiKey || '');setVal('settingBusinessName', mData.businessName);setVal('settingWebhookUrl', mData.webhookUrl);setVal('settingWebhookSecret', mData.webhookSecret);@@ -7947,4 +7947,4 @@</body>-</html>\ No newline at end of file+</html>diff --git a/apps/payment-api/src/__tests__/payment-api.test.js b/apps/payment-api/src/__tests__/payment-api.test.jsindex 4bfe2bc..ffb086d 100644--- a/apps/payment-api/src/__tests__/payment-api.test.js+++ b/apps/payment-api/src/__tests__/payment-api.test.js@@ -1159,7 +1159,7 @@ describe('Payment API End-to-End HTTP Integration Tests', () => {assert.equal(settingsBefore.status, 200);assert.ok(settingsBefore.body.merchantId);assert.equal(settingsBefore.body.publishableKey, settingsBefore.body.merchantId);- assert.ok(settingsBefore.body.merchantKey, 'merchantKey should be returned in merchant-settings');+ assert.equal(settingsBefore.body.merchantKey, '', 'legacy webhook secrets must not be returned as merchant API keys');// 2. Rotate Merchant API Key via POST /api/v1/admin/merchant-key/rotateconst rotateRes = await request('/api/v1/admin/merchant-key/rotate', {diff --git a/apps/payment-api/src/routes/admin.routes.js b/apps/payment-api/src/routes/admin.routes.jsindex 0f6f8ac..d816750 100644--- a/apps/payment-api/src/routes/admin.routes.js+++ b/apps/payment-api/src/routes/admin.routes.js@@ -726,7 +726,7 @@ export function registerAdminRoutes(server, ctx) {HttpServer.json(res, 200, {merchantId: merchant.id,publishableKey: merchant.id,- merchantKey: merchant.merchantKey || branding.merchantApiKey || merchant.webhookSecret || '',+ merchantKey: merchant.merchantKey || branding.merchantApiKey || '',businessName: merchant.businessName,upiId: account ? account.upiId : '',payeeName: account ? account.payeeName : merchant.businessName,@@ -1028,7 +1028,7 @@ export function registerAdminRoutes(server, ctx) {HttpServer.json(res, 200, {merchantId: merchant.id,publishableKey: merchant.id,- merchantKey: merchant.merchantKey || branding.merchantApiKey || merchant.webhookSecret || '',+ merchantKey: merchant.merchantKey || branding.merchantApiKey || '',businessName: merchant.businessName,contactEmail: merchant.contactEmail,contactPhone: merchant.contactPhone,@@ -1219,7 +1219,7 @@ export function registerAdminRoutes(server, ctx) {success: true,merchantId: updated.id,publishableKey: updated.id,- merchantKey: updated.merchantKey || updated.branding?.merchantApiKey || updated.webhookSecret || '',+ merchantKey: updated.merchantKey || updated.branding?.merchantApiKey || '',businessName: updated.businessName,webhookUrl: updated.webhookUrl || '',webhookSecret: updated.webhookSecret || '',diff --git a/packages/db/src/__tests__/db.test.js b/packages/db/src/__tests__/db.test.jsindex 680a423..23319f9 100644--- a/packages/db/src/__tests__/db.test.js+++ b/packages/db/src/__tests__/db.test.js@@ -37,6 +37,7 @@ describe('@youpi/db Unit & Integration Tests', () => {assert.equal(merchantRepo.verifyApiKey(merchant, 'mk_live_dedicated_api_credential_123456'), true);assert.equal(merchantRepo.verifyApiKey(merchant, 'independent_webhook_hmac_secret_123456'), false);assert.equal(merchantRepo.verifyApiKey(merchant, 'legacy_branding_key_123456'), false);+ assert.equal(merchant.merchantKey, '', 'webhook secrets must never be exposed as API keys');});beforeEach(() => {diff --git a/packages/db/src/repositories/merchant.repository.js b/packages/db/src/repositories/merchant.repository.jsindex bfcd98a..d8ebba4 100644--- a/packages/db/src/repositories/merchant.repository.js+++ b/packages/db/src/repositories/merchant.repository.js@@ -213,7 +213,7 @@ export class MerchantRepository {webhookUrl: row.webhook_url,// Plaintext rows written before encryption existed decrypt to themselves.webhookSecret,- merchantKey: branding?.merchantApiKey || webhookSecret || '',+ merchantKey: branding?.merchantApiKey && row.api_key_hash === hashApiKey(branding.merchantApiKey) ? branding.merchantApiKey : '',apiKeyHash: row.api_key_hash || null,branding,createdAt: new Date(row.created_at),