Skip to content

fix(chat): saveTurn SQL WHERE 消除 TOCTOU 竞态#32

Merged
TinyAlmond merged 1 commit into
mainfrom
fix/chat-toctou
May 10, 2026
Merged

fix(chat): saveTurn SQL WHERE 消除 TOCTOU 竞态#32
TinyAlmond merged 1 commit into
mainfrom
fix/chat-toctou

Conversation

@TinyAlmond
Copy link
Copy Markdown
Collaborator

@TinyAlmond TinyAlmond commented May 10, 2026

Summary

  • ON CONFLICT DO UPDATEWHERE "Chat"."userId" IS NULL OR "Chat"."userId" = EXCLUDED."userId" 条件,归属校验在单条 SQL 内原子完成
  • rows=0 时抛 AccessDeniedBusinessException,异常在 Message INSERT 之前抛出,Message 不会被插入
  • Controller 前置 lookupOwner 校验保留作为 defense-in-depth(快速拦截明显越权)

Closes #27

Test plan

  • SecurityInvariantsTests 12 个测试全部通过(./mvnw test -Dtest=SecurityInvariantsTests
  • ON CONFLICT ... WHERE 语法兼容性:PG 9.5+ 支持,项目用 PG 18,无问题

🤖 Generated with Claude Code

ON CONFLICT DO UPDATE 加 WHERE owner 兼容条件,归属校验在单条 SQL 内原子完成;
rows=0 时抛 AccessDeniedBusinessException,Message 不插入。
Controller 前置校验保留作为 defense-in-depth。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@TinyAlmond TinyAlmond merged commit 14b3fc2 into main May 10, 2026
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.

chat history saveTurn TOCTOU: lookupOwner 与 saveTurn 不在同一事务

1 participant