Skip to content

Commit 2d93f56

Browse files
committed
feat(secrets): reveal visible values to members
1 parent 836b87f commit 2d93f56

7 files changed

Lines changed: 117 additions & 27 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,56 @@
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().style.webkitTextSecurity).toBe('disc')
41+
42+
act(() => input().focus())
43+
44+
expect(input().value).toBe('visible-secret')
45+
expect(input().readOnly).toBe(true)
46+
expect(input().style.webkitTextSecurity).toBe('')
47+
})
48+
49+
it('never places a withheld value in the field', () => {
50+
act(() => root.render(<SecretValueField value='hidden-secret' canEdit={false} />))
51+
52+
expect(input().value).toBe('•'.repeat(10))
53+
act(() => input().focus())
54+
expect(input().value).toBe('•'.repeat(10))
55+
})
56+
})

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { ChipInput } from '@sim/emcn'
77
const BULLET = '\u2022'
88

99
/**
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.
10+
* Viewers without reveal access receive a fixed-length mask so the secret's
11+
* length is not disclosed.
1312
*/
1413
const VIEWER_MASK_LENGTH = 10
1514

@@ -20,11 +19,11 @@ type SecretValueFieldProps = Omit<
2019
value: string
2120
onChange?: (value: string) => void
2221
/**
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).
22+
* Whether the caller may edit the value. Editors can always reveal it.
2623
*/
2724
canEdit?: boolean
25+
/** Whether a read-only caller may reveal the value on focus. */
26+
canReveal?: boolean
2827
/** Render the real value without masking, e.g. an overridden/conflicted field. */
2928
unmasked?: boolean
3029
/** Force read-only even when {@link canEdit} is true (e.g. a conflicted field). */
@@ -33,9 +32,9 @@ type SecretValueFieldProps = Omit<
3332

3433
/**
3534
* 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.
35+
* masks revealable values while unfocused, reveals them on focus, and grants
36+
* editing independently. Callers without reveal access receive a fixed-length
37+
* mask. Shared by the secrets list and secret detail page.
3938
*
4039
* Rendered as a {@link ChipInput}; the chip chrome carries the canonical 30px
4140
* chip-field height, and the caller's `className` only positions it (e.g.
@@ -46,6 +45,7 @@ export function SecretValueField({
4645
value,
4746
onChange,
4847
canEdit = true,
48+
canReveal = false,
4949
unmasked = false,
5050
readOnly = false,
5151
onFocus,
@@ -56,8 +56,9 @@ export function SecretValueField({
5656
}: SecretValueFieldProps) {
5757
const [focused, setFocused] = useState(false)
5858
const editable = canEdit && !readOnly
59-
const maskActive = canEdit && !unmasked && !focused
60-
const displayValue = canEdit ? value : BULLET.repeat(VIEWER_MASK_LENGTH)
59+
const revealable = canEdit || canReveal
60+
const maskActive = revealable && !unmasked && !focused
61+
const displayValue = revealable ? value : BULLET.repeat(VIEWER_MASK_LENGTH)
6162

6263
const mergedStyle: CSSProperties | undefined = maskActive
6364
? ({ ...style, WebkitTextSecurity: 'disc' } as CSSProperties)

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

Lines changed: 6 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,7 @@ export function SecretsManager() {
10351038
).map(([key, value]) => {
10361039
const cred = workspaceEnvKeyToCredential.get(key)
10371040
const canEditRow = canCreateWorkspaceSecret && cred?.role === 'admin'
1041+
const canRevealRow = canEditRow || Boolean(cred?.unredacted)
10381042
return (
10391043
<WorkspaceVariableRow
10401044
key={key}
@@ -1044,15 +1048,14 @@ export function SecretsManager() {
10441048
pendingKeyValue={pendingKeyValue}
10451049
hasCredential={Boolean(cred)}
10461050
canEdit={canEditRow}
1051+
canReveal={canRevealRow}
10471052
canRename={canCreateWorkspaceSecret && canEditRow}
10481053
onRenameStart={setRenamingKey}
10491054
onPendingKeyChange={setPendingKeyValue}
10501055
onRenameEnd={handleWorkspaceKeyRename}
10511056
onValueChange={handleWorkspaceValueChange}
10521057
onDelete={handleDeleteWorkspaceVar}
1053-
onViewDetails={
1054-
canCreateWorkspaceSecret && cred ? handleViewDetails : undefined
1055-
}
1058+
onViewDetails={cred ? handleViewDetails : undefined}
10561059
/>
10571060
)
10581061
})}

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'

0 commit comments

Comments
 (0)