Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions apps/sim/lib/core/security/redaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
18 changes: 18 additions & 0 deletions apps/sim/lib/core/security/redaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Comment on lines +512 to +513

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Extra secrets escape redaction

The new branch skips recursive redaction for every field beside Value. redactApiKeys also receives arbitrary JSON from block inputs and workflow outputs, not just two-column tables. For example, {"cells":{"Key":"Authorization","Value":"token","password":"secret"}} now leaves password in plain text in logs; previously it was redacted. Nested secrets beside Value also escape.

Recursively redact the copied cells before replacing Value, and add a regression test for an extra sensitive field.

How this was verified: Block inputs are parsed as JSON and passed to redactApiKeys, where the new shallow copy preserves sensitive sibling fields instead of visiting them.

} else if (typeof value === 'object' && value !== null) {
result[key] = redactApiKeys(value)
} else {
Expand Down