Skip to main content

Module redact

Module redact 

Source
Expand description

v1.4.84 SEC-001 fix: Auth credential redaction for debug log output.

背景: external reviewer security report SEC-001 证实 daemon --log-level debug/tmp/*.log 明文写入 tgtgt / salt / device_sig 等完整 auth credentials. 80+ 历史 log 文件暴露 tgtgt. agent 时代, 恶意 skill 一行 cat /tmp/*.log | grep tgtgt 就能拿凭据.

修法: 这个模块提供 redact_auth_body(&str) -> String / redact_kv(&str, key) -> String / redact_auth_json_value(&mut Value) 三个 helper, 替换 敏感字段 value 为 "<REDACTED len=N>". 所有 auth debug / info log 打印 body / response 前必须过这些 helper.

敏感字段清单 (redact 时替换 value):

  • tgtgt / tgtgt_new — 172 byte base64 AES-256 auth payload
  • salt / salt32 — 16/32 char server-provided nonce (TGTGT key 派生)
  • client_sig / client_key / rand_key / rand_key_new — session keys
  • device_sig / device_sig_new — device 签名 (credentials 持久化)
  • device_id — 设备标识 (持久化 secret 文件,日志只保留 fingerprint)
  • device_verify_sig / device_code / device_code_sig — SMS 2FA 凭据
  • pwd / pwd_md5 / password — 密码 / MD5
  • auth_token / client_token / session_id — session-level tokens
  • web_sig_new / ci_sig — web session tokens
  • auth_code / moomoo_client_* / moomoo_web_sig_new — broker / moomoo auth credentials returned by /authority/verify_device_code

上下文字段保留明文: account / device_alias / device_type / os_ver / sens_state / uid / svr_time / user_attribution / region_no / is_phone — 这些是 identity / context, 保留方便 debug. device_id 虽也是 identity, 但已按 secret-file 持久化,日志不再保留 raw 值。

何时调用:

  • crates/futu-backend/src/auth/mod.rs: L765 salt / L883 raw response / L1071 verify_response / L1203 POST body
  • 其他任何 tracing::debug! / info! 打印 response / body / header 的 log point — 改为 redact_auth_body 包装

Constants§

SENSITIVE_FIELDS
v1.4.84 SEC-001: 敏感字段名清单 (case-sensitive, 匹配 JSON key 或 URL param).

Functions§

account_log_fingerprint
v1.4.106 F2: account 字符串 -> 12-char fingerprint acc-{8-hex}.
device_id_log_fingerprint
v1.4.106 F2: device_id (16-hex) -> 12-char fingerprint dev-{8-hex}.
emit_debug_log_security_warn_once
redact_auth_body
v1.4.84 SEC-001: 给一段 JSON-like / key=value text 做 redaction.
uid_log_fingerprint
v1.4.106 F3: uid (u64) -> 12-char fingerprint uid-{8-hex}.