Skip to content

Commit 34a5300

Browse files
feat(secrets): reveal visible values to members (#7231)
* feat(secrets): reveal visible values to members * fix(secrets): harden visible value reveal * fix(secrets): reveal legacy values safely
1 parent 836b87f commit 34a5300

11 files changed

Lines changed: 211 additions & 40 deletions

File tree

apps/docs/content/docs/en/platform/credentials.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Both masking and model-bound projection match only exact values in either case.
9393

9494
Copilot's Function and code-execution tools receive a saved secret only when their code explicitly contains a valid `{{KEY}}` reference. Direct `environmentVariables.KEY` access, shell `$KEY`, dynamic names, literals, and configured-but-unused secrets do not mount a value. Code execution requires workspace write access, and the caller must be allowed to **use** the secret — the same set a workflow resolves for them: your own Personal secrets, and Workspace secrets you hold an active grant on as a Credential Member or Credential Admin, which a workspace admin holds on every key. A secret you hold no grant on does not mount, and neither does one whose grant is revoked or still pending.
9595

96-
This matches what a workflow Function block already resolves for the same person, deliberately. Being able to run a secret is not the same as being able to read it: the value stays masked under **Settings → Secrets**, and **See usage** stays visible only to that secret's admins, so a Credential Member using a secret in code is recorded for whoever can rotate it.
96+
This matches what a workflow Function block already resolves for the same person, deliberately. Being able to run a secret is not normally the same as being able to read it: Credential Members can reveal a workspace secret under **Settings → Secrets** only when a Credential Admin has enabled **Show value in logs and Chat**. **See usage** remains visible only to that secret's admins, so a Credential Member using a secret in code is recorded for whoever can rotate it.
9797

9898
Headless surfaces use their saved **Secret access** setting:
9999

@@ -118,7 +118,7 @@ Click **Details** on any secret row to open its detail view.
118118

119119
From here you can:
120120

121-
- View the **Key** and edit the **Value**
121+
- View the **Key** and reveal the **Value** when visibility is enabled; Credential Admins can edit it
122122
- Toggle **Visibility** — show the value unmasked in run output; see [Visibility](#visibility)
123123
- Edit the **Description** — an optional note telling teammates what the secret is for. Workspace secrets only; a personal secret is not shared, so it has none
124124
- Manage **Members** — invite teammates by email and assign them an **Admin** or **Member** role
@@ -135,6 +135,7 @@ By default, a secret's resolved value is masked everywhere Sim shows run output
135135
- Run logs, Chat, and code output show the real value instead of `{{KEY}}`
136136
- Files a run writes with the value in them stay readable and attachable
137137
- The Secrets API list includes the value for this secret, so external agents can read it directly instead of scraping logs
138+
- Credential Members can reveal the value under **Settings → Secrets**, without gaining permission to edit it
138139

139140
The value becomes visible to **anyone who can see this workspace's runs** — including publicly shared log links and log exports, and regardless of member restrictions on the secret itself. Only turn it on for values you'd be comfortable printing in a log.
140141

@@ -146,7 +147,7 @@ The switch applies to future runs only. Logs written while the secret was masked
146147

147148
This answers the question worth asking before rotating a key: who has been using it, inside what, and how recently.
148149

149-
Only people who can read the value can see it — a Credential Admin on a workspace secret, or the owner of a personal one. For everyone else the action is visible but disabled, because the trail names workflows, people, and run IDs, which is the same information masking withholds. Two people who each hold a personal secret under the same name see only their own runs.
150+
Only Credential Admins on a workspace secret, or the owner of a personal one, can see its usage. For everyone else the action is visible but disabled because the trail names workflows, people, and run IDs. Two people who each hold a personal secret under the same name see only their own runs.
150151

151152
<Callout>
152153
Usage is recorded independently of execution logs, so it outlives them: logs expire under your workspace's retention setting, while the record of who touched a credential does not. It records what a run resolved, subject to the recognition limits under [Execution log protection](#execution-log-protection) — a read Sim cannot attribute is left out rather than guessed at, so treat an empty trail as "nothing recognized," not proof a secret was never used.
@@ -157,7 +158,7 @@ Usage is recorded independently of execution logs, so it outlives them: logs exp
157158
| | Workspace | Personal |
158159
|---|---|---|
159160
| **Who sees the name** | All workspace members, including external workspace members | Only you |
160-
| **Who sees the value** | Workspace admins and that secret's Credential Admins | Only you |
161+
| **Who sees the value** | Workspace admins and that secret's Credential Admins; Credential Members when **Show value in logs and Chat** is enabled | Only you |
161162
| **Use in workflows and code** | Any member can use | Only you can use |
162163
| **Best for** | Production workflows, shared services | Testing, personal API keys |
163164
| **Who can edit** | Workspace admins and that secret's Credential Admins | Only you |

apps/sim/app/api/workspaces/[id]/environment/route.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('GET /api/workspaces/[id]/environment', () => {
5656
personalDecrypted: { PERSONAL: 'personal-secret', SHARED_PERSONAL: 'shared-secret' },
5757
personalOwners: { PERSONAL: 'u-1', SHARED_PERSONAL: 'owner-2' },
5858
conflicts: [],
59+
workspaceUnredactedKeys: [],
5960
})
6061
mockGetPersonalEnvKeyRawAccess.mockResolvedValue({
6162
ownedKeys: new Set(['PERSONAL']),
@@ -101,6 +102,26 @@ describe('GET /api/workspaces/[id]/environment', () => {
101102
expect(body.data.workspace.DATABASE_URL).toBe('')
102103
})
103104

105+
it('reveals an unredacted workspace value to a read-only credential member', async () => {
106+
mockGetUserEntityPermissions.mockResolvedValue('read')
107+
mockGetWorkspaceEnvKeyAdminAccess.mockResolvedValue({
108+
adminKeys: new Set<string>(),
109+
knownKeys: new Set(['OPENAI_API_KEY', 'DATABASE_URL']),
110+
})
111+
mockGetPersonalAndWorkspaceEnv.mockResolvedValue({
112+
workspaceDecrypted: { OPENAI_API_KEY: 'sk-secret', DATABASE_URL: 'postgres://secret' },
113+
personalDecrypted: {},
114+
personalOwners: {},
115+
conflicts: [],
116+
workspaceUnredactedKeys: ['OPENAI_API_KEY'],
117+
})
118+
119+
const { body } = await callGet()
120+
121+
expect(body.data.workspace.OPENAI_API_KEY).toBe('sk-secret')
122+
expect(body.data.workspace.DATABASE_URL).toBe('')
123+
})
124+
104125
it('reveals legacy keys (no per-secret ACL) only to workspace admins', async () => {
105126
mockGetUserEntityPermissions.mockResolvedValue('admin')
106127
mockGetWorkspaceEnvKeyAdminAccess.mockResolvedValue({

apps/sim/app/api/workspaces/[id]/environment/route.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,26 @@ import {
3636
const logger = createLogger('WorkspaceEnvironmentAPI')
3737

3838
/**
39-
* Restricts decrypted workspace env values to administrators. Members (including
40-
* read-only) receive the variable names with empty values so editor autocomplete
41-
* and conflict detection keep working without leaking secret values. A value is
42-
* revealed when the caller is a workspace admin (which includes organization
43-
* admins) or a per-secret credential admin of that key. Mirrors the per-key edit
44-
* gating in PUT/DELETE: if you can administer a secret, you can read it.
39+
* Reveals a workspace secret only to a workspace administrator, that secret's
40+
* credential administrator, or a caller allowed to use a secret explicitly
41+
* marked visible. The environment snapshot has already limited
42+
* `workspaceUnredactedKeys` to secrets the caller may use.
4543
*/
4644
async function maskWorkspaceEnvForViewer({
4745
workspaceDecrypted,
4846
workspaceId,
4947
userId,
5048
permission,
49+
workspaceUnredactedKeys,
5150
}: {
5251
workspaceDecrypted: Record<string, string>
5352
workspaceId: string
5453
userId: string
5554
permission: PermissionType
55+
workspaceUnredactedKeys: readonly string[]
5656
}): Promise<Record<string, string>> {
5757
const workspaceKeys = Object.keys(workspaceDecrypted)
58+
const unredactedKeys = new Set(workspaceUnredactedKeys)
5859
const { adminKeys } = await getWorkspaceEnvKeyAdminAccess({
5960
workspaceId,
6061
envKeys: workspaceKeys,
@@ -63,7 +64,7 @@ async function maskWorkspaceEnvForViewer({
6364

6465
const masked: Record<string, string> = {}
6566
for (const key of workspaceKeys) {
66-
const canViewValue = permission === 'admin' || adminKeys.has(key)
67+
const canViewValue = permission === 'admin' || adminKeys.has(key) || unredactedKeys.has(key)
6768
masked[key] = canViewValue ? workspaceDecrypted[key] : ''
6869
}
6970
return masked
@@ -119,14 +120,20 @@ export const GET = withRouteHandler(
119120
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
120121
}
121122

122-
const { workspaceDecrypted, personalDecrypted, personalOwners, conflicts } =
123-
await getPersonalAndWorkspaceEnv(userId, workspaceId)
123+
const {
124+
workspaceDecrypted,
125+
personalDecrypted,
126+
personalOwners,
127+
conflicts,
128+
workspaceUnredactedKeys,
129+
} = await getPersonalAndWorkspaceEnv(userId, workspaceId)
124130

125131
const workspace = await maskWorkspaceEnvForViewer({
126132
workspaceDecrypted,
127133
workspaceId,
128134
userId,
129135
permission,
136+
workspaceUnredactedKeys,
130137
})
131138
const personal = await maskPersonalEnvForViewer({
132139
personalDecrypted,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { act, type ComponentProps } from 'react'
5+
import { createRoot, type Root } from 'react-dom/client'
6+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7+
8+
vi.mock('@sim/emcn', () => ({
9+
ChipInput: (props: ComponentProps<'input'>) => <input {...props} />,
10+
}))
11+
12+
import { SecretValueField } from '@/app/workspace/[workspaceId]/settings/components/secrets/components/secret-value-field/secret-value-field'
13+
14+
let container: HTMLDivElement
15+
let root: Root
16+
17+
function input(): HTMLInputElement {
18+
const field = container.querySelector('input')
19+
if (!field) throw new Error('Secret value field did not render')
20+
return field
21+
}
22+
23+
beforeEach(() => {
24+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
25+
container = document.createElement('div')
26+
document.body.appendChild(container)
27+
root = createRoot(container)
28+
})
29+
30+
afterEach(() => {
31+
act(() => root.unmount())
32+
container.remove()
33+
})
34+
35+
describe('SecretValueField', () => {
36+
it('lets a read-only viewer reveal an allowed value without making it editable', () => {
37+
act(() => root.render(<SecretValueField value='visible-secret' canEdit={false} canReveal />))
38+
39+
expect(input().readOnly).toBe(true)
40+
expect(input().value).toBe('•'.repeat(10))
41+
42+
act(() => input().focus())
43+
44+
expect(input().value).toBe('visible-secret')
45+
expect(input().readOnly).toBe(true)
46+
})
47+
48+
it('never places a withheld value in the field', () => {
49+
act(() => root.render(<SecretValueField value='hidden-secret' canEdit={false} />))
50+
51+
expect(input().value).toBe('•'.repeat(10))
52+
act(() => input().focus())
53+
expect(input().value).toBe('•'.repeat(10))
54+
})
55+
56+
it('keeps an empty editable value empty while unfocused', () => {
57+
act(() => root.render(<SecretValueField value='' />))
58+
59+
expect(input().value).toBe('')
60+
})
61+
})

apps/sim/app/workspace/[workspaceId]/settings/components/secrets/components/secret-value-field/secret-value-field.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use client'
22

3-
import type { ComponentProps, CSSProperties } from 'react'
3+
import type { ComponentProps } from 'react'
44
import { useState } from 'react'
55
import { ChipInput } from '@sim/emcn'
66

77
const BULLET = '\u2022'
88

9-
/**
10-
* Viewers always see this many bullets regardless of the real value, which the
11-
* server withholds (empty string) for non-admins. A fixed length also avoids
12-
* leaking the secret's length.
13-
*/
9+
/** Fixed-length masks avoid disclosing the secret's length. */
1410
const VIEWER_MASK_LENGTH = 10
1511

1612
type SecretValueFieldProps = Omit<
@@ -20,11 +16,11 @@ type SecretValueFieldProps = Omit<
2016
value: string
2117
onChange?: (value: string) => void
2218
/**
23-
* Whether the caller may reveal (on focus) and edit the value. When `false`
24-
* the real value is never shown — only a fixed-length mask — and the field is
25-
* read-only (e.g. a non-admin viewer).
19+
* Whether the caller may edit the value. Editors can always reveal it.
2620
*/
2721
canEdit?: boolean
22+
/** Whether a read-only caller may reveal the value on focus. */
23+
canReveal?: boolean
2824
/** Render the real value without masking, e.g. an overridden/conflicted field. */
2925
unmasked?: boolean
3026
/** Force read-only even when {@link canEdit} is true (e.g. a conflicted field). */
@@ -33,9 +29,9 @@ type SecretValueFieldProps = Omit<
3329

3430
/**
3531
* The single source of truth for displaying an environment-variable value:
36-
* masks the value with bullets while unfocused, reveals it on focus for editors,
37-
* and keeps the field read-only (masked) for viewers who can't edit. Shared by
38-
* the secrets list and the secret detail page so masking never diverges.
32+
* masks revealable values while unfocused, reveals them on focus, and grants
33+
* editing independently. Callers without reveal access receive a fixed-length
34+
* mask. Shared by the secrets list and secret detail page.
3935
*
4036
* Rendered as a {@link ChipInput}; the chip chrome carries the canonical 30px
4137
* chip-field height, and the caller's `className` only positions it (e.g.
@@ -46,6 +42,7 @@ export function SecretValueField({
4642
value,
4743
onChange,
4844
canEdit = true,
45+
canReveal = false,
4946
unmasked = false,
5047
readOnly = false,
5148
onFocus,
@@ -56,12 +53,10 @@ export function SecretValueField({
5653
}: SecretValueFieldProps) {
5754
const [focused, setFocused] = useState(false)
5855
const editable = canEdit && !readOnly
59-
const maskActive = canEdit && !unmasked && !focused
60-
const displayValue = canEdit ? value : BULLET.repeat(VIEWER_MASK_LENGTH)
61-
62-
const mergedStyle: CSSProperties | undefined = maskActive
63-
? ({ ...style, WebkitTextSecurity: 'disc' } as CSSProperties)
64-
: style
56+
const revealable = canEdit || canReveal
57+
const maskActive = revealable && !unmasked && !focused
58+
const displayValue =
59+
!revealable || (maskActive && value.length > 0) ? BULLET.repeat(VIEWER_MASK_LENGTH) : value
6560

6661
return (
6762
<ChipInput
@@ -70,7 +65,7 @@ export function SecretValueField({
7065
type='text'
7166
value={displayValue}
7267
readOnly
73-
style={mergedStyle}
68+
style={style}
7469
onChange={(event) => {
7570
if (editable) onChange?.(event.target.value)
7671
}}

apps/sim/app/workspace/[workspaceId]/settings/components/secrets/components/secrets-manager/secrets-manager.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ interface WorkspaceVariableRowProps {
194194
pendingKeyValue: string
195195
hasCredential: boolean
196196
canEdit: boolean
197+
canReveal: boolean
197198
/** Renaming creates a new key + deletes the old, so it also needs create access. */
198199
canRename: boolean
199200
onRenameStart: (key: string) => void
@@ -211,6 +212,7 @@ function WorkspaceVariableRow({
211212
pendingKeyValue,
212213
hasCredential,
213214
canEdit,
215+
canReveal,
214216
canRename,
215217
onRenameStart,
216218
onPendingKeyChange,
@@ -252,6 +254,7 @@ function WorkspaceVariableRow({
252254
value={value}
253255
onChange={(next) => onValueChange(envKey, next)}
254256
canEdit={canEdit}
257+
canReveal={canReveal}
255258
name={`workspace_env_value_${envKey}_${autofillSalt}`}
256259
/>
257260
<SecretRowMenu
@@ -1035,6 +1038,8 @@ export function SecretsManager() {
10351038
).map(([key, value]) => {
10361039
const cred = workspaceEnvKeyToCredential.get(key)
10371040
const canEditRow = canCreateWorkspaceSecret && cred?.role === 'admin'
1041+
const canRevealRow =
1042+
isWorkspaceAdmin || cred?.role === 'admin' || Boolean(cred?.unredacted)
10381043
return (
10391044
<WorkspaceVariableRow
10401045
key={key}
@@ -1044,15 +1049,14 @@ export function SecretsManager() {
10441049
pendingKeyValue={pendingKeyValue}
10451050
hasCredential={Boolean(cred)}
10461051
canEdit={canEditRow}
1052+
canReveal={canRevealRow}
10471053
canRename={canCreateWorkspaceSecret && canEditRow}
10481054
onRenameStart={setRenamingKey}
10491055
onPendingKeyChange={setPendingKeyValue}
10501056
onRenameEnd={handleWorkspaceKeyRename}
10511057
onValueChange={handleWorkspaceValueChange}
10521058
onDelete={handleDeleteWorkspaceVar}
1053-
onViewDetails={
1054-
canCreateWorkspaceSecret && cred ? handleViewDetails : undefined
1055-
}
1059+
onViewDetails={cred ? handleViewDetails : undefined}
10561060
/>
10571061
)
10581062
})}

apps/sim/app/workspace/[workspaceId]/settings/secrets/[credentialId]/secret-detail.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export function SecretDetail({ workspaceId, credentialId }: SecretDetailProps) {
248248
value={valueField.value}
249249
onChange={valueField.setValue}
250250
canEdit={valueField.canEdit}
251+
canReveal={!isPersonal && credential.unredacted}
251252
unmasked={valueField.isConflicted}
252253
readOnly={valueField.isConflicted}
253254
placeholder='Enter value'

apps/sim/hooks/queries/environment.test.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vi.mock('@/lib/environment/api', () => ({
1515
fetchWorkspaceEnvironment: mockFetchWorkspaceEnvironment,
1616
}))
1717

18-
import { useWorkspaceEnvironment } from '@/hooks/queries/environment'
18+
import { environmentKeys, useWorkspaceEnvironment } from '@/hooks/queries/environment'
1919

2020
function renderWorkspaceEnvironment(workspaceId: string, enabled?: boolean) {
2121
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
@@ -59,4 +59,43 @@ describe('useWorkspaceEnvironment', () => {
5959
expect(mockFetchWorkspaceEnvironment).not.toHaveBeenCalled()
6060
unmount()
6161
})
62+
63+
it('does not retain decrypted values while a different workspace loads', () => {
64+
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
65+
const container = document.createElement('div')
66+
const root = createRoot(container)
67+
const pendingWorkspace = new Promise<never>(() => {})
68+
69+
queryClient.setQueryData(environmentKeys.workspace('workspace-1'), {
70+
workspace: { SHARED_KEY: 'workspace-1-secret' },
71+
personal: {},
72+
conflicts: [],
73+
})
74+
mockFetchWorkspaceEnvironment.mockReturnValueOnce(pendingWorkspace)
75+
76+
function Probe({ workspaceId }: { workspaceId: string }) {
77+
const { data } = useWorkspaceEnvironment(workspaceId)
78+
return <span>{data?.workspace.SHARED_KEY ?? 'loading'}</span>
79+
}
80+
81+
act(() => {
82+
root.render(
83+
<QueryClientProvider client={queryClient}>
84+
<Probe workspaceId='workspace-1' />
85+
</QueryClientProvider>
86+
)
87+
})
88+
expect(container.textContent).toBe('workspace-1-secret')
89+
90+
act(() => {
91+
root.render(
92+
<QueryClientProvider client={queryClient}>
93+
<Probe workspaceId='workspace-2' />
94+
</QueryClientProvider>
95+
)
96+
})
97+
98+
expect(container.textContent).toBe('loading')
99+
act(() => root.unmount())
100+
})
62101
})

0 commit comments

Comments
 (0)