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
fix(audit-log): write sanitized metadata keys as own properties
Vlad Ligai378d706fef1b
diff --git a/backend/src/lib/validator/log-safe-text.test.ts b/backend/src/lib/validator/log-safe-text.test.tsindex dc41cb92a4..bee8397e7e 100644--- a/backend/src/lib/validator/log-safe-text.test.ts+++ b/backend/src/lib/validator/log-safe-text.test.ts@@ -110,6 +110,24 @@ describe("sanitizeLogPayload", () => {expect(Object.values(sanitized).sort()).toEqual([1, 2]);});+ test("keeps a key of __proto__ as an own property", () => {+ // Plain assignment hits the inherited setter and the field never reaches the stored record.+ // Computed keys, because the literal form would set the prototype as the object is built.+ const sanitized = sanitizeLogPayload({+ ["__proto__"]: { sub: `a${NUL}b` },+ [`__pro${ZWSP}to__`]: "second",+ ok: 1+ }) as Record<string, unknown>;++ const roundTripped = JSON.parse(JSON.stringify(sanitized)) as Record<string, unknown>;+ const entry = (key: string) => Object.entries(roundTripped).find(([name]) => name === key)?.[1];++ expect(Object.keys(roundTripped).sort()).toEqual(["__proto__", "__proto__~2", "ok"]);+ expect(entry("__proto__")).toEqual({ sub: "ab" });+ expect(entry("__proto__~2")).toBe("second");+ expect(roundTripped.ok).toBe(1);+ });+test("whitespace controls collapse to a single space, preserving word boundaries", () => {expect(sanitizeLogText(`approved by${String.fromCharCode(10)}ops`)).toBe("approved by ops");expect(sanitizeLogText(`one${String.fromCharCode(13)}${String.fromCharCode(10)}two`)).toBe("one two");diff --git a/backend/src/lib/validator/log-safe-text.ts b/backend/src/lib/validator/log-safe-text.tsindex 79954b5ca5..5d4439bafc 100644--- a/backend/src/lib/validator/log-safe-text.ts+++ b/backend/src/lib/validator/log-safe-text.ts@@ -118,18 +118,26 @@ export const sanitizeLogPayload = <T>(payload: T): T => {while (pending.length) {const [source, target] = pending.pop()!;+ // defineProperty rather than assignment: a key of `__proto__` hits the inherited setter, which+ // sets the prototype instead of writing an own property and drops the field from the serialized+ // record. Metadata keys can come from a third party, since `oidcClaimsReceived` is whatever the+ // IdP returned.+ const put = (key: string | number, value: unknown) => {+ Object.defineProperty(target, key, { value, enumerable: true, writable: true, configurable: true });+ };+const assign = (key: string | number, value: unknown) => {if (typeof value === "string") {- (target as Record<string | number, unknown>)[key] = sanitizeLogText(value);+ put(key, sanitizeLogText(value));return;}if (value !== null && typeof value === "object") {const child = emptyLike(value);- (target as Record<string | number, unknown>)[key] = child;+ put(key, child);pending.push([value, child]);return;}- (target as Record<string | number, unknown>)[key] = value;+ put(key, value);};if (Array.isArray(source)) {diff --git a/backend/src/server/lib/audit-safe-text-schema.test.ts b/backend/src/server/lib/audit-safe-text-schema.test.tsindex 37516ed1e4..21a6c22762 100644--- a/backend/src/server/lib/audit-safe-text-schema.test.ts+++ b/backend/src/server/lib/audit-safe-text-schema.test.ts@@ -75,11 +75,10 @@ describe("routes that feed audit metadata keep the wrapper", () => {["ee/routes/v1/pam-routers/pam-access-request-router.ts", 1]])("%s wraps its reason fields as multiline", (file, expected) => {const source = read(file);- const reasonFields = source.match(/reason: /g) ?? [];const wrapped = source.match(/reason: auditSafeText\(.*allowMultiline: true/g) ?? [];+ // The count is the guard: a wrapper dropped from a field, or the multiline flag flipped off,+ // takes it below the expected number.expect(wrapped).toHaveLength(expected);- // Every request-body `reason:` on these routers goes through the wrapper.- expect(reasonFields.length).toBeGreaterThanOrEqual(wrapped.length);});});