加固:插件 locale 标签累加器拒绝 __proto__ 等保留 key(PR #338 follow-up)
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 401
- Avg merge
- 21h 48m
- Merged PRs (30d)
- 776
Description
## 背景
PR #338 的 review 中 Copilot 提出(线程已按 P2 resolve,不阻塞合并,此处跟进加固)。
## 现状
- `GHOST_SETUP_KV_KEY_RE = /^[A-Za-z0-9_.-]{1,64}$/` 允许 `__proto__` / `constructor` / `prototype` 作为 setup kv key。
- `apps/desktop/src/shared/ghost.ts` 的 `validateGhostManifestLocaleResource` → `validateLocalizedLabels` 用普通对象字面量累加:`labels[declaration.key] = …`。当 key 为 `__proto__` 时,该赋值会替换累加对象自身的原型(JSON.parse 生成的是自有属性,读取路径不受影响;**不会**污染全局 `Object.prototype`)。
- 后果:setup kv 路径经 `Object.fromEntries(Object.entries(…))` 后该项丢失,`resolveGhostManifestLocale` 里对应 label 变 `undefined`,UI 渲染异常。
## 影响评估
P2:仅该插件自身文案渲染异常,无越权面;但对象完整性契约被破坏,值得统一加固。
## 建议
1. `validateLocalizedLabels` 以及同文件其它按外部 key 累加的 Record(如 `tools[tool.name]`、`parameters[pointer]`)改用 `Object.create(null)` 或 `Map`。
2. manifest 校验层对 setup kv key、network secrets/connections key、node secretBindings key、tool name 统一拒绝 `__proto__` / `constructor` / `prototype`。
3. 补对应单测(含 JSON.parse 自有属性路径)。
Contributor guide
Research direction
Start in apps/desktop/src/shared/ghost.ts at validateGhostManifestLocaleResource and validateLocalizedLabels, then inspect the other external-key accumulators for tools and parameters. Add coverage for reserved keys and JSON.parse own-property behavior. Done means setup and related manifest keys are safely rejected or accumulated without losing labels, with the corresponding tests passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100