Skip to content

Commit 96226a3

Browse files
fix(config): drop viewStates from settings imports
CodeRabbit's Security Boundaries pre-merge check flagged that a settings file can carry viewStates, whose claimToken is host-minted: an import could plant an entry plus its claim and replay it as that view's identity. The export side already omits the key; the import side now consults a shared non-portable-key list in sanitizeGlobalSettings and reports the skip as an import warning. Test: importExport.spec.ts, host-owned view state on import. Negative control: dropping the import guard turns the new assertion red (the applied settings regain a viewStates key); the production file was restored byte-identically and the suite re-ran green.
1 parent d018b9e commit 96226a3

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎src/core/config/ContextProxy.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ const globalSettingsExportSchema = globalSettingsSchema.omit({
4141
viewStates: true,
4242
})
4343

44+
/**
45+
* Global settings a settings file may not carry in either direction. Per-view selections and the
46+
* claim token that binds them are minted and held by the extension host, so a file that could
47+
* set them would be replayable as another view's identity. The export side omits the key above;
48+
* the import side consults this list in `sanitizeGlobalSettings`.
49+
*/
50+
const NON_PORTABLE_SETTINGS_KEYS: readonly string[] = ["viewStates"]
51+
52+
export const isNonPortableSettingsKey = (key: string): boolean => NON_PORTABLE_SETTINGS_KEYS.includes(key)
53+
4454
export class ContextProxy {
4555
private readonly originalContext: vscode.ExtensionContext
4656

‎src/core/config/__tests__/importExport.spec.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,55 @@ describe("importExport", () => {
251251
})
252252
})
253253

254+
describe("host-owned view state on import", () => {
255+
const settingsWithImportedViewStates = JSON.stringify({
256+
providerProfiles: {
257+
currentApiConfigName: "test",
258+
apiConfigs: {
259+
test: { apiProvider: providerIdentifiers.openai, apiKey: "test-key", id: "test-id" },
260+
},
261+
},
262+
globalSettings: {
263+
customInstructions: "keep me",
264+
viewStates: { "view-1": { mode: "architect", claimToken: "planted-claim" } },
265+
},
266+
})
267+
268+
beforeEach(() => {
269+
;(fs.readFile as Mock).mockResolvedValue(settingsWithImportedViewStates)
270+
mockProviderSettingsManager.export.mockResolvedValue({
271+
currentApiConfigName: "default",
272+
apiConfigs: { default: { apiProvider: providerIdentifiers.anthropic, id: "default-id" } },
273+
})
274+
mockProviderSettingsManager.import.mockResolvedValue(undefined)
275+
mockProviderSettingsManager.listConfig.mockResolvedValue([])
276+
mockContextProxy.setValues.mockResolvedValue(undefined)
277+
mockContextProxy.setValue.mockResolvedValue(undefined)
278+
mockContextProxy.setProviderSettings.mockResolvedValue(undefined)
279+
})
280+
281+
it("drops viewStates so an imported file cannot plant another view's claim", async () => {
282+
const result = await importSettingsFromPath("/mock/path/settings.json", {
283+
providerSettingsManager: mockProviderSettingsManager,
284+
contextProxy: mockContextProxy,
285+
customModesManager: mockCustomModesManager,
286+
})
287+
288+
expect(result).toMatchObject({ success: true })
289+
290+
// A claim token is host-minted: a file that could carry an entry could replay it as that
291+
// view's identity, so the key is dropped before anything is written.
292+
expect(mockContextProxy.setValues).toHaveBeenCalledTimes(1)
293+
const [appliedSettings] = (mockContextProxy.setValues as Mock).mock.calls[0]
294+
expect(appliedSettings).not.toHaveProperty("viewStates")
295+
expect(appliedSettings).toMatchObject({ customInstructions: "keep me" })
296+
const warnings = (result as { warnings?: string[] }).warnings ?? []
297+
expect(warnings).toHaveLength(1)
298+
expect(warnings[0]).toContain('globalSettings.viewStates" was skipped')
299+
expect(warnings[0]).toContain("not portable")
300+
})
301+
})
302+
254303
describe("importSettings", () => {
255304
it("should return success: false when user cancels file selection", async () => {
256305
;(vscode.window.showOpenDialog as Mock).mockResolvedValue(undefined)

‎src/core/config/importExport.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { TelemetryService } from "@roo-code/telemetry"
1818

1919
import { ProviderSettingsManager, providerProfilesSchema } from "./ProviderSettingsManager"
20-
import { ContextProxy } from "./ContextProxy"
20+
import { ContextProxy, isNonPortableSettingsKey } from "./ContextProxy"
2121
import { CustomModesManager } from "./CustomModesManager"
2222
import { downgradeLegacyRooConfig, ROUTER_REMOVAL_IMPORT_WARNING } from "./routerRemoval"
2323
import { resolveDefaultSaveUri, saveLastExportPath } from "../../utils/export"
@@ -105,6 +105,13 @@ function sanitizeGlobalSettings(rawGlobalSettings: unknown): {
105105
continue
106106
}
107107

108+
if (isNonPortableSettingsKey(key)) {
109+
warnings.push(
110+
`Setting "${path}" was skipped: per-view state and its host-minted claim token are not portable through settings files.`,
111+
)
112+
continue
113+
}
114+
108115
let valueToValidate = rawValue
109116

110117
if (key === "imageGenerationProvider" && rawValue === retiredProviderIdentifiers.roo) {

0 commit comments

Comments
 (0)