Skip to content

Commit f924edd

Browse files
authored
improvement(console): redact api keys from console store (#1020)
1 parent 073030b commit f924edd

File tree

2 files changed

+15
-9
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/console/components

2 files changed

+15
-9
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/console/components/console-entry/console-entry.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import Image from 'next/image'
1414
import { Button } from '@/components/ui/button'
1515
import { createLogger } from '@/lib/logs/console/logger'
16+
import { redactApiKeys } from '@/lib/utils'
1617
import {
1718
CodeDisplay,
1819
JSONView,
@@ -349,9 +350,10 @@ export function ConsoleEntry({ entry, consoleWidth }: ConsoleEntryProps) {
349350
// For code display, copy just the code string
350351
textToCopy = entry.input.code
351352
} else {
352-
// For regular JSON display, copy the full JSON
353+
// For regular JSON display, copy the full JSON with redaction applied
353354
const dataToCopy = showInput ? entry.input : entry.output
354-
textToCopy = JSON.stringify(dataToCopy, null, 2)
355+
const redactedData = redactApiKeys(dataToCopy)
356+
textToCopy = JSON.stringify(redactedData, null, 2)
355357
}
356358

357359
navigator.clipboard.writeText(textToCopy)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/console/components/json-view/json-view.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from 'react'
22
import { Button } from '@/components/ui/button'
3+
import { redactApiKeys } from '@/lib/utils'
34

45
interface JSONViewProps {
56
data: any
@@ -154,6 +155,9 @@ export const JSONView = ({ data }: JSONViewProps) => {
154155
y: number
155156
} | null>(null)
156157

158+
// Apply redaction to the data before displaying
159+
const redactedData = redactApiKeys(data)
160+
157161
const handleContextMenu = (e: React.MouseEvent) => {
158162
e.preventDefault()
159163
setContextMenuPosition({ x: e.clientX, y: e.clientY })
@@ -167,18 +171,18 @@ export const JSONView = ({ data }: JSONViewProps) => {
167171
}
168172
}, [contextMenuPosition])
169173

170-
if (data === null)
174+
if (redactedData === null)
171175
return <span className='font-[380] text-muted-foreground leading-normal'>null</span>
172176

173177
// For non-object data, show simple JSON
174-
if (typeof data !== 'object') {
175-
const stringValue = JSON.stringify(data)
178+
if (typeof redactedData !== 'object') {
179+
const stringValue = JSON.stringify(redactedData)
176180
return (
177181
<span
178182
onContextMenu={handleContextMenu}
179183
className='relative max-w-full overflow-hidden break-all font-[380] font-mono text-muted-foreground leading-normal'
180184
>
181-
{typeof data === 'string' ? (
185+
{typeof redactedData === 'string' ? (
182186
<TruncatedValue value={stringValue} />
183187
) : (
184188
<span className='break-all font-[380] text-muted-foreground leading-normal'>
@@ -192,7 +196,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
192196
>
193197
<button
194198
className='w-full px-3 py-1.5 text-left font-[380] text-sm hover:bg-accent'
195-
onClick={() => copyToClipboard(data)}
199+
onClick={() => copyToClipboard(redactedData)}
196200
>
197201
Copy value
198202
</button>
@@ -206,7 +210,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
206210
return (
207211
<div onContextMenu={handleContextMenu}>
208212
<pre className='max-w-full overflow-hidden whitespace-pre-wrap break-all font-mono'>
209-
<CollapsibleJSON data={data} />
213+
<CollapsibleJSON data={redactedData} />
210214
</pre>
211215
{contextMenuPosition && (
212216
<div
@@ -215,7 +219,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
215219
>
216220
<button
217221
className='w-full px-3 py-1.5 text-left font-[380] text-sm hover:bg-accent'
218-
onClick={() => copyToClipboard(data)}
222+
onClick={() => copyToClipboard(redactedData)}
219223
>
220224
Copy object
221225
</button>

0 commit comments

Comments
 (0)