From 710a1141bac82d8d61d5dadda7f55a58c6cd1ad9 Mon Sep 17 00:00:00 2001 From: inkyu-bae Date: Fri, 20 Nov 2026 11:21:24 +0900 Subject: [PATCH] fix(redaction): redact sensitive table rows in logged inputs Table sub-blocks store each row as { cells: { Key, Value } }, so a header named Authorization is a cell value and key-based redaction never saw it. Redact the Value of rows whose Key is a sensitive name. Signed-off-by: inkyu-bae --- apps/sim/lib/core/security/redaction.test.ts | 36 ++++++++++++++++++++ apps/sim/lib/core/security/redaction.ts | 18 ++++++++++ 2 files changed, 54 insertions(+) diff --git a/apps/sim/lib/core/security/redaction.test.ts b/apps/sim/lib/core/security/redaction.test.ts index 43b1fd24e6b..e8e60d4807b 100644 --- a/apps/sim/lib/core/security/redaction.test.ts +++ b/apps/sim/lib/core/security/redaction.test.ts @@ -458,6 +458,42 @@ describe('redactApiKeys', () => { redactApiKeys(original) expect(original).toEqual(originalCopy) }) + + it.concurrent('should redact the value of a table row whose key is sensitive', () => { + const result = redactApiKeys({ + url: 'https://example.com', + headers: [ + { id: 'h1', cells: { Key: 'Authorization', Value: 'Bearer ghp_secret' } }, + { id: 'h2', cells: { Key: 'X-GitHub-Token', Value: 'ghs_secret' } }, + { id: 'h3', cells: { Key: 'Accept', Value: 'application/json' } }, + ], + }) + + expect(result.headers).toEqual([ + { id: 'h1', cells: { Key: 'Authorization', Value: '[REDACTED]' } }, + { id: 'h2', cells: { Key: 'X-GitHub-Token', Value: '[REDACTED]' } }, + { id: 'h3', cells: { Key: 'Accept', Value: 'application/json' } }, + ]) + }) + + it.concurrent('should keep table rows without a string key unchanged', () => { + const input = { + params: [ + { id: 'p1', cells: { Key: '', Value: 'v' } }, + { id: 'p2', cells: {} }, + ], + } + + expect(redactApiKeys(input)).toEqual(input) + }) + + it.concurrent('should not mutate the original table row', () => { + const row = { id: 'h1', cells: { Key: 'Authorization', Value: 'Bearer ghp_secret' } } + + redactApiKeys({ headers: [row] }) + + expect(row.cells.Value).toBe('Bearer ghp_secret') + }) }) describe('sanitizeForLogging', () => { diff --git a/apps/sim/lib/core/security/redaction.ts b/apps/sim/lib/core/security/redaction.ts index db46e1c9208..19fb3a9ce62 100644 --- a/apps/sim/lib/core/security/redaction.ts +++ b/apps/sim/lib/core/security/redaction.ts @@ -460,6 +460,22 @@ export function isLargeDataKey(key: string): boolean { return LARGE_DATA_KEYS.has(key) } +/** + * Table sub-blocks (such as API block headers and query params) store each row as + * `{ cells: { Key, Value } }`, so a sensitive name like `Authorization` is a cell value + * rather than an object key and key-based redaction never sees it. + */ +function isSensitiveTableCells( + key: string, + value: unknown +): value is { Key: string; Value: unknown } { + if (key !== 'cells' || typeof value !== 'object' || value === null) { + return false + } + const name = (value as { Key?: unknown }).Key + return typeof name === 'string' && isSensitiveKey(name) +} + export function redactApiKeys(obj: any): any { if (obj === null || obj === undefined) { return obj @@ -493,6 +509,8 @@ export function redactApiKeys(obj: any): any { result[key] = REDACTED_MARKER } else if (isLargeDataKey(key) && typeof value === 'string') { result[key] = TRUNCATED_MARKER + } else if (isSensitiveTableCells(key, value)) { + result[key] = { ...value, Value: REDACTED_MARKER } } else if (typeof value === 'object' && value !== null) { result[key] = redactApiKeys(value) } else {