@pithy-sh/payments 0.2.0 → 0.3.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/capability.d.ts.map +1 -1
- package/dist/capability.js +3 -0
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +32 -1
- package/dist/http/webhookGuard.d.ts +9 -6
- package/dist/http/webhookGuard.d.ts.map +1 -1
- package/dist/http/webhookGuard.js +44 -8
- package/dist/rails/apple/x509.d.ts.map +1 -1
- package/dist/rails/apple/x509.js +6 -0
- package/dist/rails/google/oidc.d.ts +91 -31
- package/dist/rails/google/oidc.d.ts.map +1 -1
- package/dist/rails/google/oidc.js +144 -127
- package/dist/rails/google/playApi.js +1 -1
- package/dist/rails/google/rail.d.ts +25 -0
- package/dist/rails/google/rail.d.ts.map +1 -1
- package/dist/rails/google/rail.js +2 -1
- package/dist/rails/paddle/rail.d.ts +10 -1
- package/dist/rails/paddle/rail.d.ts.map +1 -1
- package/dist/rails/paddle/signature.d.ts +8 -2
- package/dist/rails/paddle/signature.d.ts.map +1 -1
- package/dist/rails/paddle/signature.js +17 -2
- package/dist/rails/providers.d.ts +15 -0
- package/dist/rails/providers.d.ts.map +1 -1
- package/dist/rails/providers.js +2 -1
- package/dist/rails/stripe/rail.d.ts +11 -1
- package/dist/rails/stripe/rail.d.ts.map +1 -1
- package/dist/rails/stripe/signature.d.ts +8 -1
- package/dist/rails/stripe/signature.d.ts.map +1 -1
- package/dist/secret/branches.d.ts +39 -0
- package/dist/secret/branches.d.ts.map +1 -0
- package/dist/secret/branches.js +46 -0
- package/dist/secret/registry.d.ts.map +1 -1
- package/dist/secret/registry.js +15 -15
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +11 -9
- package/src/capability.ts +7 -0
- package/src/config/config.ts +10 -1
- package/src/http/routes.ts +32 -1
- package/src/http/webhookGuard.ts +40 -7
- package/src/rails/apple/x509.ts +18 -0
- package/src/rails/google/oidc.ts +194 -218
- package/src/rails/google/rail.ts +28 -0
- package/src/rails/paddle/rail.ts +10 -1
- package/src/rails/paddle/signature.ts +39 -3
- package/src/rails/providers.ts +16 -0
- package/src/rails/stripe/rail.ts +11 -1
- package/src/rails/stripe/signature.ts +8 -1
- package/src/secret/branches.ts +48 -0
- package/src/secret/registry.ts +24 -2
- package/src/version.generated.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { base64UrlDecode, decodeJwtJson, splitJwt } from "./jwt.js";
|
|
3
|
+
import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
4
|
+
import { WebhookUnverifiedError } from "@pithy-sh/core/src/error/pithyError";
|
|
6
5
|
import { z } from "zod";
|
|
6
|
+
import { OidcClaims, OidcJwk, OidcJwks, verifyOidcToken } from "@pithy-sh/core/src/http/oidcWebhook";
|
|
7
7
|
//#region src/rails/google/oidc.ts
|
|
8
8
|
/**
|
|
9
9
|
* The authenticity boundary on Google's webhook: the OIDC token a Pub/Sub push carries.
|
|
@@ -20,21 +20,47 @@ import { z } from "zod";
|
|
|
20
20
|
* for. Verify the signature and skip the audience and you have built an endpoint that accepts notifications
|
|
21
21
|
* from any Google customer who points a subscription at it.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
23
|
+
* ## Everything above is `@pithy-sh/core/src/http/oidcWebhook`, and none of it is here
|
|
24
|
+
*
|
|
25
|
+
* Algorithm pinning, key resolution by `kid`, signature verification, issuer, audience, `exp`, `nbf`, `iat`,
|
|
26
|
+
* the JWKS fetch and its cache: one implementation, in core, shared with every other OIDC sender the kit
|
|
27
|
+
* verifies. This module is the **Google specialization** — two issuer spellings, a key endpoint, an audience,
|
|
28
|
+
* and the one claim pair Google's own guidance adds — and nothing else. A second copy of a verifier is a
|
|
29
|
+
* second thing to keep current, and the thing that would drift here is an authentication boundary (#520).
|
|
30
|
+
*
|
|
31
|
+
* Core is stricter than the copy it replaced, deliberately: `nbf` is honored, a non-finite skew or key-set
|
|
32
|
+
* lifetime is refused rather than silently disabling the freshness checks, and a claim outside `Date`'s range
|
|
33
|
+
* is quoted as a number rather than throwing a `RangeError` while composing the refusal it had already
|
|
34
|
+
* decided on.
|
|
35
|
+
*
|
|
36
|
+
* ## What a refusal is called
|
|
37
|
+
*
|
|
38
|
+
* Core answers `core/webhook_unverified` for every failing step. The rail re-codes that to
|
|
39
|
+
* **`payments/verification_failed`**, so the audit trail's `metadata.step` stays a `payments/*` value and the
|
|
40
|
+
* webhook guard's pass-through set governs the rest. Core's `detail` rides along under a `Google:` prefix.
|
|
41
|
+
*
|
|
42
|
+
* `payments/invalid_receipt` no longer appears on this path, and that is a deliberate contract change rather
|
|
43
|
+
* than something the refactor dropped. It meant *the token could not be read*, which is a **receipt**
|
|
44
|
+
* distinction: `PaymentsRailProvider.verify` uses it for a client submission, where telling a developer that
|
|
45
|
+
* their payload is malformed is useful. A Pub/Sub push token is not a receipt, it is a webhook credential, and
|
|
46
|
+
* on the webhook path the guard already collapsed both codes to `payments/webhook_unverified` (401) before
|
|
47
|
+
* anything reached the sender — so no caller ever saw the difference, and core's own argument for one code
|
|
48
|
+
* applies with full force: a forger must not learn which check it tripped. Both codes were 400 and
|
|
49
|
+
* `verifyGoogleOidcToken` is not exported from the package, so the change is visible in exactly one place,
|
|
50
|
+
* the audit row's `metadata.step`.
|
|
51
|
+
*
|
|
52
|
+
* Two codes come from core untouched, because neither is a statement about the sender and both are already in
|
|
53
|
+
* the webhook guard's pass-through set: `core/internal` (500) for an endpoint of ours that is not configured
|
|
54
|
+
* to verify anything, and `core/upstream_failed` (502) for Google's key endpoint failing to answer. The
|
|
55
|
+
* second replaces `payments/provider_unavailable` (503) on the JWKS hop alone — CLAUDE.md §Errors gives the
|
|
56
|
+
* upstream pair exactly this job, and the Play Developer API hop is untouched and still 503.
|
|
57
|
+
*
|
|
58
|
+
* **A pass-through code is a code an anonymous caller must not be able to choose**, and that is what decided
|
|
59
|
+
* where the line sits. A published key that is not RSA, or will not import, used to be core's 502 and is
|
|
60
|
+
* core's 401 now: the key was reached because a `kid` in an unverified header selected it, so a 502 there
|
|
61
|
+
* let a forger pick a code this rail passes through — out of the audit trail, and into Pub/Sub's indefinite
|
|
62
|
+
* retry — by naming one `kid` instead of another. Nothing a `kid` can steer stays in the pass-through set.
|
|
63
|
+
* What is left in it is failure nobody chose: the endpoint being unreachable, and our own configuration.
|
|
38
64
|
*/
|
|
39
65
|
/** Where Google publishes the keys that sign an OIDC token. Public, so it is pinned here rather than stored. */
|
|
40
66
|
const GOOGLE_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
|
|
@@ -43,131 +69,116 @@ const GOOGLE_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
|
|
|
43
69
|
* decide, so both are accepted and nothing else is.
|
|
44
70
|
*/
|
|
45
71
|
const GOOGLE_OIDC_ISSUERS = ["https://accounts.google.com", "accounts.google.com"];
|
|
46
|
-
/** How long a fetched key set is reused. Google rotates slowly, and an unknown `kid` forces a refresh anyway. */
|
|
47
|
-
const JWKS_TTL_MS = 36e5;
|
|
48
|
-
/** Tolerance on `exp` and `iat`. A minute covers clock drift; an hour would cover a replay. */
|
|
49
|
-
const DEFAULT_CLOCK_SKEW_SECONDS = 60;
|
|
50
|
-
/** RSASSA-PKCS1-v1_5 with SHA-256 — the one algorithm `alg: RS256` names, fixed here rather than derived. */
|
|
51
|
-
const RS256 = {
|
|
52
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
53
|
-
hash: "SHA-256"
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* The header of a Pub/Sub push token, as tightly as it can be stated. `alg` is a literal for the reason in the
|
|
57
|
-
* module doc; `kid` is required because a key is resolved by it and a token that names no key cannot be
|
|
58
|
-
* checked against one.
|
|
59
|
-
*/
|
|
60
|
-
const GoogleOidcHeader = z.object({
|
|
61
|
-
alg: z.literal("RS256").describe("The signing algorithm. A literal, not a lookup: `alg` arrives in an unverified header, and accepting `none` or `HS256` from it is how JWS verifiers are bypassed."),
|
|
62
|
-
kid: z.string().min(1).describe("Which of Google's published keys signed the token. Resolved against Google's key endpoint.")
|
|
63
|
-
}).loose().describe("The header of a Google-signed OIDC token, constrained to the one shape Pub/Sub sends.");
|
|
64
72
|
/**
|
|
65
|
-
* One published RSA verification key,
|
|
66
|
-
*
|
|
73
|
+
* One published RSA verification key, and the key set Google's endpoint returns.
|
|
74
|
+
*
|
|
75
|
+
* Core's schemas under the rail's published names, not copies of them. The shape is the JWKS shape — it
|
|
76
|
+
* belongs to RFC 7517 rather than to Google — and two declarations of one wire format is the same drift this
|
|
77
|
+
* module exists to remove, one layer down. The names stay because they are `@pithy-sh/payments`' public
|
|
78
|
+
* surface and an adopter typing a Pub/Sub emulator's key against `GoogleJwk` should not have to learn a
|
|
79
|
+
* second one.
|
|
67
80
|
*/
|
|
68
|
-
const GoogleJwk =
|
|
69
|
-
|
|
70
|
-
kty: z.string().min(1).describe("The key type. Only `RSA` is accepted — Google signs these with RSA keys."),
|
|
71
|
-
n: z.string().min(1).describe("The RSA modulus, base64url."),
|
|
72
|
-
e: z.string().min(1).describe("The RSA public exponent, base64url."),
|
|
73
|
-
alg: z.string().min(1).optional().describe("The algorithm the key is published for, when stated."),
|
|
74
|
-
use: z.string().min(1).optional().describe("What the key is published for — `sig` for a signing key.")
|
|
75
|
-
}).loose().describe("One of Google's published OIDC verification keys.");
|
|
76
|
-
/** Google's published key set. At least one key: an empty set is an endpoint that is not answering properly. */
|
|
77
|
-
const GoogleJwks = z.object({ keys: z.array(GoogleJwk).min(1).describe("Every key currently signing Google OIDC tokens.") }).loose().describe("The response of Google's OIDC key endpoint.");
|
|
81
|
+
const GoogleJwk = OidcJwk;
|
|
82
|
+
const GoogleJwks = OidcJwks;
|
|
78
83
|
/**
|
|
79
|
-
* The claims a Pub/Sub push token carries,
|
|
80
|
-
*
|
|
84
|
+
* The claims a Pub/Sub push token carries: core's, plus the two Google adds.
|
|
85
|
+
*
|
|
86
|
+
* `email` and `email_verified` are the extension, and they are the reason this schema exists at all — core
|
|
87
|
+
* reads what every OIDC token has and hands the rest to a predicate. Extended rather than redeclared, so
|
|
88
|
+
* `iss`/`aud`/`exp`/`nbf`/`iat` have one definition in the kit. Still `.loose()`: the whole token is never
|
|
89
|
+
* stored, and a claim set must not be refused for being richer than expected.
|
|
81
90
|
*/
|
|
82
|
-
const GoogleOidcClaims =
|
|
83
|
-
iss: z.string().min(1).describe("Who issued the token. One of Google's two issuer spellings, and nothing else."),
|
|
84
|
-
aud: z.string().min(1).describe("Who the token was minted for — the audience configured on the push subscription. The claim that makes a token ours rather than merely Google's."),
|
|
85
|
-
exp: z.number().int().describe("When the token expires, in seconds since the epoch."),
|
|
86
|
-
iat: z.number().int().optional().describe("When the token was issued, in seconds since the epoch."),
|
|
91
|
+
const GoogleOidcClaims = OidcClaims.extend({
|
|
87
92
|
email: z.string().min(1).optional().describe("The service account Pub/Sub used to mint the token. Checked against the configured one."),
|
|
88
|
-
email_verified: z.boolean().optional().describe("Whether Google vouches for that address. Always true on a real push token.")
|
|
89
|
-
|
|
90
|
-
}).loose().describe("The claims on a Pub/Sub push OIDC token, narrowed to the ones verification depends on.");
|
|
93
|
+
email_verified: z.boolean().optional().describe("Whether Google vouches for that address. Always true on a real push token.")
|
|
94
|
+
}).describe("The claims on a Pub/Sub push OIDC token, narrowed to the ones verification depends on.");
|
|
91
95
|
/**
|
|
92
|
-
*
|
|
96
|
+
* Verify one Pub/Sub push OIDC token and return its claims.
|
|
93
97
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
98
|
+
* @throws {@link PaymentsVerificationFailedError} when the sender did not prove itself — an unreadable token,
|
|
99
|
+
* an unknown key, a key that cannot verify an `RS256` signature, a bad signature, the wrong audience, the
|
|
100
|
+
* wrong issuer, an expiry, the wrong service account.
|
|
101
|
+
* @throws `core/internal` (500) when this endpoint is not configured to verify anything — an audience that is
|
|
102
|
+
* empty, a clock that is not a clock, a skew or key-set lifetime that is not a number.
|
|
103
|
+
* @throws `core/upstream_failed` (502) when Google's key endpoint could not be read.
|
|
97
104
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
async function verifyGoogleOidcToken(token, options) {
|
|
106
|
+
let verified;
|
|
107
|
+
try {
|
|
108
|
+
verified = await verifyOidcToken(token, {
|
|
109
|
+
issuers: GOOGLE_OIDC_ISSUERS,
|
|
110
|
+
jwksUrl: GOOGLE_JWKS_URL,
|
|
111
|
+
audience: options.audience,
|
|
112
|
+
claims: (claims) => acceptedByThisEndpoint(claims, options.serviceAccountEmail),
|
|
113
|
+
skewSeconds: options.clockSkewSeconds,
|
|
114
|
+
jwksTtlSeconds: options.jwksTtlSeconds,
|
|
115
|
+
jwksCache: googleKeySource(options.trustedKeys, options.jwksCache),
|
|
116
|
+
transport: options.transport,
|
|
117
|
+
now: options.now
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
throw railCode(error);
|
|
121
|
+
}
|
|
122
|
+
const parsed = GoogleOidcClaims.safeParse(verified);
|
|
123
|
+
if (!parsed.success) throw failed(`the token claims are not those of a Pub/Sub push token — ${issues(parsed.error)}.`);
|
|
124
|
+
return parsed.data;
|
|
113
125
|
}
|
|
114
126
|
/**
|
|
115
|
-
*
|
|
127
|
+
* Google's own second check, run last and handed only claims core has already proven.
|
|
128
|
+
*
|
|
129
|
+
* It **throws** rather than answering `false`. Core's own refusal for a rejected predicate names the subject
|
|
130
|
+
* and nothing else, which is right for a rule it cannot see inside — and wrong here, where the two things
|
|
131
|
+
* being asserted are named claims and an operator reading the log needs to know which one failed. A predicate
|
|
132
|
+
* that throws a `PaymentsVerificationFailedError` leaves `verifyOidcToken` as itself, past
|
|
133
|
+
* {@link railCode}'s `instanceof`, with the sentence the old verifier wrote.
|
|
116
134
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* because otherwise a stream of forged tokens naming random `kid`s is a way to make us hammer Google.
|
|
135
|
+
* The audience says which endpoint the token was minted for; the email says which identity minted it. Both
|
|
136
|
+
* are always present on a real push token.
|
|
120
137
|
*/
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const cached = publishedKeys?.keys.find((key) => key.kid === kid);
|
|
127
|
-
if (cached) return cached;
|
|
128
|
-
}
|
|
129
|
-
const found = (await refreshPublishedKeys(transport, options.now)).find((key) => key.kid === kid);
|
|
130
|
-
if (!found) throw new PaymentsVerificationFailedError({ detail: `Google: no published key matches the token's kid "${kid}".` });
|
|
131
|
-
return found;
|
|
138
|
+
function acceptedByThisEndpoint(claims, serviceAccountEmail) {
|
|
139
|
+
const email = typeof claims.email === "string" ? claims.email : void 0;
|
|
140
|
+
if (email !== serviceAccountEmail) throw failed(`the token names service account "${snippet(email ?? "none")}", not the configured one.`);
|
|
141
|
+
if (claims.email_verified !== true) throw failed("the token's service-account address is not marked verified by Google.");
|
|
142
|
+
return true;
|
|
132
143
|
}
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The configured keys, presented to core as a key source rather than seeded into its cache.
|
|
146
|
+
*
|
|
147
|
+
* Seeding is the obvious shape and the wrong one, because a cache is **shared** and `trustedKeys` is not. A
|
|
148
|
+
* key written into the store reads back to every other verifier holding that store as a key *Google
|
|
149
|
+
* publishes* — so a Pub/Sub emulator's key, or a suite's, would be trusted by a rail instance nobody handed
|
|
150
|
+
* it to. A wrapper keeps `trustedKeys` additive for its own caller and invisible to everyone else, and it is
|
|
151
|
+
* additive **by construction**: core still fetches for a `kid` the configured keys do not cover, and core's
|
|
152
|
+
* own write-back cannot evict them.
|
|
153
|
+
*
|
|
154
|
+
* No keys and no cache is `undefined`, which is core's "fetch per call" and not a cache that never holds
|
|
155
|
+
* anything.
|
|
156
|
+
*
|
|
157
|
+
* **The refresh claim is delegated, never answered here**, and that is the same rule one axis over: the
|
|
158
|
+
* window belongs to the store, because it is what bounds every caller sharing it. Answering `true` would
|
|
159
|
+
* hand each configured-key caller its own window, which for a store shared across isolates is the bound
|
|
160
|
+
* dissolved by a wrapper nobody thought was one. With no store behind it there is no window to claim and no
|
|
161
|
+
* bound to keep, which is core's own fetch-per-call state.
|
|
162
|
+
*/
|
|
163
|
+
function googleKeySource(trustedKeys, cache) {
|
|
164
|
+
if (trustedKeys === void 0 || trustedKeys.length === 0) return cache;
|
|
165
|
+
return {
|
|
166
|
+
get: async (url) => [...trustedKeys, ...await cache?.get(url) ?? []],
|
|
167
|
+
set: async (url, keys, ttlSeconds) => cache?.set(url, keys, ttlSeconds),
|
|
168
|
+
claimRefresh: async (url, seconds) => await cache?.claimRefresh(url, seconds) ?? true
|
|
169
|
+
};
|
|
144
170
|
}
|
|
145
171
|
/**
|
|
146
|
-
*
|
|
172
|
+
* Core's refusal under the rail's own code.
|
|
147
173
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
174
|
+
* Only `core/webhook_unverified` is re-coded, and it is re-coded by **class** rather than by reading core's
|
|
175
|
+
* prose — matching on a sentence is the drift this module was written to delete. `core/internal` and
|
|
176
|
+
* `core/upstream_failed` pass through untouched: neither is the sender's failure, both are already in the
|
|
177
|
+
* webhook guard's pass-through set, and re-coding either would name a culprit that is not there.
|
|
152
178
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (!header.success) throw new PaymentsInvalidReceiptError({ detail: `Google: the token header is not one Pub/Sub sends — ${issues(header.error)}.` });
|
|
157
|
-
const key = await importKey(await resolveKey(header.data.kid, options));
|
|
158
|
-
if (!await crypto.subtle.verify(RS256.name, key, base64UrlDecode(mac, "the token signature"), new TextEncoder().encode(`${head}.${body}`))) throw new PaymentsVerificationFailedError({ detail: `Google: the token signature does not match the signed segments under key "${header.data.kid}".` });
|
|
159
|
-
const parsed = GoogleOidcClaims.safeParse(decodeJwtJson(body, "the token claims"));
|
|
160
|
-
if (!parsed.success) throw new PaymentsVerificationFailedError({ detail: `Google: the token claims are not those of a Pub/Sub push token — ${issues(parsed.error)}.` });
|
|
161
|
-
const claims = parsed.data;
|
|
162
|
-
const skew = options.clockSkewSeconds ?? DEFAULT_CLOCK_SKEW_SECONDS;
|
|
163
|
-
const seconds = Math.floor(options.now.getTime() / 1e3);
|
|
164
|
-
if (!GOOGLE_OIDC_ISSUERS.includes(claims.iss)) throw failed(`the token issuer is "${claims.iss}", not one of Google's.`);
|
|
165
|
-
if (claims.aud !== options.audience) throw failed(`the token audience is "${claims.aud}", and this endpoint expects "${options.audience}".`);
|
|
166
|
-
if (claims.exp + skew < seconds) throw failed(`the token expired at ${(/* @__PURE__ */ new Date(claims.exp * 1e3)).toISOString()}.`);
|
|
167
|
-
if (claims.iat !== void 0 && claims.iat - skew > seconds) throw failed(`the token was issued at ${(/* @__PURE__ */ new Date(claims.iat * 1e3)).toISOString()}, which is in the future.`);
|
|
168
|
-
if (claims.email !== options.serviceAccountEmail) throw failed(`the token names service account "${claims.email ?? "none"}", not the configured one.`);
|
|
169
|
-
if (claims.email_verified !== true) throw failed("the token's service-account address is not marked verified by Google.");
|
|
170
|
-
return claims;
|
|
179
|
+
function railCode(error) {
|
|
180
|
+
if (!(error instanceof WebhookUnverifiedError)) return error;
|
|
181
|
+
return new PaymentsVerificationFailedError({ detail: `Google: ${error.payload.detail ?? "the push token did not verify."}` }, { cause: error });
|
|
171
182
|
}
|
|
172
183
|
/** A post-signature refusal. `Google:` prefixed, and the token itself never appears. */
|
|
173
184
|
function failed(detail) {
|
|
@@ -177,5 +188,11 @@ function failed(detail) {
|
|
|
177
188
|
function issues(error) {
|
|
178
189
|
return error.issues.map((issue) => `${issue.path.join(".") || "<root>"}:${issue.code}`).join(", ");
|
|
179
190
|
}
|
|
191
|
+
/** How much of a token-supplied value a refusal may quote. Enough to diagnose, too little to fill a log. */
|
|
192
|
+
const SNIPPET_LENGTH = 120;
|
|
193
|
+
/** A token-supplied value, bounded, so a refusal names what failed without becoming the log. */
|
|
194
|
+
function snippet(value) {
|
|
195
|
+
return value.length > SNIPPET_LENGTH ? `${value.slice(0, SNIPPET_LENGTH)}…` : value;
|
|
196
|
+
}
|
|
180
197
|
//#endregion
|
|
181
|
-
export { GOOGLE_JWKS_URL, GOOGLE_OIDC_ISSUERS, GoogleJwk, GoogleJwks, GoogleOidcClaims,
|
|
198
|
+
export { GOOGLE_JWKS_URL, GOOGLE_OIDC_ISSUERS, GoogleJwk, GoogleJwks, GoogleOidcClaims, verifyGoogleOidcToken };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { PaymentsProviderUnavailableError, PaymentsRailNotConfiguredError, PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
4
|
+
import { pauseResumesAt } from "../../data/pause.js";
|
|
4
5
|
import { googleHttpFetch, googleJson } from "./http.js";
|
|
5
6
|
import { base64UrlEncode, pemPrivateKey } from "./jwt.js";
|
|
6
|
-
import { pauseResumesAt } from "../../data/pause.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
//#region src/rails/google/playApi.ts
|
|
9
9
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { JwksCache } from "@pithy-sh/core/src/http/oidcWebhook";
|
|
3
4
|
import type { PaymentsGoogleCredentials } from "../../secret/registry";
|
|
4
5
|
import type { PaymentsRailProvider } from "../contract";
|
|
5
6
|
import type { GoogleHttpFetch } from "./http";
|
|
@@ -53,6 +54,30 @@ export interface GoogleRailOptions {
|
|
|
53
54
|
* Passed down by the reconciliation Workflow; absent everywhere else, where one call mints its own.
|
|
54
55
|
*/
|
|
55
56
|
accessToken?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Where Google's published keys are held between deliveries, and it is **not optional on the webhook path**.
|
|
59
|
+
*
|
|
60
|
+
* A rail is built per request — `resolveRailProvider` runs inside the guard — so this object cannot own the
|
|
61
|
+
* store, and a cache hung here would be one that has never held anything. It is passed in instead, from
|
|
62
|
+
* whatever *does* outlive a request: `registerPaymentsRoutes` builds one per registered route tree, which is
|
|
63
|
+
* once per isolate, and an adopter wanting a harder bound hands `RailTrustOptions.googleJwksCache` a store
|
|
64
|
+
* over KV.
|
|
65
|
+
*
|
|
66
|
+
* Absent is core's fetch-per-call, which is correct on the `verify` and `refresh` paths (one caller, one
|
|
67
|
+
* purchase, no flood to absorb) and is an outbound amplifier on the webhook: `parseNotification` resolves a
|
|
68
|
+
* key *before* it can check a signature, so a 49-byte forged token buys a round trip to
|
|
69
|
+
* `https://www.googleapis.com/oauth2/v3/certs`, 1:1, until Google rate-limits us and the genuine deliveries
|
|
70
|
+
* 502 alongside the forgeries — and a 502 is in the webhook guard's pass-through set, so Pub/Sub redelivers
|
|
71
|
+
* into the same uncached path. That is the hazard core's own `JwksCache` doc names, and this is the seam
|
|
72
|
+
* that answers it here.
|
|
73
|
+
*
|
|
74
|
+
* **Whatever the `kid` claims**, which is the half the first round of this missed. Holding Google's keys
|
|
75
|
+
* answers a token naming one of them and nothing else, and a `kid` is attacker-chosen: a random one is a
|
|
76
|
+
* miss, and a miss is a refresh. So the store carries a refresh window too (`JwksCache.claimRefresh`), and
|
|
77
|
+
* the bound it keeps is one ask per `OIDC_JWKS_MIN_REFRESH_SECONDS` per key endpoint rather than one per
|
|
78
|
+
* `kid` somebody invents.
|
|
79
|
+
*/
|
|
80
|
+
jwksCache?: JwksCache;
|
|
56
81
|
}
|
|
57
82
|
/** The Google Play rail. Verifies client submissions at Play, and Pub/Sub pushes on the webhook. */
|
|
58
83
|
export declare function googleRail(credentials: PaymentsGoogleCredentials, options?: GoogleRailOptions): PaymentsRailProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rail.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/google/rail.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EACV,oBAAoB,EAMrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,QAAQ,CAAC;AAK/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,WAAW,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACnC,mGAAmG;IACnG,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAKD,oGAAoG;AACpG,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,CAiGtB"}
|
|
@@ -27,7 +27,8 @@ function googleRail(credentials, options = {}) {
|
|
|
27
27
|
serviceAccountEmail: credentials.serviceAccountEmail,
|
|
28
28
|
now: context.now,
|
|
29
29
|
transport: options.transport,
|
|
30
|
-
trustedKeys: options.trustedKeys
|
|
30
|
+
trustedKeys: options.trustedKeys,
|
|
31
|
+
jwksCache: options.jwksCache
|
|
31
32
|
});
|
|
32
33
|
const parsed = parseGoogleNotification(delivery.body, { packageName: credentials.packageName });
|
|
33
34
|
if (parsed.pointer === null) return {
|
|
@@ -40,7 +40,16 @@ export interface PaddleRailOptions {
|
|
|
40
40
|
clientToken: string;
|
|
41
41
|
/** Whether checkout opens as an overlay, inline, or on Paddle's own hosted page. */
|
|
42
42
|
checkout: "overlay" | "inline" | "hosted";
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* How many seconds either side of now a delivery may be dated. Undefined uses the rail's 300.
|
|
45
|
+
*
|
|
46
|
+
* Threaded down unchanged through `webhook.ts` and validated in one place, `signature.ts`, where the
|
|
47
|
+
* comparison is — a non-finite, negative, or over-wide window is `core/internal` there, refused before any
|
|
48
|
+
* delivery is judged. The layers between only apply defaults with `??`, which catches `undefined` and never
|
|
49
|
+
* `NaN`; one place that refuses beats three that each half-check. `paddle.webhookFreshnessSeconds` reaches
|
|
50
|
+
* this field and is deliberately **not** bounded again in `PaymentsPaddleSettings`: that schema parses at
|
|
51
|
+
* module scope, so a bound there refuses the whole Worker for one webhook route's knob.
|
|
52
|
+
*/
|
|
44
53
|
freshnessSeconds?: number;
|
|
45
54
|
/**
|
|
46
55
|
* The currency this project's Paddle catalog prices in, when the project declared one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/rail.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAEX,UAAU,EAIV,gBAAgB,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAmB,MAAM,OAAO,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/rail.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAEX,UAAU,EAIV,gBAAgB,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAmB,MAAM,OAAO,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,WAAW,EAAE,iBAAiB,CAAC;IAC/B,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,uBAAuB;AACvB,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,EAAE,iBAAiB,GACzB,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,UAAU,CAqHlG"}
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
* The window still earns its place, in both directions. It bounds how long a captured-but-never-delivered
|
|
39
39
|
* signature stays usable, and it refuses a far-future timestamp — either a broken clock or somebody trying
|
|
40
40
|
* to mint a delivery that never goes stale. Configurable, so an adopter who wants Paddle's number can set
|
|
41
|
-
* it.
|
|
41
|
+
* it — bounded, and checked before it is used, because a window is only a boundary while it is a number. A
|
|
42
|
+
* non-finite tolerance makes `drift > tolerance` false for every delivery ever signed, which is not a wider
|
|
43
|
+
* window but no window at all.
|
|
42
44
|
*
|
|
43
45
|
* Paddle re-signs each retry attempt with a fresh `ts`, which is the only way a three-day retry window and
|
|
44
46
|
* a five-second SDK tolerance could both be coherent — so the window does not silently reject retries.
|
|
@@ -60,7 +62,11 @@ export interface VerifyPaddleSignatureOptions {
|
|
|
60
62
|
secret: string;
|
|
61
63
|
/** The clock, for the freshness window. Injected so verification is deterministic. */
|
|
62
64
|
now: Date;
|
|
63
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* How many seconds either side of `now` a delivery may be dated. Undefined uses the default, and anything
|
|
67
|
+
* present must be a finite number from 0 to {@link SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} — anything else is
|
|
68
|
+
* `core/internal`, because a `NaN` here does not widen the window, it removes it.
|
|
69
|
+
*/
|
|
64
70
|
toleranceSeconds?: number;
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/signature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/paddle/signature.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,2GAA2G;AAC3G,eAAO,MAAM,gCAAgC,MAAM,CAAC;AAkBpD,uFAAuF;AACvF,MAAM,WAAW,4BAA4B;IAC3C,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,GAAG,EAAE,IAAI,CAAC;IACV;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AA+BD;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASrG;AA2CD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CA4Cf"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
4
|
+
import { InternalError } from "@pithy-sh/core/src/error/pithyError";
|
|
5
|
+
import { SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS } from "@pithy-sh/core/src/http/webhookWindow";
|
|
4
6
|
//#region src/rails/paddle/signature.ts
|
|
5
7
|
/**
|
|
6
8
|
* Paddle's authenticity proof: a timestamp and one or more HMACs, in one header.
|
|
@@ -40,7 +42,9 @@ import { PaymentsVerificationFailedError } from "../../error/errors.js";
|
|
|
40
42
|
* The window still earns its place, in both directions. It bounds how long a captured-but-never-delivered
|
|
41
43
|
* signature stays usable, and it refuses a far-future timestamp — either a broken clock or somebody trying
|
|
42
44
|
* to mint a delivery that never goes stale. Configurable, so an adopter who wants Paddle's number can set
|
|
43
|
-
* it.
|
|
45
|
+
* it — bounded, and checked before it is used, because a window is only a boundary while it is a number. A
|
|
46
|
+
* non-finite tolerance makes `drift > tolerance` false for every delivery ever signed, which is not a wider
|
|
47
|
+
* window but no window at all.
|
|
44
48
|
*
|
|
45
49
|
* Paddle re-signs each retry attempt with a fresh `ts`, which is the only way a three-day retry window and
|
|
46
50
|
* a five-second SDK tolerance could both be coherent — so the window does not silently reject retries.
|
|
@@ -141,7 +145,18 @@ async function verifyPaddleSignature(body, header, options) {
|
|
|
141
145
|
const parsed = header === null ? void 0 : parse(header.trim());
|
|
142
146
|
if (parsed === void 0) throw new PaymentsVerificationFailedError({ detail: refusal("unreadable") });
|
|
143
147
|
const tolerance = options.toleranceSeconds ?? 300;
|
|
144
|
-
if (
|
|
148
|
+
if (!Number.isFinite(tolerance) || tolerance < 0 || tolerance > SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS) throw new InternalError({
|
|
149
|
+
message: "This webhook endpoint is not configured.",
|
|
150
|
+
action: `Give the Paddle webhook a freshness window between 0 and ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS} seconds.`,
|
|
151
|
+
detail: `Paddle: the signature check was given a freshness window of ${String(tolerance)} seconds, and a window must be a number from 0 to ${SIGNED_WEBHOOK_MAX_TOLERANCE_SECONDS}.`
|
|
152
|
+
});
|
|
153
|
+
const nowSeconds = Math.floor(options.now.getTime() / 1e3);
|
|
154
|
+
if (!Number.isFinite(nowSeconds)) throw new InternalError({
|
|
155
|
+
message: "This webhook endpoint is not configured.",
|
|
156
|
+
action: "Give the Paddle webhook a valid clock.",
|
|
157
|
+
detail: "Paddle: the signature check was handed a clock that is not a valid Date, so no delivery's freshness can be judged."
|
|
158
|
+
});
|
|
159
|
+
if (Math.abs(nowSeconds - parsed.timestamp) > tolerance) throw new PaymentsVerificationFailedError({ detail: refusal("stale") });
|
|
145
160
|
const key = await signingKey(options.secret, "verify");
|
|
146
161
|
const message = new TextEncoder().encode(`${parsed.timestamp}:${body}`);
|
|
147
162
|
for (const candidate of parsed.candidates) if (await crypto.subtle.verify("HMAC", key, candidate, message)) return;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { JwksCache } from "@pithy-sh/core/src/http/oidcWebhook";
|
|
3
4
|
import type { PaymentsConfig } from "../config/config";
|
|
4
5
|
import type { PaymentsRail } from "../data/rail";
|
|
5
6
|
import { type PaymentsProviderCredentials } from "../secret/registry";
|
|
@@ -56,6 +57,20 @@ export interface RailTrustOptions {
|
|
|
56
57
|
googleTransport?: GoogleHttpFetch;
|
|
57
58
|
/** A Play access token already minted, so a batch of Google refreshes pays for one. */
|
|
58
59
|
googleAccessToken?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Where the Google rail holds Google's published verification keys between deliveries.
|
|
62
|
+
*
|
|
63
|
+
* **The third kind of seam, and the only one that is about availability rather than trust or cost.** A rail
|
|
64
|
+
* is built per request, so it cannot own a store that outlives one; the webhook path resolves a key before
|
|
65
|
+
* it can check a signature; and therefore with no store an anonymous POST buys a round trip to Google,
|
|
66
|
+
* 1:1 — whether it names a `kid` Google publishes, which the held keys answer, or one nobody ever
|
|
67
|
+
* published, which only the store's refresh window does. `registerPaymentsRoutes` supplies one per
|
|
68
|
+
* registered route tree when a caller gives none; this parameter is for the caller that wants a harder
|
|
69
|
+
* bound than an isolate's memory, a store over KV or the Cache API that every isolate shares — and sharing
|
|
70
|
+
* it shares the window with it. Additive to nothing and narrowing nothing: core still fetches for a `kid`
|
|
71
|
+
* the store does not hold once the window is over, which is how key rotation stays invisible.
|
|
72
|
+
*/
|
|
73
|
+
googleJwksCache?: JwksCache;
|
|
59
74
|
/** The HTTP transport the Stripe rail reaches Stripe's API through. Defaults to `fetch`. */
|
|
60
75
|
stripeTransport?: StripeHttpFetch;
|
|
61
76
|
/** The HTTP transport the Lemon Squeezy rail reaches its API through. Defaults to `fetch`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/rails/providers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,KAAK,2BAA2B,EAAmB,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,uGAAuG;IACvG,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,6FAA6F;IAC7F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,iBAAiB,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACzC,kGAAkG;IAClG,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,8FAA8F;IAC9F,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uFAAuF;IACvF,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/rails/providers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,KAAK,2BAA2B,EAAmB,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,uGAAuG;IACvG,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,6FAA6F;IAC7F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,iBAAiB,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACzC,kGAAkG;IAClG,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,8FAA8F;IAC9F,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uFAAuF;IACvF,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAiED,+EAA+E;AAC/E,wBAAgB,gBAAgB,IAAI,SAAS,YAAY,EAAE,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,cAAc,EACtB,WAAW,EAAE,2BAA2B,EACxC,KAAK,GAAE,gBAAqB,GAC3B,oBAAoB,CAatB"}
|
package/dist/rails/providers.js
CHANGED
|
@@ -23,7 +23,8 @@ const RAIL_FACTORIES = {
|
|
|
23
23
|
google: (credentials, trust) => googleRail(railCredentials(credentials, "google"), {
|
|
24
24
|
trustedKeys: trust.googleTrustedKeys,
|
|
25
25
|
transport: trust.googleTransport,
|
|
26
|
-
accessToken: trust.googleAccessToken
|
|
26
|
+
accessToken: trust.googleAccessToken,
|
|
27
|
+
jwksCache: trust.googleJwksCache
|
|
27
28
|
}),
|
|
28
29
|
stripe: (credentials, trust) => stripeRail(railCredentials(credentials, "stripe"), { transport: trust.stripeTransport }),
|
|
29
30
|
lemonSqueezy: (credentials, trust, config) => lemonSqueezyRail(railCredentials(credentials, "lemonSqueezy"), {
|
|
@@ -22,7 +22,17 @@ import type { StripeHttpFetch } from "./api";
|
|
|
22
22
|
export interface StripeRailOptions {
|
|
23
23
|
/** The HTTP seam Stripe's API is reached through. Defaults to the runtime's `fetch`. */
|
|
24
24
|
transport?: StripeHttpFetch;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The signature freshness window, in seconds. Defaults to Stripe's own five minutes.
|
|
27
|
+
*
|
|
28
|
+
* Threaded down unchanged and validated in exactly one place: `@pithy-sh/core`'s `checkSignedWebhook`, which
|
|
29
|
+
* refuses a non-finite, negative, or over-wide window as `core/internal` before it compares anything. This
|
|
30
|
+
* layer, `webhook.ts` and `signature.ts` each re-apply a default with `??` — which catches `undefined` and
|
|
31
|
+
* never `NaN` — and none of them re-checks the number. That is deliberate: one place that refuses is better
|
|
32
|
+
* than three that each half-check, and nothing on this path can reach the comparison without going through
|
|
33
|
+
* the primitive, so there is no bypass for a second check to cover. Three copies of the bound would only be
|
|
34
|
+
* three chances for one of them to drift.
|
|
35
|
+
*/
|
|
26
36
|
toleranceSeconds?: number;
|
|
27
37
|
}
|
|
28
38
|
/** The Stripe rail. Verifies a returning Checkout Session, verifies webhooks, and creates hosted sessions. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C;;;;;;;;;;;;;;GAcG;AAEH,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B
|
|
1
|
+
{"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/rail.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAEZ,oBAAoB,EAGpB,WAAW,EAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C;;;;;;;;;;;;;;GAcG;AAEH,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,8GAA8G;AAC9G,wBAAgB,UAAU,CACxB,WAAW,EAAE,yBAAyB,EACtC,OAAO,GAAE,iBAAsB,GAC9B,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CA8ElE"}
|
|
@@ -50,7 +50,14 @@ export type StripeSignatureHeader = SignedWebhookHeader;
|
|
|
50
50
|
export interface VerifyStripeSignatureOptions {
|
|
51
51
|
/** The clock. Injected so the replay window is deterministic in tests rather than wall-clock dependent. */
|
|
52
52
|
now: Date;
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The freshness window, in seconds. Defaults to {@link STRIPE_SIGNATURE_TOLERANCE_SECONDS}.
|
|
55
|
+
*
|
|
56
|
+
* The `??` below applies that default and nothing more — a `NaN` passes it untouched, on purpose. The
|
|
57
|
+
* primitive owns the bound (`core/internal` for anything non-finite, negative, or over-wide) because it owns
|
|
58
|
+
* the comparison, and every caller on this path reaches it. See {@link ./rail.StripeRailOptions} for why the
|
|
59
|
+
* check is not repeated at each layer.
|
|
60
|
+
*/
|
|
54
61
|
toleranceSeconds?: number;
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/signature.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,uCAAuC,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,6GAA6G;AAC7G,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAQtD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAExD,iGAAiG;AACjG,MAAM,WAAW,4BAA4B;IAC3C,2GAA2G;IAC3G,GAAG,EAAE,IAAI,CAAC;IACV
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../src/rails/stripe/signature.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,uCAAuC,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,6GAA6G;AAC7G,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAQtD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAExD,iGAAiG;AACjG,MAAM,WAAW,4BAA4B;IAC3C,2GAA2G;IAC3G,GAAG,EAAE,IAAI,CAAC;IACV;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAE5F;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAWf"}
|