Skip to content

Commit 138b147

Browse files
fix(extension): drop a caller-supplied viewStates map from setConfiguration
RooCodeApi.setConfiguration takes a whole RooCodeSettings object and writes it at src/extension/api.ts:643 through contextProxy.setValues, which walks past ClineProvider.setValues, and then hands the same object to providerSettingsManager.saveConfig at :644. The registered viewStates map is host-owned - ClineProvider rewrites it from a full read of storage (savePersistedViewState, clearPersistedViewState, prunePersistedViewStates) - so an API caller that handed one in replaced every other view's durable entry in globalState and in the profile file, and an explicit unset erased it: globalState.update(key, undefined) deletes, which the repo itself relies on at ContextProxy.ts:173, :280-282, :305 and :346, and the secrets path deletes explicitly at :464-466. The pre-filter cannot catch the key either: withoutInvalidDisplaySettings validates timeFormat, dateFormat, showRelativeTimes and language, and states at displaySettings.ts:14 that any other key is never invalid there. The key is now dropped, with the same host-ownership rationale the two webview doors use; the rest of the settings object is the caller's to set. Door inventory for this boundary, so that two guards are not read as a closed boundary: 1. webview message handler - the per-key updateSettings loop wrote contextProxy.setValue directly (webviewMessageHandler.ts:894) and bypassed setValues; closed at 75add35. 2. ClineProvider.setValues - closed at 75add35; this is also the door the API startNewTask path reaches, whose configuration goes to provider.createTask at src/extension/api.ts:256. 3. API setConfiguration - the door this commit closes. The read side stays open on purpose: getConfiguration (:626-629) returns getValues() minus secrets, and reading the registered map is not the hazard the finding names; a read guard would change what existing callers see for no shown defect. Test: api-configuration.spec.ts pins that setConfiguration({ viewStates: {...}, soundEnabled: true }) calls contextProxy.setValues and saveConfig with { soundEnabled: true } only, and logs the ignore. Control: red at 75add35 without the drop - setValues received the crafted map - and green with it. Lanes at this head: api-configuration 10, api-delegation-events 6, api-delete-queued-message 3, api-has-task-ui-message-text 8, api-send-message 6, api-start-new-task 6, api-start-task-logging 8, api-task-conversation-history-length 23, api-terminal-profile 1, api-theme-fixture 2, displaySettings 22, ClineProvider 475, webviewMessageHandler 175, all passing; src tsc --noEmit exit 0. Compile-job command list in job order: lint, check-types, code-qa-ci, solheim-smoke check-types, agent-evals unit and check-types, lifecycle model-check, webview-recovery check-types and model-check and the mcp integration check are green; format:check is red locally on 2004 files and none of them is touched here (working-tree CRLF, every blob CR=0, and the touched files re-checked after LF normalisation pass prettier --check), and the two solheim record.sh suites need ffprobe (absent on this box) and POSIX path separators. ESLint suppressions unchanged at 3298; neither touched file carries an entry.
1 parent 75add35 commit 138b147

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎src/extension/__tests__/api-configuration.spec.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,38 @@ describe("API - configuration", () => {
6868
expect(postStateToWebview).toHaveBeenCalledOnce()
6969
})
7070

71+
it("drops a caller-supplied viewStates map so the registered map stays host-written", async () => {
72+
const setValues = vi.fn().mockResolvedValue(undefined)
73+
const saveConfig = vi.fn().mockResolvedValue("default-id")
74+
const postStateToWebview = vi.fn().mockResolvedValue(undefined)
75+
const log = vi.fn()
76+
const provider = {
77+
context: {},
78+
on: vi.fn(),
79+
log,
80+
contextProxy: { setValues },
81+
providerSettingsManager: { saveConfig, setModeConfig: vi.fn().mockResolvedValue(undefined) },
82+
postStateToWebview,
83+
} as unknown as ClineProvider
84+
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
85+
const api = new API(outputChannel, provider, makeClineProviderFactory())
86+
87+
// The registered map is written by the extension host from a full read of storage, so a map handed in by
88+
// an API caller replaces every other view's durable entry in globalState and in the profile file written
89+
// from the same object. An explicit unset is the same hazard, since ContextProxy reads undefined as a
90+
// delete. The rest of the settings object is the caller's to set.
91+
await api.setConfiguration({
92+
viewStates: { "crafted-view": { mode: "ask", currentApiConfigName: "crafted" } },
93+
soundEnabled: true,
94+
} as unknown as RooCodeSettings)
95+
96+
expect(setValues).toHaveBeenCalledWith({ soundEnabled: true })
97+
expect(saveConfig).toHaveBeenCalledWith("default", { soundEnabled: true })
98+
expect(log).toHaveBeenCalledWith(
99+
"[setConfiguration] Ignored a caller-supplied viewStates map; the registered map is written by the extension host.",
100+
)
101+
})
102+
71103
describe("the display settings", () => {
72104
const setup = () => {
73105
const setValues = vi.fn().mockResolvedValue(undefined)

‎src/extension/api.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,26 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
634634
* `ContextProxy.setValues`, which is not a transaction (see there): if a setting cannot be stored, this rejects
635635
* with a `SettingsWriteError` that lists the keys that were stored and the keys that were not (the cache of the
636636
* failed keys has been read back from storage), the stored settings stay, and nothing after the settings is
637-
* written. Invalid values of the display settings are dropped and logged first.
637+
* written. Invalid values of the display settings are dropped and logged first, and a caller-supplied
638+
* `viewStates` map is dropped too: the registered map is host-owned, rewritten by the extension host from
639+
* a full read of storage.
638640
*/
639641
public async setConfiguration(allValues: RooCodeSettings) {
640642
const values = withoutInvalidDisplaySettings(allValues, (key) =>
641643
this.sidebarProvider.log(`[setConfiguration] Ignored an invalid value for ${key}`),
642644
)
645+
// The registered viewStates map is host-owned: ClineProvider rewrites it from a full read of storage
646+
// (savePersistedViewState, clearPersistedViewState, prunePersistedViewStates), so a map handed in here
647+
// would replace every other view's durable entry - in globalState, and below in the profile file written
648+
// from the same object - and an explicit unset would erase it, since ContextProxy reads undefined as a
649+
// delete. The key is dropped rather than sanitised; the rest of the settings object is the caller's to
650+
// set.
651+
if ("viewStates" in values) {
652+
this.sidebarProvider.log(
653+
"[setConfiguration] Ignored a caller-supplied viewStates map; the registered map is written by the extension host.",
654+
)
655+
delete values.viewStates
656+
}
643657
await this.sidebarProvider.contextProxy.setValues(values)
644658
await this.sidebarProvider.providerSettingsManager.saveConfig(values.currentApiConfigName || "default", values)
645659
if (values.modeApiConfigs) {

0 commit comments

Comments
 (0)