@onesub/server 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/google-webhook-open-warning.test.d.ts +12 -0
- package/dist/__tests__/google-webhook-open-warning.test.d.ts.map +1 -0
- package/dist/__tests__/webhook-google-mount.test.d.ts +18 -0
- package/dist/__tests__/webhook-google-mount.test.d.ts.map +1 -0
- package/dist/index.cjs +26 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/routes/webhook-google.d.ts +29 -0
- package/dist/routes/webhook-google.d.ts.map +1 -1
- package/dist/routes/webhook.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Startup warning for the two conditions that leave the Google RTDN route open.
|
|
3
|
+
*
|
|
4
|
+
* `POST /onesub/webhook/google` verifies the Pub/Sub OIDC token only when an app
|
|
5
|
+
* declares `pushAudience`, and serves any `packageName` when none declares one.
|
|
6
|
+
* The route is mounted either way. Both behaviours are pre-existing and
|
|
7
|
+
* deliberate — a host may front the route with its own verification — so this
|
|
8
|
+
* warns instead of refusing, and these tests pin down that it says so exactly
|
|
9
|
+
* when it should and stays quiet otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=google-webhook-open-warning.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-webhook-open-warning.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/google-webhook-open-warning.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `POST /onesub/webhook/google` is mounted only for deployments that serve
|
|
3
|
+
* Google Play.
|
|
4
|
+
*
|
|
5
|
+
* Why it is conditional at all: unlike Apple's route, it does not authenticate
|
|
6
|
+
* unconditionally — the Pub/Sub OIDC token is verified only when an app declares
|
|
7
|
+
* a `pushAudience` — and its voided-purchase branch needs no Google credentials
|
|
8
|
+
* to run. It cancels a subscription by `purchaseToken`, or deletes a purchase row
|
|
9
|
+
* by `orderId`, straight from the payload. So an Apple-only deployment used to
|
|
10
|
+
* expose an unauthenticated endpoint that could revoke entitlement, with no
|
|
11
|
+
* Google purchases for it to be about.
|
|
12
|
+
*
|
|
13
|
+
* Apple's route stays unconditional, and this file asserts that too: it verifies
|
|
14
|
+
* the `signedPayload` JWS against the bundled Apple roots on every request
|
|
15
|
+
* regardless of config, so it is not open in the same way.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=webhook-google-mount.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-google-mount.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/webhook-google-mount.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
package/dist/index.cjs
CHANGED
|
@@ -1751,6 +1751,25 @@ var GOOGLE_FAILURE_MESSAGES = {
|
|
|
1751
1751
|
message: "Failed to process notification"
|
|
1752
1752
|
}
|
|
1753
1753
|
};
|
|
1754
|
+
function servesGoogle(config) {
|
|
1755
|
+
return getAppRegistry(config).apps.some((app) => !!app.google);
|
|
1756
|
+
}
|
|
1757
|
+
function warnIfGoogleWebhookOpen(config) {
|
|
1758
|
+
if (process.env["NODE_ENV"] !== "production") return;
|
|
1759
|
+
if (!servesGoogle(config)) return;
|
|
1760
|
+
const apps = getAppRegistry(config).apps;
|
|
1761
|
+
const googleApps = apps.map((a) => a.google).filter((g) => !!g);
|
|
1762
|
+
if (!googleApps.some((g) => g.pushAudience)) {
|
|
1763
|
+
log.warn(
|
|
1764
|
+
"[onesub] SECURITY: POST /onesub/webhook/google accepts unauthenticated requests \u2014 no configured app sets google.pushAudience, so the Pub/Sub OIDC token is never verified. A caller who knows a purchaseToken or orderId can cancel a subscription or delete a one-time purchase. Set google.pushAudience (and google.pushServiceAccountEmail)."
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1767
|
+
if (!apps.some((a) => a.google?.packageName)) {
|
|
1768
|
+
log.warn(
|
|
1769
|
+
"[onesub] POST /onesub/webhook/google is in open mode \u2014 no configured app declares google.packageName, so notifications for ANY package are accepted. Set google.packageName on each app you serve."
|
|
1770
|
+
);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1754
1773
|
function googleResolver(config) {
|
|
1755
1774
|
const registry = getAppRegistry(config);
|
|
1756
1775
|
const restricted = registry.apps.some((app) => !!app.google?.packageName);
|
|
@@ -1966,10 +1985,12 @@ function createWebhookRouter(config, store, purchaseStore, webhookEventStore, we
|
|
|
1966
1985
|
shared.ROUTES.WEBHOOK_APPLE,
|
|
1967
1986
|
(req, res) => handleAppleWebhook(req, res, config, store, purchaseStore, webhookEventStore, webhookQueue)
|
|
1968
1987
|
);
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1988
|
+
if (servesGoogle(config)) {
|
|
1989
|
+
router.post(
|
|
1990
|
+
shared.ROUTES.WEBHOOK_GOOGLE,
|
|
1991
|
+
(req, res) => handleGoogleWebhook(req, res, config, store, purchaseStore, webhookEventStore, webhookQueue)
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1973
1994
|
return router;
|
|
1974
1995
|
}
|
|
1975
1996
|
var NO_PURCHASE = { valid: false, purchase: null };
|
|
@@ -4149,6 +4170,7 @@ function createOneSubMiddleware(config) {
|
|
|
4149
4170
|
"[onesub] apple.mockMode / google.mockMode cannot be enabled when NODE_ENV=production \u2014 these modes accept any receipt as valid."
|
|
4150
4171
|
);
|
|
4151
4172
|
}
|
|
4173
|
+
warnIfGoogleWebhookOpen(config);
|
|
4152
4174
|
const store = config.store ?? new InMemorySubscriptionStore();
|
|
4153
4175
|
const purchaseStore = config.purchaseStore ?? new InMemoryPurchaseStore();
|
|
4154
4176
|
if (config.cache) setDefaultCache(config.cache);
|