fix: redact secrets in instance settings reads unless explicitly revealed (#12682)

* fix: redact secrets in instance settings reads unless explicitly revealed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): compare redacted remote settings against unchanged local secrets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: redact nuget, maven, cargo, webhook and otel header credentials too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): mask get-config secrets from servers that do not redact

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): refuse a masked get-config export from a server that cannot restore it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): word the get-config prompt for servers that do not redact

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-26 15:45:42 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent c689d74505
commit cc855e6fd9
15 changed files with 402 additions and 74 deletions
+79 -4
View File
@@ -103,6 +103,60 @@ export const SETTINGS_MANAGED_ONLY_WHEN_PRESENT = [
* so a file that still carries one must not show as differing from the workspace. */
export const RETIRED_SETTINGS = ["guest_access_enabled"] as const;
/** How the server's settings reads begin a secret they withheld (without `dangerouslyRevealSecrets`). */
export const REDACTED_SECRET_PREFIX = "__REDACTED__";
function keepUnchangedLocalSecrets(redacted: any, revealed: any, local: any): any {
if (typeof redacted === "string" && redacted.startsWith(REDACTED_SECRET_PREFIX)) {
return local !== undefined && deepEqual(local, revealed) ? local : redacted;
}
if (Array.isArray(redacted)) {
return redacted.map((v, i) =>
keepUnchangedLocalSecrets(v, revealed?.[i], local?.[i])
);
}
if (redacted && typeof redacted === "object") {
return Object.fromEntries(
Object.entries(redacted).map(([k, v]) => [
k,
keepUnchangedLocalSecrets(v, revealed?.[k], local?.[k]),
])
);
}
return redacted;
}
/**
* The remote settings as pull and push compare them with the local file. Unless
* `showSecrets`, a remote secret stays redacted, except where the local file already holds
* that same value: comparing against the redacted value alone would flag every secret as
* changed on each sync, while the revealed one must not reach the printed diff or the file.
*/
async function remoteSettingsAgainstLocal(
opts: InstanceSyncOptions,
readLocal: () => Promise<GlobalSetting[]>
): Promise<GlobalSetting[]> {
if (opts.showSecrets) {
return await wmill.listGlobalSettings({ dangerouslyRevealSecrets: true });
}
const redacted = await wmill.listGlobalSettings();
if (!JSON.stringify(redacted).includes(REDACTED_SECRET_PREFIX)) {
return redacted;
}
const revealed = await wmill.listGlobalSettings({
dangerouslyRevealSecrets: true,
});
const local = await readLocal();
return redacted.map((s) => ({
...s,
value: keepUnchangedLocalSecrets(
s.value,
revealed.find((r) => r.name === s.name)?.value,
local.find((l) => l.name === s.name)?.value
),
}));
}
// Legacy settings interface for reading old settings.yaml files
interface LegacySimplifiedSettings {
auto_invite_enabled?: boolean;
@@ -708,7 +762,10 @@ export async function pushWorkspaceKey(
}
}
export async function readInstanceSettings(opts: InstanceSyncOptions) {
export async function readInstanceSettings(
opts: InstanceSyncOptions,
silent = false
) {
let localSettings: GlobalSetting[] = [];
await checkInstanceSettingsPath(opts);
@@ -718,7 +775,7 @@ export async function readInstanceSettings(opts: InstanceSyncOptions) {
instanceSettingsPath
)) as GlobalSetting[];
} catch {
log.warn(`No ${instanceSettingsPath} found`);
if (!silent) log.warn(`No ${instanceSettingsPath} found`);
}
return localSettings;
}
@@ -781,7 +838,22 @@ export async function pullInstanceSettings(
opts: InstanceSyncOptions,
preview = false
) {
const remoteSettings = await wmill.listGlobalSettings();
const remoteSettings = await remoteSettingsAgainstLocal(
opts,
async () =>
await processInstanceSettings(
await readInstanceSettings(opts, true),
"decode"
)
);
if (
!preview &&
JSON.stringify(remoteSettings).includes(REDACTED_SECRET_PREFIX)
) {
log.info(
"Secrets are redacted in the pulled settings: pass --show-secrets to include them. Pushing them back keeps the stored secrets."
);
}
await checkInstanceSettingsPath(opts);
@@ -818,9 +890,12 @@ export async function pushInstanceSettings(
opts: InstanceSyncOptions,
preview: boolean = false
) {
const remoteSettings = await wmill.listGlobalSettings();
let localSettings: GlobalSetting[] = await readInstanceSettings(opts);
localSettings = await processInstanceSettings(localSettings, "decode");
const remoteSettings = await remoteSettingsAgainstLocal(
opts,
async () => localSettings
);
if (opts.baseUrl) {
localSettings = localSettings.filter((s) => s.name !== "base_url");