feat(safety): protect non-SQL production writes#3272
Conversation
t8y2
left a comment
There was a problem hiding this comment.
I'm requesting changes because the production write permit is not bound to the mutation the user confirmed.
The permit is currently keyed only by connection_id + database. The client authorizes first and sends the mutation as a separate request, so another concurrent write on the same connection and database can consume that permit before the confirmed operation arrives. The backend then has no way to prove which mutation was authorized.
Please issue a random, single-use token from the authorization request and require the corresponding mutation to carry it. Consumption should atomically validate the token, connection, effective database, operation kind, and preferably a stable request or target digest, with a short TTL. Adding only the action to the existing shared key is not sufficient because concurrent operations of the same kind can still consume each other's authorization.
648aa4b to
eac4ced
Compare
已在 现在生产写授权不再使用
同时补充了随机令牌、请求不匹配、并发单次消费、同类型并发隔离、过期拒绝以及 Web 授权头完整性测试。这样同一连接、数据库甚至同一操作类型的并发写入也无法再误用其他 mutation 的确认许可。 |
t8y2
left a comment
There was a problem hiding this comment.
I'm requesting changes because the new token fixes the concurrent permit-consumption race, but the request digest is still not verified against the mutation that the backend actually executes.
authorize_production_write stores the digest supplied by the client, and permit consumption only compares it with the digest carried alongside the token. The Redis/Mongo/etc. mutation handlers do not recompute that digest from their deserialized request. A caller can therefore confirm mutation A and submit a different mutation B of the same operation while carrying A's token and digest; the backend will accept and execute B.
Please derive a canonical digest or target descriptor from the actual mutation request on the backend and include it in the atomic permit check. The authorization path should derive the same value from structured intent rather than accepting an arbitrary hash string.
变更说明
完善生产环境保护,将原本主要覆盖 SQL 写操作的保护机制扩展至非 SQL 连接类型。
主要改动:
$out、$merge按实际目标数据库进行判断。MOVE、COPY ... DB、SWAPDB、FLUSHALL按所有受影响 logical DB 判断。本次改动范围较大,涉及前端、Tauri、Web、dbx-core、Node core 和 MCP,需要在不同连接类型及运行模式下反复测试。
当前本地只有 Redis 环境,因此人工联调仅覆盖了 Redis 相关操作。MongoDB、Elasticsearch、向量数据库、Etcd、ZooKeeper、Nacos 和 MQ 目前主要通过单元测试、静态入口覆盖测试及编译检查验证,建议在具备相应服务的环境中继续进行真实连接测试。
变更类型
涉及前端
验证
make check通过make cargo-check-fast通过已完成:
cargo check --no-default-featurescargo fmt --all -- --checkpnpm typecheckgit diff --check已知环境限制:
EPERM,业务测试均通过。关联 Issue
无