Skip to main content

Module caller_context

Module caller_context 

Source
Expand description

Caller context — 跨 REST surface 统一携带 caller key id + allowed_acc_ids 快照.

§触发 (codex 0522 audit F1 / F2)

v1.4.105 之前 REST adapter 只把 allowed_acc_ids 接到 response filter, 不 填进 IncomingRequest.caller_allowed_acc_ids —— dispatch-time handler (如 SubAccPushHandler) 看到 None 当 “无限制”, silent bypass per-acc 白名单 (gRPC / WS 已对齐, REST 落后).

同时 REST 在 routes 层手写多套 caller scope check (account list / card_num / sub-acc-push / unsub-acc-push), IncomingRequest.caller_key_id 不存在导致 per-key cleanup / 审计 / owner-bound subscription 在 daemon 层只能 REST state 表自己维护, 不能走 gateway 统一入口.

§解决

引入 CallerContext (一处 build, 全 surface 透传), 作为 REST adapter proto_request_with_ctx 唯一 caller scope 输入. 同时填:

  1. IncomingRequest.caller_allowed_acc_ids (defense-in-depth, dispatch handler)
  2. IncomingRequest.caller_key_id (per-key 配额 / 审计 / cleanup)
  3. FilterRegistry::apply 入参 (响应 acc_list filter)

与 routes 层手写 audit / per-acc rate check 共用同一份 CallerContext, 防止 “检查的 body” 和 “实际 dispatch 的 body” 不一致 (codex F2).

Structs§

CallerContext
REST caller scope 快照 (一次 build, 多次透传).