Repository navigation
fix(thesis): 投资论文仓库未校验 id 的文件名边界,路径型 id 会越出 <userData>/thesis 读写删 - #303
Merged
helsome merged 1 commit intoOct 18, 2026
Merged
Conversation
ThesisRepository and ThesisImpactRepository interpolated the caller-supplied id straight into a file name, and JsonFileStore only `join()`s it onto the store root. A path-like id (`../escaped`) therefore wrote, read, and deleted files outside `<userData>/thesis`, and the escaped key was persisted into `index.json` so later `list()` / `getBySymbol()` calls kept reading out of root. The sibling research repositories already enforce the same "ids are opaque names, not relative paths" contract (research/repository.ts:21-28) and pin it with a regression test. Mirror it here: reject non-`/^[a-zA-Z0-9_-]+$/` ids with INVALID_ARGUMENT before touching the file system, and fail closed when an index already contains a path-like id.
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
独立源码审查通过;精确 HEAD focused 25 pass / 0 fail。与最新 main 的本批累计组合独立验证 1831 pass / 7 skip / 0 fail,全 workspace typecheck、i18n 均通过。相关生产变更文件高信号 secret 扫描零命中;不把这些确定性回归声称为真实模型或完整桌面验收。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与修复
Closes #302
ThesisRepository/ThesisImpactRepository把调用方给的 id 直接插进文件名(`${id}.json`、`impacts/${thesisId}.json`),而JsonFileStore只做join(rootDir, file),不校验名字(json-file-store.ts:43/:48/:66/:102)⇒ 路径型 id 会越出<userData>/thesis:../escaped)ThesisRepository.save<userData>/escaped.json,并把键../escaped记进index.jsonINVALID_ARGUMENT,index.json不生成list()/getBySymbol()length=1)length=0delete('../vanish')<userData>/vanish.jsonINVALID_ARGUMENT,文件保留impacts.append({ thesisId: '../escaped' })impacts/../escaped.json,即论文正文同名文件INVALID_ARGUMENT修复方式复用同一文件族里 research 仓库已经写明并已被测试固定的契约(
packages/shared/src/research/repository.ts:21-28):save/get/delete与 impact 的append/list全部改走护栏;原来的私有方法ThesisImpactRepository.path()由模块级impactFile()取代。可达路径:
preload/index.ts:278thesis:update→kernelHost.ts:771-773thesisUpdate()(只做requireObject)→thesis/service.ts:122-124updateThesis()原样落盘 →repository.ts拼文件名。即<userData>/thesis的写入边界完全取决于 renderer 传来的id;thesisSchema(converter.ts:15-29)也只把id声明为z.string()。可复现测试报告
3a17eca6;headb1384da0packages/shared/src/thesis/repository.test.ts(7 条用例)swap_files.py把repository.ts切回 main 原样字节):1 pass / 6 failbun test packages/shared/src/thesis --isolate:25 pass / 0 fail(converter / repository / service 三个文件)bun x tsc --noEmit -p packages/shared/tsconfig.json:exit 0bun run typecheck:core / i18n / shared / ui / electron 五工作区 exit 0bun test packages/shared --isolate(全量):1127 pass / 2 fail,两条均为既存问题,可在 main 原始字节下复现:ResearchService > lists runs newest-first——beforeEach/afterEach钩子超时(6.7s),时序偶发langfuse backend > does not throw when Langfuse is down — agent path keeps a diagnostic—— 把repository.ts还原成 main 字节后单跑packages/shared/src/evaluation/langfuse/langfuse.test.ts同样 12 pass / 1 fail(A/B 后已还原,md5e70c862c校验一致)save(id="../escaped"): NO_THROW、list() length=1、<base>/vanish.json ... survived: false;修复后全部THREW INVALID_ARGUMENT、index.json exists: false、survived: true。临时复现脚本已删除(ls | grep -c __repro= 0)pr.yml口径,排除node_modules/docs/*.test.ts(x)/bun.lock):命中 0PR checks工作流本次开工实测仍为disabled_manually,新 PR 不产生 check run,故按仓库等价命令在本地补齐上述检查,不声称 CI 通过边界与范围
JsonFileStore:它是有意保持极简的存储底座,文件名边界的校验属于仓库层(research 侧也是这样分工的)。randomUUID)与现有全部 id,均满足/^[a-zA-Z0-9_-]+$/,无行为回归。thesisSchema、不改任何 IPC 契约;thesis:update的调用方式与错误返回形状之外的行为不变(越界 id 现在会明确报INVALID_ARGUMENT,而不是静默写错地方)。packages/shared/src/thesis/repository.ts与新增的测试文件。check_collisions.py对 79 个 open PR 求交,repository.ts/service.ts/ 新测试文件均collisions=0。UI 变化
无可见 UI 变化。纯持久化层护栏。
本地基线的补充说明
工作树是「Git Data API 推送」流程留下的累积基线,除本 PR 外还含本轮另外几个 PR 以及我在 #270 方向上尚未合并的改动(
packages/shared/src/evaluation/aggregate.ts的higherIsBetter方向判定及其测试)。因此上文的全量用例数比「main + 本 PR」多;失败项与这个数量无关,两条失败均可在 main 原始字节下复现。