feat(手机号资产关联): AUG26-009 手机号—资产关联、十项上限与后台解绑
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m2s

- 新增成对迁移 000223(tb_phone_asset_association,含有效关系部分唯一索引与 down 守卫)与 000224(解绑导入任务表),不回填历史
- H5:need_bind_phone 三支判定(开关关闭完全短路);已有主号幂等建联;十项上限按手机号 advisory 串行化(含换绑到全新号的并发场景);换绑原子迁移与冲突整单回滚;不写遗留列
- 后台:关联列表、单项/批量解绑、CSV 导入解绑(B1–B16),超管/平台 gate + 资产数据范围复核,三态统一文案
- 读侧:卡/设备列表与详情按页一次 IN 聚合;两类导出补「关联手机号」列并保留历史表头反解兼容
- 脱敏:关联审计走独立动作/资源只写脱敏手机号;访问日志手机号类字段脱敏
- 同步主 Spec openspec/specs/phone-asset-association 并归档 AUG26-009,补齐 requirement-evidence 与入口矩阵,context-health 通过
This commit is contained in:
2026-09-15 11:54:56 +08:00
parent 93e072e1e2
commit 70e680eb0a
67 changed files with 3951 additions and 147 deletions

View File

@@ -5,7 +5,9 @@ import (
"crypto/sha256"
"encoding/hex"
"net/url"
"strings"
"time"
"unicode"
"github.com/break/junhong_cmp_fiber/pkg/auditcontext"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -52,6 +54,38 @@ func truncateBody(body []byte, maxSize int) (string, bool) {
return string(body[:maxSize]), true
}
// phoneFieldNames 是访问日志中属于手机号类的字段名集合。
// 手机号不在 sanitizer 的 forbidden 字段清单内,仅靠字段名通用清理无法脱敏;
// 这里单独识别并输出前 3 位 + **** + 后 4 位,禁止完整号码进入 query、请求正文或响应正文。
// 只覆盖手机号类字段forbidden 字段仍按原语义标记为已脱敏,两者处理互不影响。
var phoneFieldNames = map[string]struct{}{
"phone": {},
"mobile": {},
"associated_phones": {},
}
// normalizeLogFieldName 归一化字段名用于敏感字段判断。
func normalizeLogFieldName(key string) string {
var builder strings.Builder
for index, char := range key {
if unicode.IsUpper(char) && index > 0 {
builder.WriteByte('_')
}
if char == '-' || char == '.' {
builder.WriteByte('_')
continue
}
builder.WriteRune(unicode.ToLower(char))
}
return builder.String()
}
// isPhoneField 判断字段名是否属于手机号类字段(与 forbidden 字段分开处理)。
func isPhoneField(key string) bool {
_, ok := phoneFieldNames[normalizeLogFieldName(key)]
return ok
}
// maskSensitiveValue 按字段名判断并脱敏访问日志中的敏感值
func maskSensitiveValue(key, value string) string {
if value == "" {
@@ -60,6 +94,9 @@ func maskSensitiveValue(key, value string) string {
if shouldMaskField(key) {
return redactedValue
}
if isPhoneField(key) {
return sanitizer.MaskPhone(value)
}
return value
}
@@ -125,6 +162,25 @@ func sanitizeJSONValue(value any) {
typed[key] = redactedValue
continue
}
if isPhoneField(key) {
// 手机号类数组逐元素脱敏;非字符串元素不保留原值。
list, ok := item.([]any)
if !ok {
if item != nil {
typed[key] = redactedValue
}
continue
}
for index, element := range list {
if text, ok := element.(string); ok {
list[index] = sanitizer.MaskPhone(text)
continue
}
list[index] = redactedValue
}
typed[key] = list
continue
}
sanitizeJSONValue(item)
}
case []any: