Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(secret-rotation): finish the Stripe review round

Calvin550dd82094dd
diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-jwe.test.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-jwe.test.ts
deleted file mode 100644
index d8f3b64da3..0000000000
--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-jwe.test.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-import crypto from "node:crypto";
-
-import { describe, expect, it, vi } from "vitest";
-
-vi.mock("@app/lib/logger", () => ({
- logger: { error: vi.fn(), info: vi.fn(), warn: vi.fn(), debug: vi.fn() }
-}));
-
-// eslint-disable-next-line import/first
-import { decryptStripeJwe, generateStripeEncryptionKeyPair, readStripeSecret } from "./stripe-api-key-jwe";
-
-/** Builds the compact JWE Stripe would return, so the test proves the real unwrap path. */
-const encryptJwe = (
- plaintext: string,
- publicKeyPem: string,
- { alg = "RSA-OAEP", enc = "A256GCM" }: { alg?: string; enc?: string } = {}
-) => {
- const header = Buffer.from(JSON.stringify({ alg, enc })).toString("base64url");
- const contentKey = crypto.randomBytes(32);
- const wrapped = crypto.publicEncrypt(
- {
- key: publicKeyPem,
- padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
- oaepHash: alg === "RSA-OAEP" ? "sha1" : "sha256"
- },
- contentKey
- );
- const iv = crypto.randomBytes(12);
- const cipher = crypto.createCipheriv("aes-256-gcm", contentKey, iv);
- cipher.setAAD(Buffer.from(header, "ascii"));
- const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
-
- return [
- header,
- wrapped.toString("base64url"),
- iv.toString("base64url"),
- ciphertext.toString("base64url"),
- cipher.getAuthTag().toString("base64url")
- ].join(".");
-};
-
-describe("decryptStripeJwe", () => {
- it("round-trips both algorithms Stripe may use", async () => {
- const { publicKey, privateKey } = await generateStripeEncryptionKeyPair();
-
- for (const alg of ["RSA-OAEP", "RSA-OAEP-256"]) {
- const jwe = encryptJwe("rk_live_secret", publicKey, { alg });
- expect(decryptStripeJwe(jwe, privateKey)).toBe("rk_live_secret");
- }
- });
-
- it("rejects a JWE without exactly five segments", async () => {
- const { privateKey } = await generateStripeEncryptionKeyPair();
-
- expect(() => decryptStripeJwe("a.b.c", privateKey)).toThrow(/5 JWE segments, got 3/);
- });
-
- it.each([{ alg: "RSA1_5" }, { enc: "A128GCM" }])(
- "names an unsupported algorithm rather than guessing (%o)",
- async (header) => {
- const { publicKey, privateKey } = await generateStripeEncryptionKeyPair();
- const jwe = encryptJwe("rk_live_secret", publicKey, header);
-
- expect(() => decryptStripeJwe(jwe, privateKey)).toThrow(/RSA1_5|A128GCM/);
- }
- );
-
- it("rejects an authentication tag that is not the 16 bytes A256GCM requires", async () => {
- const { publicKey, privateKey } = await generateStripeEncryptionKeyPair();
- const segments = encryptJwe("rk_live_secret", publicKey).split(".");
- segments[4] = Buffer.from(segments[4], "base64url").subarray(0, 12).toString("base64url");
-
- expect(() => decryptStripeJwe(segments.join("."), privateKey)).toThrow(/authentication tag is 12 bytes/);
- });
-
- it("fails a tampered ciphertext with a message an administrator can act on, and logs the cause", async () => {
- const { logger } = await import("@app/lib/logger");
- const { publicKey, privateKey } = await generateStripeEncryptionKeyPair();
- const segments = encryptJwe("rk_live_secret", publicKey).split(".");
- segments[4] = Buffer.alloc(16).toString("base64url");
-
- expect(() => decryptStripeJwe(segments.join("."), privateKey)).toThrow(/could not decrypt the secret/);
- expect(logger.error).toHaveBeenCalledWith(expect.any(Error), expect.stringContaining("decryptStripeJwe"));
- });
-});
-
-describe("readStripeSecret", () => {
- // Observed against a real sandbox: supplying a public key makes Stripe return the JWE and the
- // plaintext token together, so this is the ordinary case rather than an edge one.
- it("decrypts the JWE even when Stripe also returns the plaintext token", async () => {
- const { publicKey, privateKey } = await generateStripeEncryptionKeyPair();
- const jwe = encryptJwe("rk_test_from_jwe", publicKey);
-
- expect(readStripeSecret({ token: "rk_test_plain", encrypted_secret: { ciphertext: jwe } }, privateKey)).toBe(
- "rk_test_from_jwe"
- );
- });
-
- it("falls back to the plaintext token when Stripe returns no ciphertext", async () => {
- const { privateKey } = await generateStripeEncryptionKeyPair();
-
- expect(readStripeSecret({ token: "rk_test_plain", encrypted_secret: null }, privateKey)).toBe("rk_test_plain");
- });
-
- it("throws when Stripe returns neither", async () => {
- const { privateKey } = await generateStripeEncryptionKeyPair();
-
- expect(() => readStripeSecret({}, privateKey)).toThrow(/without a secret/);
- expect(() => readStripeSecret(undefined, privateKey)).toThrow(/without a secret/);
- });
-});
diff --git a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts
index a6b5dbc044..2e530234ab 100644
--- a/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/stripe-api-key/stripe-api-key-rotation-fns.ts
@@ -174,8 +174,7 @@ export const stripeApiKeyRotationFactory: TRotationFactory<
...credentials.filter((_, index) => index === activeIndex)
];
- for (const { keyId } of retirementOrder) {
- // eslint-disable-next-line no-await-in-loop
+ for await (const { keyId } of retirementOrder) {
await $retireKey(keyId);
}
diff --git a/docs/self-hosting/configuration/envars.mdx b/docs/self-hosting/configuration/envars.mdx
index 182639bf7e..1a322ec357 100644
--- a/docs/self-hosting/configuration/envars.mdx
+++ b/docs/self-hosting/configuration/envars.mdx
@@ -130,14 +130,12 @@ Example values:
Defaults to `false` so an operator-configured forward proxy keeps working.
-{/* vale Infisical.Contractions = NO */}
<Note>
- Enable this only if your instance does **not** rely on an outbound
+ Enable this only if your instance has **no** outbound
`HTTP_PROXY` / `HTTPS_PROXY` for egress. When a proxy is in use, the IP pin
can't extend past the proxy (the proxy resolves the target itself), so
leaving this off is the correct choice for proxied deployments.
</Note>
-{/* vale Infisical.Contractions = YES */}
</ParamField>
<ParamField
@@ -282,14 +280,12 @@ your own `psql` sessions. If you're close to the limit, **lower `DB_POOL_MAX`**
connections wastes it. If instead you see queries queueing while your database is idle, the pool is too small
and raising it is the right move.
-{/* vale Infisical.Contractions = NO */}
<Tip>
Prefer scaling reads with `DB_READ_REPLICAS` over enlarging the primary pool. A connection pooler such as
PgBouncer or RDS Proxy is only worth the extra hop and failure domain once instance count alone pushes you
- near `max_connections`, and note that a pooler in transaction mode does **not** reclaim connections held
+ near `max_connections`, and note that a pooler in transaction mode **never** reclaims connections held
open inside a transaction.
</Tip>
-{/* vale Infisical.Contractions = YES */}
<ParamField query="DB_POOL_MIN" type="int" default="0" optional>
Minimum connections kept open in the primary database pool. `0` lets idle connections close, which is
@@ -970,7 +966,7 @@ You can configure third-party app connections for re-use across Infisical Projec
</ParamField>
<ParamField query="INF_APP_CONNECTION_STRIPE_OAUTH_AUTHORIZE_URL" type="string" default="none" optional>
- Overrides the install link, which is otherwise derived from the Client ID above. Set it to the test-mode or sandbox link from the Stripe dashboard when the secret key below is not a live-mode key.
+ Leave this unset for a published Stripe App. Infisical builds the install link from the Client ID above, and takes the redirect URI from the address your instance is served on. Set it only when the secret key below is a test-mode or sandbox key, using that mode's install link from the Stripe dashboard.
</ParamField>
<ParamField query="INF_APP_CONNECTION_STRIPE_SECRET_KEY" type="string" default="none" optional>