@devries-cameron20 / t3code-1 / commits / 187781e9a0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(settings): removing a secret provider clears the fields that used it (#31651)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 5, 2026 at 15:30 UTC 187781e9a0f06fd44c6d1780579ba6d58229d99f
9 files changed +342 -8
apps/server/src/auth/RpcAuthorization.test.ts
+6
@@ -192,6 +192,12 @@ describe("settings mutation authorization", () => {
192 providerInstanceMutation,
193 }).pipe(Effect.flip),
194 ).toMatchObject({ requiredPermission: AuthSettingsWriteScope });
195 + // Removing a secret provider clears settings fields that read from it.
196 + expect(
197 + yield* client[WS_METHODS.serverUpdateSettings]({
198 + patch: { secretProviders: { [SecretProviderId.make("personal")]: null } },
199 + }).pipe(Effect.flip),
200 + ).toMatchObject({ requiredPermission: AuthSettingsWriteScope });
201 expect(handled).toBe(2);
202 }).pipe(Effect.scoped),
203 );
apps/server/src/policy/managedProviders.ts
+2 -1
@@ -206,7 +206,8 @@ const sameVariable = (
206 left === right ||
207 (left !== undefined &&
208 right !== undefined &&
209 - left.value === right.value &&
209 + // A secret reference is an object, and a decoded copy is never the stored one.
210 + sameValue(left.value, right.value) &&
211 left.sensitive === right.sensitive);
212
213 const pinnedFields = (pin: ManagedProviderInstance): ReadonlyArray<PinnedConfigField> =>
apps/server/src/serverSettings.test.ts
+110
@@ -1716,6 +1716,86 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("server settings"
1716 }).pipe(Effect.provide(layerServerSettingsWithSecrets())),
1717 );
1718
1719 + it.effect("removing a secret provider unsets every field that read from it", () =>
1720 + Effect.gen(function* () {
1721 + const service = yield* ServerSettingsModule.ServerSettingsService;
1722 + const personal = (reference: string) => ({
1723 + provider: SecretProviderId.make("personal"),
1724 + reference: `op://Private/${reference}`,
1725 + });
1726 + const work = { provider: SecretProviderId.make("work"), reference: "op://Work/token" };
1727 + const instanceId = ProviderInstanceId.make("antigravity_refs");
1728 + const hub = UsageLimitSourceId.make("hub");
1729 + yield* decodeServerSettingsPatch({
1730 + secretProviders: {
1731 + personal: { kind: "one_password", label: "Personal", config: { account: "my" } },
1732 + work: { kind: "one_password", label: "Work", config: { account: "work" } },
1733 + },
1734 + }).pipe(Effect.flatMap(service.updateSettings));
1735 + yield* service.updateSettings({
1736 + providerInstances: {
1737 + [instanceId]: {
1738 + driver: ProviderDriverKind.make("antigravity"),
1739 + environment: [
1740 + { name: "API_TOKEN", value: personal("Antigravity/env"), sensitive: true },
1741 + { name: "WORK_TOKEN", value: work, sensitive: true },
1742 + { name: "PLAIN", value: "kept", sensitive: false },
1743 + ],
1744 + },
1745 + },
1746 + sourceControlHosts: {
1747 + bitbucket: { accessToken: personal("Bitbucket/token") },
1748 + github: { tokens: { "github.com": personal("GitHub/token"), "ghe.acme.test": work } },
1749 + },
1750 + usageLimitSources: {
1751 + [hub]: {
1752 + kind: "cliproxy",
1753 + url: "https://hub.test",
1754 + managementKey: personal("Hub/key"),
1755 + enabled: true,
1756 + },
1757 + },
1758 + easDeviceHosts: [
1759 + {
1760 + kind: "eas",
1761 + id: "eas",
1762 + label: "EAS Simulator",
1763 + accessToken: personal("Expo/token"),
1764 + maxSessionMinutes: 30,
1765 + idleMinutes: 10,
1766 + maxConcurrentSessions: 2,
1767 + },
1768 + ],
1769 + });
1770 +
1771 + // An older client's save echoes a reference it cannot decode as the redacted marker.
1772 + const removed = yield* service.updateSettings({
1773 + secretProviders: { [SecretProviderId.make("personal")]: null },
1774 + usageLimitSources: {
1775 + [hub]: {
1776 + kind: "cliproxy",
1777 + url: "https://hub.test",
1778 + managementKey: SECRET_REDACTED,
1779 + enabled: true,
1780 + },
1781 + },
1782 + });
1783 + assert.notInclude(JSON.stringify(removed), "op://Private");
1784 + assert.deepEqual(removed.providerInstances[instanceId]?.environment, [
1785 + { name: "WORK_TOKEN", value: work, sensitive: true },
1786 + { name: "PLAIN", value: "kept", sensitive: false },
1787 + ]);
1788 + assert.equal(removed.sourceControlHosts.bitbucket?.accessToken, "");
1789 + assert.deepEqual(removed.sourceControlHosts.github?.tokens, {
1790 + "github.com": "",
1791 + "ghe.acme.test": work,
1792 + });
1793 + assert.equal(removed.usageLimitSources[hub]?.managementKey, "");
1794 + assert.equal(removed.easDeviceHosts[0]?.accessToken, "");
1795 + assert.deepEqual(Object.keys(removed.secretProviders), ["work"]);
1796 + }).pipe(Effect.provide(layerServerSettingsWithSecrets())),
1797 + );
1798 +
1799 it.effect("knows every strictly decoded field that can hold a secret reference", () =>
1800 Effect.sync(() => {
1801 // Shipped clients decode these as strings. Each must be covered by the older-client case above.
@@ -2731,6 +2811,36 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))(
2811 );
2812 const restored = yield* withPolicy(undefined, (service) => service.getSettings);
2813 assert.equal(restored.providerInstances[claudeId]?.environment?.[0]?.value, token.value);
2814 +
2815 + // Removing a secret provider still clears a hidden variable that read from it.
2816 + const reference = {
2817 + provider: SecretProviderId.make("personal"),
2818 + reference: "op://Private/Anthropic/key",
2819 + };
2820 + yield* withPolicy(undefined, (service) =>
2821 + decodeServerSettingsPatch({
2822 + secretProviders: {
2823 + personal: { kind: "one_password", label: "Personal", config: { account: "my" } },
2824 + },
2825 + }).pipe(
2826 + Effect.flatMap(service.updateSettings),
2827 + Effect.andThen(
2828 + service.updateProviderInstance({
2829 + operation: "upsert",
2830 + instanceId: claudeId,
2831 + instance: {
2832 + driver: claude,
2833 + environment: [{ name: token.name, value: reference, sensitive: true }],
2834 + },
2835 + }),
2836 + ),
2837 + ),
2838 + );
2839 + yield* withPolicy(policy, (service) =>
2840 + service.updateSettings({ secretProviders: { [reference.provider]: null } }),
2841 + );
2842 + const cleared = yield* withPolicy(undefined, (service) => service.getSettings);
2843 + assert.notInclude(JSON.stringify(cleared), "op://Private");
2844 }).pipe(Effect.provide(shared));
2845 });
2846
apps/server/src/serverSettings.ts
+9 -2
@@ -65,6 +65,7 @@ import {
65 import {
66 mapSettingsSecrets,
67 mapSettingsSecretValues,
68 + withoutRemovedSecretProviderReferences,
69 SECRET_REDACTED,
70 type SettingsSecret,
71 } from "./settingsSecrets.ts";
@@ -1171,7 +1172,9 @@ const make = Effect.gen(function* () {
1172 cause: parseFailure.value,
1173 });
1174 }
1174 - const updated = yield* update(current);
1175 + // An older client echoes a reference as the redacted marker; restore it before vetting so
1176 + // a removed provider's reference is cleared below rather than restored by persistence.
1177 + const updated = withEchoedSecretReferences(current, yield* update(current));
1178 // Vet before secrets: a variable the policy hides from clients is not one they removed.
1179 const vetted = managed.vetWrite(current, yield* normalizeServerSettings(updated), patch);
1180 if (vetted._tag === "Locked") {
@@ -1200,7 +1203,11 @@ const make = Effect.gen(function* () {
1203 managedBy: managedPolicy?.organization,
1204 });
1205 }
1203 - const persisted = yield* persistSettingsSecrets(current, vettedProviders.settings);
1206 + // After vetting, which can keep stored variables a policy hides from clients.
1207 + const persisted = yield* persistSettingsSecrets(
1208 + current,
1209 + withoutRemovedSecretProviderReferences(current, vettedProviders.settings),
1210 + );
1211 const next = yield* normalizeServerSettings(persisted.settings);
1212 const materializedNext = yield* Effect.uninterruptibleMask(() =>
1213 Effect.gen(function* () {
apps/server/src/settingsSecrets.ts
+30
@@ -239,3 +239,33 @@ function mapSecretFieldGroups(
239 simlockDeviceHosts,
240 };
241 }
242 +
243 +/**
244 + * `next` with every secret reference to a secret provider that `current` has and `next` dropped
245 + * unset: a credential field becomes empty, and a provider variable holding one is removed.
246 + */
247 +export function withoutRemovedSecretProviderReferences(
248 + current: ServerSettings,
249 + next: ServerSettings,
250 +): ServerSettings {
251 + const removed = new Set(
252 + Object.keys(current.secretProviders).filter((id) => !Object.hasOwn(next.secretProviders, id)),
253 + );
254 + if (removed.size === 0) return next;
255 + const isRemoved = (value: unknown) => isSecretReference(value) && removed.has(value.provider);
256 + const fields = mapSettingsSecretValues(next, (value) => (isRemoved(value) ? "" : value));
257 + return {
258 + ...fields,
259 + providerInstances: Object.fromEntries(
260 + Object.entries(fields.providerInstances).map(([instanceId, instance]) => [
261 + instanceId,
262 + instance.environment?.some((variable) => isRemoved(variable.value))
263 + ? {
264 + ...instance,
265 + environment: instance.environment.filter((variable) => !isRemoved(variable.value)),
266 + }
267 + : instance,
268 + ]),
269 + ),
270 + };
271 +}
apps/web/src/components/settings/SecretsSettings.logic.test.ts new
+51
@@ -0,0 +1,51 @@
1 +import { ServerSettings } from "@t3tools/contracts";
2 +import * as Schema from "effect/Schema";
3 +import { expect, it } from "vite-plus/test";
4 +
5 +import { secretProviderUses } from "./SecretsSettings.logic";
6 +
7 +const personal = (reference: string) => ({ provider: "personal", reference });
8 +const work = { provider: "work", reference: "op://Work/token" };
9 +
10 +const settings = Schema.decodeSync(ServerSettings)({
11 + providerInstances: {
12 + antigravity_work: {
13 + driver: "antigravity",
14 + displayName: "Antigravity Work",
15 + environment: [
16 + { name: "API_TOKEN", value: "", secret: personal("op://a/env") },
17 + { name: "OTHER_TOKEN", value: "", secret: work },
18 + ],
19 + },
20 + codex_plain: {
21 + driver: "codex",
22 + environment: [{ name: "CODEX_TOKEN", value: "", secret: personal("op://c/env") }],
23 + },
24 + },
25 + sourceControlHosts: {
26 + github: { tokens: { "github.com": personal("op://gh"), "ghe.acme.test": work } },
27 + },
28 + usageLimitSources: {
29 + hub: { kind: "cliproxy", url: "https://hub.test", managementKey: personal("op://hub") },
30 + },
31 + easDeviceHosts: [
32 + { kind: "eas", id: "eas", label: "EAS Simulator", accessToken: personal("op://expo") },
33 + ],
34 +});
35 +
36 +it.each([
37 + [
38 + "personal",
39 + [
40 + "Antigravity Work · API_TOKEN",
41 + "Codex · CODEX_TOKEN",
42 + "GitHub · github.com",
43 + "https://hub.test · Management Key",
44 + "EAS Simulator · Access Token",
45 + ],
46 + ],
47 + ["work", ["Antigravity Work · OTHER_TOKEN", "GitHub · ghe.acme.test"]],
48 + ["unused", []],
49 +])("lists what reads from secret provider %s", (providerId, uses) => {
50 + expect(secretProviderUses(settings, providerId).map((use) => use.label)).toEqual(uses);
51 +});
apps/web/src/components/settings/SecretsSettings.logic.ts new
+90
@@ -0,0 +1,90 @@
1 +import {
2 + EasDeviceHostConfig,
3 + isSecretReference,
4 + secretReferencesInSettings,
5 + type ServerSettings,
6 + UsageLimitSourceConfig,
7 +} from "@t3tools/contracts";
8 +import { getProviderClient } from "@t3tools/client-runtime/provider-clients";
9 +import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
10 +
11 +import { deriveProviderSettingsFields, type SettingsFormDefinition } from "./ProviderSettingsForm";
12 +
13 +type SecretUseSettings = Pick<
14 + ServerSettings,
15 + "providerInstances" | "sourceControlHosts" | "usageLimitSources" | "easDeviceHosts"
16 +>;
17 +
18 +interface SecretProviderUse {
19 + readonly id: string;
20 + readonly label: string;
21 +}
22 +
23 +/** What reads from secret provider `providerId`, one readable name per field, in settings order. */
24 +export function secretProviderUses(
25 + settings: SecretUseSettings,
26 + providerId: string,
27 +): ReadonlyArray<SecretProviderUse> {
28 + const uses = (
29 + definition: SettingsFormDefinition,
30 + ownerId: string,
31 + owner: string,
32 + value: unknown,
33 + ): ReadonlyArray<SecretProviderUse> => {
34 + const labels = new Map(
35 + deriveProviderSettingsFields(definition).map((field) => [field.key, field.label] as const),
36 + );
37 + return secretReferencesInSettings(definition.settingsSchema, value).flatMap(
38 + ({ field, key, reference }) =>
39 + reference.provider === providerId
40 + ? [
41 + {
42 + id: `${ownerId}:${field}:${key ?? ""}`,
43 + label: `${owner} · ${key ?? labels.get(field) ?? field}`,
44 + },
45 + ]
46 + : [],
47 + );
48 + };
49 +
50 + return [
51 + ...Object.entries(settings.providerInstances).flatMap(([instanceId, instance]) => {
52 + const client = getProviderClient(instance.driver);
53 + const owner = instance.displayName ?? client?.label ?? instanceId;
54 + return [
55 + ...(client ? uses(client, `provider:${instanceId}`, owner, instance.config) : []),
56 + ...(instance.environment ?? []).flatMap((variable) =>
57 + isSecretReference(variable.value) && variable.value.provider === providerId
58 + ? [
59 + {
60 + id: `provider:${instanceId}:env:${variable.name}`,
61 + label: `${owner} · ${variable.name}`,
62 + },
63 + ]
64 + : [],
65 + ),
66 + ];
67 + }),
68 + ...sourceControlClients.definitions.flatMap((definition) =>
69 + definition.settings
70 + ? uses(
71 + { settingsSchema: definition.settings },
72 + `source-control:${definition.kind}`,
73 + definition.label,
74 + settings.sourceControlHosts[definition.kind],
75 + )
76 + : [],
77 + ),
78 + ...Object.entries(settings.usageLimitSources).flatMap(([id, source]) =>
79 + uses(
80 + { settingsSchema: UsageLimitSourceConfig },
81 + `usage-limit:${id}`,
82 + source.label ?? source.url,
83 + source,
84 + ),
85 + ),
86 + ...settings.easDeviceHosts.flatMap((host) =>
87 + uses({ settingsSchema: EasDeviceHostConfig }, `eas:${host.id}`, host.label, host),
88 + ),
89 + ];
90 +}
apps/web/src/components/settings/SecretsSettings.tsx
+40 -5
@@ -1,4 +1,4 @@
1 -import type { SecretProviderConfig, SecretProviderId } from "@t3tools/contracts";
1 +import type { EnvironmentId, SecretProviderConfig, SecretProviderId } from "@t3tools/contracts";
2 import { PlusIcon } from "lucide-react";
3 import { useState } from "react";
4
@@ -18,6 +18,7 @@ import {
18 import { Button } from "../ui/button";
19 import { SecretProviderDialog } from "./SecretProviderDialog";
20 import { classifySecretProvider } from "./SecretProviderDialog.logic";
21 +import { secretProviderUses } from "./SecretsSettings.logic";
22 import {
23 classifyProviderEnvironmentAccess,
24 resolveRemoteOperateAccess,
@@ -164,6 +165,8 @@ function EnvironmentSecretProviders({
165 </Button>
166 ) : null}
167 <RemoveSecretProviderButton
168 + environmentId={environmentId}
169 + id={id}
170 label={config.label}
171 onConfirm={() => updateSettings({ secretProviders: { [id]: null } })}
172 />
@@ -189,9 +192,13 @@ function EnvironmentSecretProviders({
192 }
193
194 function RemoveSecretProviderButton({
195 + environmentId,
196 + id,
197 label,
198 onConfirm,
199 }: {
200 + readonly environmentId: EnvironmentId;
201 + readonly id: SecretProviderId;
202 readonly label: string;
203 readonly onConfirm: () => void;
204 }) {
@@ -205,10 +212,7 @@ function RemoveSecretProviderButton({
212 <AlertDialogPopup>
213 <AlertDialogHeader>
214 <AlertDialogTitle>Remove {label}?</AlertDialogTitle>
208 - <AlertDialogDescription>
209 - Provider variables that read from {label} stop resolving until a provider with the
210 - same name is added again. The secrets themselves are untouched.
211 - </AlertDialogDescription>
215 + <SecretProviderUses environmentId={environmentId} id={id} label={label} />
216 </AlertDialogHeader>
217 <AlertDialogFooter>
218 <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
@@ -227,3 +231,34 @@ function RemoveSecretProviderButton({
231 </>
232 );
233 }
234 +
235 +function SecretProviderUses({
236 + environmentId,
237 + id,
238 + label,
239 +}: {
240 + readonly environmentId: EnvironmentId;
241 + readonly id: SecretProviderId;
242 + readonly label: string;
243 +}) {
244 + const uses = secretProviderUses(useEnvironmentSettings(environmentId), id);
245 + if (uses.length === 0) {
246 + return (
247 + <AlertDialogDescription>
248 + Nothing reads from {label}. The secrets themselves are untouched.
249 + </AlertDialogDescription>
250 + );
251 + }
252 + return (
253 + <>
254 + <AlertDialogDescription>
255 + These read from {label} and will be unset. The secrets themselves are untouched.
256 + </AlertDialogDescription>
257 + <ul className="max-h-48 list-disc space-y-0.5 overflow-y-auto ps-5 text-sm wrap-anywhere">
258 + {uses.map((use) => (
259 + <li key={use.id}>{use.label}</li>
260 + ))}
261 + </ul>
262 + </>
263 + );
264 +}
packages/contracts/src/settings.ts
+4
@@ -1744,6 +1744,10 @@ export function requiredScopesForServerSettingsPatch(
1744 changesSettings = true;
1745 }
1746 }
1747 + // Removing a secret provider also clears the settings fields that read from it.
1748 + if (Object.values(patch.secretProviders ?? {}).some((entry) => entry === null)) {
1749 + changesSettings = true;
1750 + }
1751 return [
1752 ...(changesSettings || !changesProviders ? [AuthSettingsWriteScope] : []),
1753 ...(changesProviders ? [AuthProvidersManageScope] : []),