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(android): make the allowlist generator idempotent and require the package

rishabh734e5778a1b2
diff --git a/apps/android-observer-app/app/src/main/java/com/youpi/observer/PaymentNotificationListenerService.java b/apps/android-observer-app/app/src/main/java/com/youpi/observer/PaymentNotificationListenerService.java
index cd763f0..a76a0fc 100644
--- a/apps/android-observer-app/app/src/main/java/com/youpi/observer/PaymentNotificationListenerService.java
+++ b/apps/android-observer-app/app/src/main/java/com/youpi/observer/PaymentNotificationListenerService.java
@@ -16,7 +16,7 @@ public class PaymentNotificationListenerService extends NotificationListenerServ
private static final String TAG = "YoupiNotifListener";
private ApiClient apiClient;
- // Generated from packages/common/src/upi-providers.js - Single Source of Truth
+ // Generated from packages/common/src/upi-providers.js - Single Source of Truth
private static final Set<String> ALLOWED_BANKING_PACKAGES = new HashSet<>(Arrays.asList(
"com.axis.mobile",
"com.bankofbaroda.mconnect",
diff --git a/apps/payment-api/src/routes/pollers.routes.js b/apps/payment-api/src/routes/pollers.routes.js
index d139f5c..5a835b6 100644
--- a/apps/payment-api/src/routes/pollers.routes.js
+++ b/apps/payment-api/src/routes/pollers.routes.js
@@ -263,7 +263,7 @@ export function registerPollerRoutes(server, ctx) {
server.post('/api/v1/observers/sms/pair', handleAndroidPair);
// --- ANDROID SMS GATEWAY OBSERVATION INGESTION ---
- const handleAndroidSmsEvents = async (req, res) => {
+ const handleAndroidSmsEvents = async (req, res, { requirePackage = false } = {}) => {
const rawBodyText = await new Promise(resolve => {
let data = '';
req.on('data', chunk => { data += chunk; });
@@ -332,9 +332,16 @@ export function registerPollerRoutes(server, ctx) {
let senderVpa = body.senderVpa;
let observedAt = body.observedAt ? new Date(body.observedAt) : new Date();
- // Security Invariant (Issues #24, #61): Validate Android notification package name if notification origin
- if (body.rawNotification) {
- const rawPkg = body.rawNotification.package;
+ // Security Invariant (Issues #24, #61): the notification package must be declared and
+ // must be on the allowlist. Validating it only when `rawNotification` was present let a
+ // caller omit the field entirely and still reach the verification pipeline.
+ //
+ // The package is required on the notification-listener route, which is where the
+ // allowlist is the control. The plain SMS-broadcast route has no package to report (the
+ // broadcast only carries the sender address) and is authenticated by the device HMAC
+ // instead, so requiring one there would break the observer.
+ const rawPkg = body.rawNotification?.package;
+ if (requirePackage) {
if (!rawPkg || typeof rawPkg !== 'string' || !rawPkg.trim()) {
HttpServer.json(res, 400, {
accepted: false,
@@ -342,7 +349,9 @@ export function registerPollerRoutes(server, ctx) {
});
return;
}
+ }
+ if (rawPkg && typeof rawPkg === 'string' && rawPkg.trim()) {
const notificationPackage = rawPkg.trim().toLowerCase();
if (!isAllowedNotificationPackage(notificationPackage)) {
HttpServer.json(res, 400, {
@@ -463,8 +472,9 @@ export function registerPollerRoutes(server, ctx) {
});
};
- server.post('/api/v1/pollers/android/events', handleAndroidSmsEvents);
- server.post('/api/v1/observers/sms', handleAndroidSmsEvents);
+ // The notification-listener route must declare its package; the SMS-broadcast route has none.
+ server.post('/api/v1/pollers/android/events', (req, res) => handleAndroidSmsEvents(req, res, { requirePackage: true }));
+ server.post('/api/v1/observers/sms', (req, res) => handleAndroidSmsEvents(req, res, { requirePackage: false }));
// --- ANDROID HEARTBEAT HANDLER ---
const handleAndroidHeartbeat = async (req, res) => {
diff --git a/scripts/sync-android-allowlist.js b/scripts/sync-android-allowlist.js
index c89d9e2..332c02c 100644
--- a/scripts/sync-android-allowlist.js
+++ b/scripts/sync-android-allowlist.js
@@ -32,7 +32,12 @@ export function syncAndroidAllowlist() {
${javaArrayLines}
));`;
- const regex = /(?:\/\/[^\n]*\n\s*)?private static final Set<String> ALLOWED_BANKING_PACKAGES = new HashSet<\>\(Arrays\.asList\([\s\S]*?\)\);/;
+ // Anchored at the start of a line (with optional leading whitespace) so the generated
+ // comment is matched as a whole. The previous pattern could start mid-line, which made
+ // the replacement re-indent the block on every run: the script was not idempotent, the
+ // committed file stopped matching what the generator produced, and every build left the
+ // working tree dirty.
+ const regex = /^[ \t]*(?:\/\/[^\n]*\n[ \t]*)?private static final Set<String> ALLOWED_BANKING_PACKAGES = new HashSet<\>\(Arrays\.asList\([\s\S]*?\)\);/m;
if (!regex.test(content)) {
throw new Error('Could not match ALLOWED_BANKING_PACKAGES block in PaymentNotificationListenerService.java');
}