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): sign Gmail OAuth state and derive the redirect URI in the admin API

Abhi Pareekf6f7caa58458
diff --git a/apps/payment-api/src/routes/admin.routes.js b/apps/payment-api/src/routes/admin.routes.js
index f8298c0..3058d33 100644
--- a/apps/payment-api/src/routes/admin.routes.js
+++ b/apps/payment-api/src/routes/admin.routes.js
@@ -1,6 +1,6 @@
import crypto from 'node:crypto';
import { HttpServer } from '../server.js';
-import { PaymentStatus, PaymentMethod, SellingMode, AuditActorType, isValidVpa, toRupeesString, deriveCloudflareRoutes, resolveRuntimeUrls } from '@youpi/common';
+import { PaymentStatus, PaymentMethod, SellingMode, AuditActorType, isValidVpa, toRupeesString, deriveCloudflareRoutes, resolveRuntimeUrls, resolveGmailRedirectUri, createOAuthState } from '@youpi/common';
import { PaymentVerificationPipeline } from '@youpi/core';
import { globalTunnelManager } from '../services/tunnel-manager.js';
import { formatQrDataUrl } from '../services/whatsapp-berry.service.js';
@@ -1429,7 +1429,7 @@ export function registerAdminRoutes(server, ctx) {
const branding = merchant?.branding || {};
const gmailConfig = branding.gmailConfig || {};
- const redirectUri = 'https://pay-gmail.gauravtesting.online/oauth/callback';
+ const redirectUri = resolveGmailRedirectUri(branding);
const hasToken = Boolean(gmailConfig.refreshToken && gmailConfig.refreshToken.trim());
HttpServer.json(res, 200, {
@@ -1472,9 +1472,9 @@ export function registerAdminRoutes(server, ctx) {
});
return;
}
- const redirectUri = 'https://pay-gmail.gauravtesting.online/oauth/callback';
+ const redirectUri = resolveGmailRedirectUri(branding);
const scopes = encodeURIComponent('https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/userinfo.email');
- const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scopes}&access_type=offline&prompt=consent&include_granted_scopes=true`;
+ const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scopes}&access_type=offline&prompt=consent&include_granted_scopes=true&state=${encodeURIComponent(createOAuthState())}`;
HttpServer.json(res, 200, {
success: true,