Skip to content

Commit 7c1cd55

Browse files
authored
feat(toolchain): 可信位置可以单独添加和删除,拒绝把文件系统根目录设为可信位置(#2207) (#144)
toolchains.editCatalog 新增 trustedLocations: {add?, remove?},供没有打开工作区的设置页增删可信位置:按平台大小写身份匹配,删除不存在的位置不算修改,已存在的位置保留原有写法,工作区上的明确决定不受影响。添加文件系统根目录(/、盘符、UNC 共享)返回 plugin.toolchain.rootLocation;手写进文档的根目录位置在读取时被拒绝,工作区保持安全模式。信任列表超过 256 项改为返回 plugin.toolchain.trustListFull(含原来 workspaceTrust 的超限),宿主可以提示“列表已满”而不是“文档无效”。offered_location 改用 paths::is_root 判断根目录。schema 补上 #118 漏掉的 distrustedWorkspaces 和 trustedLocations。
1 parent 9aa95a7 commit 7c1cd55

5 files changed

Lines changed: 414 additions & 27 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ or removing a command fails until the table changes in the same commit.
535535
| `toolchains.resolvePins` | Validate a captured local document and find the nearest ancestor directory pin, retaining dormant and legacy entries without probing or writing |
536536
| `toolchains.editPins` | Apply one bounded batch of directory pin edits to a captured local document without writing native files |
537537
| `toolchains.catalogState` | Validate machine-wide SDK registrations and optional workspace project-code trust without a project |
538-
| `toolchains.editCatalog` | Merge confirmed machine-wide SDK registrations, defaults and explicit workspace project-code trust |
538+
| `toolchains.editCatalog` | Merge confirmed machine-wide SDK registrations, defaults, explicit workspace project-code trust and trusted location changes |
539539
| `toolchains.pinStoragePlan` | Declare bounded workspace-native pin and ignore sources |
540540
| `toolchains.decodePinDocument` | Validate a complete native source or supply the absent-source default |
541541
| `toolchains.editPinSources` | Plan deterministic pin and Git ignore source edits without native I/O |
@@ -7758,27 +7758,41 @@ applies first, then a trusted location containing it: `state` is `trusted`, `dis
77587758
`unknown` when the user has not been asked. `location` is the trusted location that trusts the
77597759
workspace, else `null`. `offeredLocation` is the parent folder a trust prompt may offer to trust
77607760
with the workspace, or `null` when that parent is a filesystem root (`/`, a drive, a UNC share).
7761+
A filesystem root is never a trusted location: a document listing one (no edit writes it) is
7762+
rejected at `trustedLocations`, so its workspaces stay in safe mode rather than every project
7763+
on the volume being trusted.
77617764
The two newer lists are written only once used, so a document without them stays readable by
77627765
hosts that predate them.
77637766
Native clients resolve the relative path below their platform user-preference directory,
77647767
never below a workspace, SDK, installed package or application bundle. Reading an absent
77657768
source returns `{version:1,tools:{}}` and must not create a directory or file.
77667769

7767-
`toolchains.editCatalog` accepts `{document:string|null,platform,filesystemCaseSensitive?,edits?,workspaceTrust?}`,
7768-
where at least one of a nonempty `edits` array of `{tool,homes:[absoluteHome],defaultHome:string|null}`
7769-
or `workspaceTrust:{workspace,trusted,location?}` is required. Each tool edit replaces only that tool's
7770+
`toolchains.editCatalog` accepts `{document:string|null,platform,filesystemCaseSensitive?,edits?,workspaceTrust?,trustedLocations?}`,
7771+
where at least one of a nonempty `edits` array of `{tool,homes:[absoluteHome],defaultHome:string|null}`,
7772+
`workspaceTrust:{workspace,trusted,location?}` or `trustedLocations:{add?:[absolutePath],remove?:[absolutePath]}`
7773+
is required. Each tool edit replaces only that tool's
77707774
registrations and default; other tools, dormant plugins and the trust lists remain intact.
77717775
`workspaceTrust` records one decision on one normalized workspace root, preserving `tools` and
77727776
other decisions: `trusted: true` moves it to `trustedWorkspaces`, `trusted: false` to
77737777
`distrustedWorkspaces` (safe mode), and `location: true` also adds its `offeredLocation` to
77747778
`trustedLocations`; `location` with `trusted: false`, or without an offered location, rejects at
7775-
`workspaceTrust.location`. At most
7779+
`workspaceTrust.location`.
7780+
`trustedLocations` changes the trusted folders on their own, for a settings page without an
7781+
open workspace, and applies after `workspaceTrust` when both are present. Paths are normalized
7782+
and matched by platform case identity: `remove` drops each named folder, a folder that is not
7783+
trusted changes nothing, and `add` keeps the recorded spelling of a folder already trusted.
7784+
`add` and `remove` cannot both be empty or name one folder. Adding a filesystem root (`/`, a
7785+
drive, a UNC share) rejects with `plugin.toolchain.rootLocation` at `trustedLocations.add`.
7786+
Workspace decisions are untouched: a workspace kept in safe mode stays there inside a newly
7787+
trusted location.
7788+
An edit that would leave `trustedWorkspaces`, `distrustedWorkspaces` or `trustedLocations`
7789+
longer than 256 entries rejects with `plugin.toolchain.trustListFull` at that list's name. At most
77767790
64 tools and 32 distinct homes per tool are accepted. Native platform path normalization
77777791
and case identity apply before deduplication. A selected default is registered if needed;
77787792
null clears only the default. Empty registrations plus null remove the tool entry.
77797793
The result is `{status:"ok",edit:{changed,document:string|null,catalog}}`; unchanged edits
77807794
return a null replacement and must not create a source. Invalid shapes, duplicate JSON keys,
7781-
unknown fields, relative homes, aliases and oversized documents reject with
7795+
unknown fields, relative homes or paths, aliases and oversized documents reject with
77827796
`plugin.toolchain.invalidDocument`. The schema is
77837797
[`toolchain-global-v1.schema.json`](toolchain-global-v1.schema.json); cross-client vectors
77847798
are in `rust/fixtures/toolchain-global-catalog.json`.

‎rust/contracts/toolchain-global-v1.schema.json‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@
4646
"type": "string",
4747
"minLength": 1
4848
}
49+
},
50+
"distrustedWorkspaces": {
51+
"description": "Workspaces the user chose to keep in safe mode; an explicit decision wins over a trusted location containing it.",
52+
"type": "array",
53+
"maxItems": 256,
54+
"uniqueItems": true,
55+
"items": {
56+
"type": "string",
57+
"minLength": 1
58+
}
59+
},
60+
"trustedLocations": {
61+
"description": "Folders whose every workspace, at any depth, is trusted unless distrusted itself. Never a filesystem root.",
62+
"type": "array",
63+
"maxItems": 256,
64+
"uniqueItems": true,
65+
"items": {
66+
"type": "string",
67+
"minLength": 1
68+
}
4969
}
5070
}
5171
}

0 commit comments

Comments
 (0)