Skip to content

chore(security): pin Actions to SHAs and fix CodeQL findings - #22

Merged
satan9394 merged 1 commit into
feat/server_teamfrom
chore/harden-actions-codeql-20260919
Sep 19, 2026
Merged

satan9394 merged 1 commit into
feat/server_teamfrom
chore/harden-actions-codeql-20260919

Conversation

@satan9394

Copy link
Copy Markdown
Owner

摘要

一个提交同时完成两件事:加固 GitHub Actions 设置(Task A)与修复 15 个 CodeQL 告警(Task B)。全部改动最小化、自包含,便于向上游 TencentCloud/TencentDB-Agent-Memory 重新套用。

Task A — Actions 固定 SHA

pr-ci.yml 中全部 10 处 uses: 固定到 40 位 commit SHA(保留 # v4 注释):

Action SHA
actions/checkout 11d5960a326750d5838078e36cf38b85af677262
actions/setup-node 49933ea5288caeca8642d1e84afbd3f7d6820020
actions/cache 0057852bfaa89a56745cba8c7296529d2fc39830
actions/upload-artifact ea165f8d65b6e75b540449e92b4886f43607fa02
actions/download-artifact d3f86a106a0bac45b974a628896c90dbdf5c8093

Task B — CodeQL 修复

  • js/insecure-randomness ×5:id-generator.ts 的 randomBase36() 改用 crypto.randomInt()(一次修复 sqlite/mongodb/metadata-service 三处调用点);e2e helper 的随机用户名后缀改为模块内自增计数器。
  • js/polynomial-redos ×4:/\/+$/ 全部替换为线性 stripTrailingSlashes()(sdk 导出复用,MemoryCore 本地定义)。对抗性输入 "/".repeat(n)+"x" 实测:原正则 n=128000 需 7952ms(二次增长),新实现 n=400000 仅 0.3ms;20 万+ 用例等价性校验 0 差异。
  • js/insufficient-password-hash ×3:经确认均为「API key 派生的查询/追踪索引」(非密码存储/校验),保留快速哈希并加注释说明。注意:CodeQL 将 createHmac 也建模为弱哈希 sink,故改 HMAC 并不能关闭该告警。
  • js/weak-cryptographic-algorithm ×2:anthropicHandler.ts 调试指纹 md5 → sha256。
  • js/biased-cryptographic-random ×1:generatePassword() 改用 crypto.randomInt(),消除 % 63 偏差。

验证

  • MemoryCore: npm run build(tsdown + 脚本 tsc)通过;针对 src 的 tsc --noEmit 前后错误数均为 228,无新增。
  • sdk/memory-core/typescript: npm run build(tsc)通过。
  • MemoryProxy: npm run typecheck 仍为基线上既有的 6 个错误,无新增。
  • 本仓库无任何测试文件,无法做行为验证。

已知限制

  • MemoryProxy 无测试,typecheck 在基线即失败(既有问题)。
  • 3 个 insufficient-password-hash 告警保留(判定为查询索引误报,已注释说明)。
  • 仓库内另有 8 处相同 /\/+$/ 模式未被 CodeQL 标记,为保持最小 diff 未改动。

Task A: pin all 10 uses: in pr-ci.yml to 40-char commit SHAs.
Task B: fix CodeQL alerts in forked code:
- insecure-randomness: randomInt() in id-generator/crypto, counter in e2e helpers
- polynomial-redos: linear stripTrailingSlashes() replaces /\/+\$/ at 4 sites
- weak-crypto: sha256 replaces md5 in anthropicHandler debug fingerprints
- biased-cryptographic-random: randomInt() replaces modulo on randomBytes
- insufficient-password-hash: documented as lookup-index false positives
@satan9394
satan9394 merged commit df4946c into feat/server_team Sep 19, 2026
8 checks passed
@satan9394
satan9394 deleted the chore/harden-actions-codeql-20260919 branch September 19, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant