Skip to content

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

only redact valeus on read

Matheus Nogueirab93ef4b21632
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.ts
index 1d3065823d..12e4b4a73a 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
@@ -19,20 +19,24 @@ const createTranscript = (secrets: (string | undefined)[]) => {
const redact = (value: string) =>
knownSecrets.reduce((redacted, secret) => redacted.replaceAll(secret, "***"), value);
- let text = "";
- let truncated = false;
+ // Raw text is kept unredacted so a secret split across two data events is
+ // still intact when redact() runs. The buffer lives only for the duration
+ // of one runExpectSession call (bounded by SHELL_TIMEOUT and the overflow
+ // check on the unmatched buffer), so it needs no independent cap.
+ let raw = "";
return {
append: (chunk: string) => {
- text += chunk;
- text = redact(text);
- if (text.length > MAX_TRANSCRIPT_SIZE) {
- text = text.slice(-MAX_TRANSCRIPT_SIZE);
- truncated = true;
- }
+ raw += chunk;
},
redact,
- read: () => (truncated ? `...${redact(text)}` : redact(text))
+ read: () => {
+ const redacted = redact(raw);
+ if (redacted.length > MAX_TRANSCRIPT_SIZE) {
+ return `...${redacted.slice(-MAX_TRANSCRIPT_SIZE)}`;
+ }
+ return redacted;
+ }
};
};
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.ts
index f242645d3b..b8988b1b28 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
@@ -187,6 +187,27 @@ describe("runManagedPasswordChange", () => {
expect((error as Error).message).not.toContain(longPassword);
});
+ test("redacts a secret split across two data events when a shorter secret overlaps", async () => {
+ const shortPassword = "secret";
+ const longPassword = "my-secret-value";
+ const fake = createFakeStream();
+ const result = runManagedPasswordChange(fake.stream, shortPassword, longPassword);
+
+ // The network splits the echoed long password across two chunks, right
+ // through the shorter secret. An eager per-chunk redactor would replace
+ // "secret" in the first chunk, leaving "-value" visible in the second.
+ fake.feed("[sudo] password for svc: my-secret");
+ fake.feed(`-value\r\nNew 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);
+ expect((error as Error).message).not.toContain("-value");
+ });
+
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);