Repository navigation
fix: scanner false positives & symlink dodge; perf: policy cache - #10
Open
liuhaolin07 wants to merge 2 commits into
Open
liuhaolin07 wants to merge 2 commits into
liuhaolin07 wants to merge 2 commits into
Conversation
Audit findings addressed: - scanner: 'sk-' pattern had no word boundary or minimum length, so 'task-123' / 'risk-2026' matched as leaked keys and blocked clean model calls (the serialized loop payload contains the user task). Now mirrors the dots_client redaction shape; patterns precompiled. - middleware: check the blocked-name list against the resolved path as well, so a benign-named symlink cannot dodge blocked_files. - policy: cache parsed policies per path, revalidated against (st_mtime_ns, st_size) — ~5.5x faster on hot loops, identical change-on-disk semantics, errors never cached. - main: deterministic demo now exits 2 on block, matching --llm. Tests: 30 -> 35 (all pass; symlink case skips only where the platform cannot create symlinks, e.g. Windows without developer mode).
The fixture named the target real.env, but blocks_file matches filenames exactly, so '.env' never matched and the case asserted the wrong expectation. The target is now .env; the benign-named link is notes.txt as before.
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.
代码审计结果
对全部
\u0076core模块(middleware / policy / scanner / capabilities / audit / agent / dots_client)做了一次完整审计,修复 4 项发现:修复
1. Scanner
sk-正则误报(功能性 bug) —security/scanner.py原模式
sk-[a-zA-Z0-9]+无词边界、无长度下限,task-123、risk-2026等普通词命中("task-123")。LLM loop 会把含用户任务的整段对话序列化后过扫描器,任务文本带task-xxx即导致模型调用被误判为sensitive_data而终止。现改为与model/dots_client.py脱敏正则一致的\u005cbsk-[a-zA-Z0-9_-]{8,}\u005cb,并预编译全部模式。2. Symlink 绕过
blocked_files(安全加固) —security/middleware.py封锁名单原来只匹配调用方传入的原始文件名;名为
notes.txt的软链接指向.env即可绕过。现在对 resolve 后的绝对路径同样做封锁名检查。3. 策略每次调用重新读盘解析(性能) —
security/policy.pyload_policy按路径缓存,以(st_mtime_ns, st_size)指纹校验:实测 5.5x 提速(20000 次加载 61.4s → 11.2s),文件修改即失效重载,异常从不缓存,失败语义不变。4. CLI 退出码不一致 —
main.py确定性 demo 被拦截时恒返回 0,与
--llm模式(返回 2)不一致;现统一为拦截返回 2。测试
审计中记录、未改动的点
blocks_file的endswith分支与文件名相等判断语义重复(无害,为控制 diff 未动)