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
solve secret redaction issues
Matheus Nogueirabaa0931971a2
diff --git a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/pty-expect-engine.ts b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/pty-expect-engine.tsindex 01ebf40574..1d3065823d 100644--- a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/pty-expect-engine.ts+++ b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/pty-expect-engine.ts@@ -13,7 +13,9 @@ export type TInteractiveShellStream = {};const createTranscript = (secrets: (string | undefined)[]) => {- const knownSecrets = secrets.filter((secret): secret is string => Boolean(secret));+ const knownSecrets = secrets+ .filter((secret): secret is string => Boolean(secret))+ .sort((a, b) => b.length - a.length);const redact = (value: string) =>knownSecrets.reduce((redacted, secret) => redacted.replaceAll(secret, "***"), value);@@ -23,6 +25,7 @@ const createTranscript = (secrets: (string | undefined)[]) => {return {append: (chunk: string) => {text += chunk;+ text = redact(text);if (text.length > MAX_TRANSCRIPT_SIZE) {text = text.slice(-MAX_TRANSCRIPT_SIZE);truncated = true;diff --git a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.test.ts b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.test.tsindex ba9392974b..f242645d3b 100644--- a/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.test.ts+++ b/backend/src/ee/services/secret-rotation-v2/unix-linux-local-account-rotation/unix-linux-local-account-rotation-fns.test.ts@@ -168,6 +168,25 @@ describe("runManagedPasswordChange", () => {expect((error as Error).message).not.toContain("\ufffd");});+ test("redacts overlapping secrets when one password is a substring of the other", async () => {+ const shortPassword = "secret";+ const longPassword = "my-secret-value";+ const fake = createFakeStream();+ const result = runManagedPasswordChange(fake.stream, shortPassword, longPassword);++ // The sudo prompt echoes the long password (which contains the short one as a substring),+ // then the session closes without completing passwd.+ fake.feed(`[sudo] password for svc: ${longPassword}\r\n`);+ fake.feed(`New password: ${shortPassword}\r\n`);+ fake.close();++ const error = await result.catch((err: unknown) => err);++ expect(error).toBeInstanceOf(Error);+ expect((error as Error).message).not.toContain(shortPassword);+ expect((error as Error).message).not.toContain(longPassword);+ });+test("rejects with sudoers guidance when sudo asks for a password we do not have", async () => {const fake = createFakeStream();const result = runManagedPasswordChange(fake.stream, ROTATED_SENTINEL);@@ -222,6 +241,29 @@ describe("runSelfPasswordChange", () => {expect((error as Error).message).not.toContain(ROTATED_SENTINEL);expect((error as Error).message).toContain("***");});++ test("redacts a password that would straddle the 4 KiB transcript boundary", async () => {+ const fake = createFakeStream();+ const result = runSelfPasswordChange(fake.stream, CURRENT_SENTINEL, ROTATED_SENTINEL);++ // Fill the transcript so the secret sits right at the 4 KiB truncation point.+ // MAX_TRANSCRIPT_SIZE is 4096 internally; we pad with filler lines, then echo+ // the password so it would straddle the boundary if redaction happened after truncation.+ const fillerSize = 4096 - Math.floor(ROTATED_SENTINEL.length / 2);+ const filler = "x".repeat(fillerSize);++ fake.feed(filler);+ fake.feed("Current password: ");+ fake.feed(`${CURRENT_SENTINEL}\r\nNew password: `);+ fake.feed(`${ROTATED_SENTINEL}\r\n`);+ fake.close();++ const error = await result.catch((err: unknown) => err);++ expect(error).toBeInstanceOf(Error);+ expect((error as Error).message).not.toContain(CURRENT_SENTINEL);+ expect((error as Error).message).not.toContain(ROTATED_SENTINEL);+ });});describe("runSuLoginVerification", () => {