Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(app-connections): stop Stripe API key pagination before leaking the platform credential
Calvin0b19a1a466cd
diff --git a/backend/src/services/app-connection/stripe/stripe-connection-public-client.ts b/backend/src/services/app-connection/stripe/stripe-connection-public-client.tsindex 263bec6306..938f2c5955 100644--- a/backend/src/services/app-connection/stripe/stripe-connection-public-client.ts+++ b/backend/src/services/app-connection/stripe/stripe-connection-public-client.ts@@ -106,7 +106,21 @@ export const listStripeApiKeys = async (accountId: string): Promise<TStripeApiKe);keys.push(...(response.data?.data ?? []));- url = response.data?.next_page_url ?? undefined;++ const nextPageUrl = response.data?.next_page_url ?? undefined;++ // config.auth carries our platform key, which can act on every connected Stripe account, not a+ // per-connection token. This must be checked before that credential goes out on the next request,+ // never after, since next_page_url comes from the response body Stripe controls.+ if (nextPageUrl && !nextPageUrl.startsWith(STRIPE_API_KEYS_URL)) {+ logger.error(+ `listStripeApiKeys: next_page_url for account ${accountId} did not point at the Stripe API keys endpoint, stopped paginating`+ );+ url = undefined;+ } else {+ url = nextPageUrl;+ }+pages += 1;}diff --git a/backend/src/services/app-connection/stripe/stripe-connection-service.test.ts b/backend/src/services/app-connection/stripe/stripe-connection-service.test.tsindex 0324d8a9f5..517c1ad8ad 100644--- a/backend/src/services/app-connection/stripe/stripe-connection-service.test.ts+++ b/backend/src/services/app-connection/stripe/stripe-connection-service.test.ts@@ -74,4 +74,14 @@ describe("stripeConnectionService.listApiKeys", () => {expect(getMock.mock.calls[0][0]).toContain("limit=100");expect(getMock.mock.calls[1][0]).toBe("https://api.stripe.com/v2/iam/api_keys?page=2");});++ it("never sends the platform credential to a next_page_url outside the Stripe API keys endpoint", async () => {+ getMock.mockResolvedValueOnce(keyPage("mk_1", "https://evil.example.com/v2/iam/api_keys?page=2"));++ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument+ const keys = await makeService().listApiKeys("connection-id", {} as any);++ expect(keys.map((key) => key.id)).toEqual(["mk_1"]);+ expect(getMock).toHaveBeenCalledTimes(1);+ });});