Skip to content

Commit 45baba5

Browse files
fix(settings): servers check secret provider writes and keep unknown configs to themselves
Follow-up to #25709. The server now rejects a secret provider write whose kind it does not know or whose config fails that kind's schema, strips the config of unknown kinds before settings reach clients, and advertises secretProviderSettings so the Secrets page tells you to update an older server instead of losing writes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7a4f5b6 commit 45baba5

7 files changed

Lines changed: 75 additions & 11 deletions

File tree

‎apps/server/src/serverSettings.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ it.layer(NodeServices.layer)("server settings", (it) => {
235235
}).pipe(Effect.provide(layerServerSettings())),
236236
);
237237

238+
it.effect("sends clients a known secret provider's config but never an unknown kind's", () =>
239+
Effect.gen(function* () {
240+
const settings = yield* decodeServerSettings({
241+
secretProviders: {
242+
personal: { kind: "one_password", label: "Personal", config: { account: "my" } },
243+
vault: { kind: "openbao", label: "Vault", config: { token: "bao-token" } },
244+
},
245+
});
246+
assert.deepStrictEqual<unknown>(
247+
ServerSettingsModule.redactServerSettingsForClient(settings).secretProviders,
248+
{
249+
personal: { kind: "one_password", label: "Personal", config: { account: "my" } },
250+
vault: { kind: "openbao", label: "Vault" },
251+
},
252+
);
253+
}),
254+
);
255+
238256
it.effect("saves through a symlinked settings file without replacing the link", () =>
239257
Effect.gen(function* () {
240258
const config = yield* ServerConfig.ServerConfig;

‎apps/server/src/serverSettings.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type ProviderInstanceConfig,
88
type ProviderInstanceMutation,
99
defaultInstanceIdForDriver,
10+
isKnownSecretProviderKind,
1011
isProviderDriverKind,
1112
ProviderDriverKind,
1213
ProviderInstanceId,
@@ -128,11 +129,25 @@ const normalizeServerSettings = (
128129
);
129130

130131
export function redactServerSettingsForClient(settings: ServerSettings): ServerSettings {
131-
return mapSettingsSecrets(settings, (secret) =>
132+
const redacted = mapSettingsSecrets(settings, (secret) =>
132133
secret.sensitive
133134
? { value: "", redacted: secret.redacted || secret.value.length > 0 }
134135
: { value: secret.value, redacted: false },
135136
);
137+
return { ...redacted, secretProviders: withoutUnknownSecretProviderConfigs(redacted) };
138+
}
139+
140+
// A newer kind's config may hold credentials this build cannot recognize, so it never leaves the server.
141+
function withoutUnknownSecretProviderConfigs(
142+
settings: ServerSettings,
143+
): ServerSettings["secretProviders"] {
144+
return Object.fromEntries(
145+
Object.entries(settings.secretProviders).map(([id, entry]) => {
146+
if (isKnownSecretProviderKind(entry.kind)) return [id, entry];
147+
const { config: _config, ...envelope } = entry;
148+
return [id, envelope];
149+
}),
150+
) as ServerSettings["secretProviders"];
136151
}
137152

138153
export function applyProviderInstanceMutation(

‎apps/server/src/ws.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ export const layerWsRpc = (
17911791
threadSnapshotPagination: true,
17921792
threadFind: true,
17931793
threadFindProgressive: true,
1794+
secretProviderSettings: true,
17941795
...Option.match(scratchWorkspaceRoot, {
17951796
onNone: () => ({}),
17961797
onSome: (root) => ({ scratchWorkspaceRoot: root }),

‎apps/web/src/components/settings/SecretsSettings.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ const SECRET_PROVIDER_KINDS: Readonly<
3535

3636
export function SecretsSettingsPanel() {
3737
const { scope, environment } = useSettingsScope();
38+
const connected = environment?.connection.phase === "connected";
3839
return (
3940
<SettingsPageContainer>
40-
{environment?.connection.phase === "connected" ? (
41+
{connected &&
42+
environment.serverConfig !== null &&
43+
environment.serverConfig.secretProviderSettings !== true ? (
44+
<SettingsSection {...searchableSetting("secret-providers")}>
45+
<p className="px-4 py-3 text-sm text-muted-foreground">
46+
Update T3 Code on {environment.label} to manage its secret providers.
47+
</p>
48+
</SettingsSection>
49+
) : connected ? (
4150
<EnvironmentSecretProviders
4251
key={environment.environmentId}
4352
environment={environment}

‎packages/contracts/src/server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ export const ServerConfig = Schema.Struct({
638638
threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
639639
threadFind: Schema.optionalKey(Schema.Boolean),
640640
threadFindProgressive: Schema.optionalKey(Schema.Boolean),
641+
/** Settings patches may carry `secretProviders`; older servers drop the key without an error. */
642+
secretProviderSettings: Schema.optionalKey(Schema.Boolean),
641643
scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
642644
newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
643645
/**

‎packages/contracts/src/settings.test.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
resolveProjectProviderInstanceEnabled,
1616
resolveProviderInstanceEnabled,
1717
ServerSettings,
18-
OnePasswordSecretProviderConfig,
1918
ServerSettingsPatch,
2019
withIdleCompaction,
2120
} from "./settings.ts";
@@ -26,7 +25,6 @@ const encodeClientSettings = Schema.encodeSync(ClientSettingsSchema);
2625
const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
2726
const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
2827
const encodeServerSettings = Schema.encodeSync(ServerSettings);
29-
const decodeOnePasswordConfig = Schema.decodeUnknownSync(OnePasswordSecretProviderConfig);
3028
const decodeClaudeSettings = Schema.decodeUnknownSync(ClaudeSettings);
3129

3230
describe("storage cleanup settings", () => {
@@ -155,13 +153,14 @@ describe("ServerSettings secret providers", () => {
155153
).toThrow();
156154
});
157155

158-
it("rejects a 1Password account op could misread", () => {
156+
it("rejects writes of an unknown kind or an account op could misread", () => {
157+
const write = (entry: unknown) => () =>
158+
decodeServerSettingsPatch({ secretProviders: { personal: entry } });
159159
for (const account of ["", "my account", "--help"]) {
160-
expect(() => decodeOnePasswordConfig({ account })).toThrow();
160+
expect(write(onePassword(account))).toThrow();
161161
}
162-
expect(decodeOnePasswordConfig({ account: "my.1password.com" }).account).toBe(
163-
"my.1password.com",
164-
);
162+
expect(write({ kind: "one_password", label: "Personal" })).toThrow();
163+
expect(write({ kind: "openbao", label: "Vault", config: { address: "https://x" } })).toThrow();
165164
});
166165
});
167166

‎packages/contracts/src/settings.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ export const UsageLimitSourceConfig = Schema.Struct({
859859
});
860860
export type UsageLimitSourceConfig = typeof UsageLimitSourceConfig.Type;
861861

862-
// Final once shipped: a key or field that fails here fails the whole settings decode on older builds.
862+
// Final once shipped: older builds drop entries whose key fails here, and erase them on their next save.
863863
// Unlike provider slugs it may start with a digit, so a provider named "1Password" fits.
864864
const SecretProviderSlug = TrimmedNonEmptyString.check(
865865
Schema.isMaxLength(64),
@@ -903,11 +903,31 @@ export const SecretProviderConfig = Schema.Struct({
903903
});
904904
export type SecretProviderConfig = typeof SecretProviderConfig.Type;
905905

906+
/** Kinds this build can resolve. Their `config` holds no credentials, so clients may read it. */
907+
const SECRET_PROVIDER_KIND_CONFIG_GUARDS: Readonly<Record<string, (config: unknown) => boolean>> = {
908+
one_password: Schema.is(OnePasswordSecretProviderConfig),
909+
};
910+
911+
export function isKnownSecretProviderKind(kind: string): boolean {
912+
return Object.hasOwn(SECRET_PROVIDER_KIND_CONFIG_GUARDS, kind);
913+
}
914+
906915
// Limits that may change later are enforced on writes only, never on the stored envelope.
916+
// Writes must be a kind this build knows with a config it accepts, so an older server
917+
// rejects a newer kind instead of storing what it cannot check.
907918
const SecretProviderConfigWrite = Schema.Struct({
908919
...SecretProviderConfig.fields,
909920
label: SecretProviderLabel,
910-
});
921+
}).check(
922+
Schema.makeFilter((entry) => {
923+
if (!isKnownSecretProviderKind(entry.kind)) {
924+
return `Unsupported secret provider kind: ${entry.kind}.`;
925+
}
926+
return SECRET_PROVIDER_KIND_CONFIG_GUARDS[entry.kind]!(entry.config)
927+
? true
928+
: `Invalid ${entry.kind} secret provider config.`;
929+
}),
930+
);
911931

912932
export const SourceControlHostSettings = Schema.Record(Schema.String, Schema.Unknown);
913933
export type SourceControlHostSettings = typeof SourceControlHostSettings.Type;

0 commit comments

Comments
 (0)