Skip to content

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

keep sanitization order

Thiago Araujo da Silvaf6463ca1c7e5
diff --git a/backend/src/lib/validator/log-safe-text.test.ts b/backend/src/lib/validator/log-safe-text.test.ts
index 272fc2e930..0cb627a32e 100644
--- a/backend/src/lib/validator/log-safe-text.test.ts
+++ b/backend/src/lib/validator/log-safe-text.test.ts
@@ -156,6 +156,18 @@ describe("sanitizeLogPayload", () => {
expect(Object.values(sanitized).sort()).toEqual([1, 2]);
});
+ test("keeps a clean key's value under its own name when a dirty look-alike comes first", () => {
+ const sanitized = sanitizeLogPayload({
+ [`email${ZWSP}`]: "spoofed",
+ email: "real",
+ [`ab${ZWSP}`]: 1,
+ ab: 2,
+ "ab~2": 3
+ });
+
+ expect(sanitized).toEqual({ email: "real", "email~2": "spoofed", ab: 2, "ab~2": 3, "ab~3": 1 });
+ });
+
test("keeps a key of __proto__ as an own property", () => {
// Computed keys: the literal form would set the prototype as the object is built.
const sanitized = sanitizeLogPayload({ ["__proto__"]: { sub: `a${NUL}b` }, [`__pro${ZWSP}to__`]: "second" });
diff --git a/backend/src/lib/validator/log-safe-text.ts b/backend/src/lib/validator/log-safe-text.ts
index d009ee3521..10678a72db 100644
--- a/backend/src/lib/validator/log-safe-text.ts
+++ b/backend/src/lib/validator/log-safe-text.ts
@@ -154,8 +154,16 @@ export const sanitizeLogPayload = <T>(payload: T): T => {
if (Array.isArray(source)) {
source.forEach((item, index) => assign(index, item));
} else {
- const taken = new Set<string>();
- Object.entries(source as Record<string, unknown>).forEach(([key, value]) => {
+ const entries = Object.entries(source as Record<string, unknown>);
+ // Clean keys claim their names first. Otherwise a look-alike `email` with a zero-width space, listed
+ // first, would take the name and push the real field to `email~2`.
+ const cleanKeys = new Set(entries.filter(([key]) => isClean(key)).map(([key]) => key));
+ const taken = new Set(cleanKeys);
+ entries.forEach(([key, value]) => {
+ if (cleanKeys.has(key)) {
+ assign(key, value);
+ return;
+ }
const sanitizedKey = disambiguate(sanitizeLogText(key), taken);
taken.add(sanitizedKey);
assign(sanitizedKey, value);