Skip to content

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

fix ansi check

Thiago Araujo da Silva0ddcae63259c
diff --git a/backend/src/lib/validator/log-safe-text.test.ts b/backend/src/lib/validator/log-safe-text.test.ts
index 304c1dd983..149ca5869b 100644
--- a/backend/src/lib/validator/log-safe-text.test.ts
+++ b/backend/src/lib/validator/log-safe-text.test.ts
@@ -64,6 +64,13 @@ describe("containsLogUnsafeCharacters", () => {
expect(containsLogUnsafeCharacters(value)).toBe(true);
expect(containsLogUnsafeCharacters(value)).toBe(true);
});
+
+ // Both functions share the global ANSI pattern, so a check must not leave a lastIndex behind that
+ // makes a later, shorter sanitize skip its sequences.
+ test("does not break a later sanitize of a shorter value", () => {
+ expect(containsLogUnsafeCharacters(`${"x".repeat(400)}${ESC}[31m`)).toBe(true);
+ expect(sanitizeLogText(`${ESC}[31mab${ESC}[0m`)).toBe("ab");
+ });
});
describe("sanitizeLogPayload", () => {
diff --git a/backend/src/lib/validator/log-safe-text.ts b/backend/src/lib/validator/log-safe-text.ts
index 08fb16ede0..9d6373d91a 100644
--- a/backend/src/lib/validator/log-safe-text.ts
+++ b/backend/src/lib/validator/log-safe-text.ts
@@ -64,9 +64,6 @@ export const LOG_UNSAFE_TEXT_MESSAGE = "Value cannot contain control, escape, bi
export const containsLogUnsafeCharacters = (value: string, { allowMultiline = false } = {}): boolean => {
if (!UNSAFE_SCREEN.test(value)) return false;
- ANSI_ESCAPE_PATTERN.lastIndex = 0;
- if (ANSI_ESCAPE_PATTERN.test(value)) return true;
-
return Array.from(value).some((character) => {
const code = character.codePointAt(0) ?? 0;
if (allowMultiline && LINE_BREAKS.has(code)) return false;