| name | go-vuln-info-disclosure |
| description | Use when auditing Go code involving logging, error handling, HTTP response data, Kubernetes Secret management, or credential storage. Covers CWE-200/532/522/312/552. Keywords: information disclosure, credential leak, log exposure, Kubernetes Secret, json tag, struct formatting, error message, stack trace, Rancher, Argo CD, sensitive data |
Go Information Disclosure Vulnerability Patterns (CWE-200/532/522/312/552)
当审计 Go 代码中涉及日志记录、错误处理、API 响应、K8s Secret 管理、凭证存储时加载此 Skill。
Detection Strategy
Sources(敏感数据来源):
- Kubernetes Secret 对象(
v1.Secret.Data)
- 数据库凭证(
database/sql 连接字符串)
- API token / OAuth credential(struct 字段)
- TLS 证书私钥
- 环境变量中的密钥(
os.Getenv("API_KEY"))
- Git 仓库 URL 中的认证信息(
https://user:token@github.com)
Sinks(泄露出口):
log.Printf("%+v", configStruct) -- %+v 格式化输出所有字段包括密钥
logrus.WithFields(logrus.Fields{...}).Error() -- 结构化日志中包含敏感字段
zap.Any("config", struct) -- zap 日志序列化完整结构体
- HTTP API 响应 body(
json.Marshal(objectWithSecrets))
- K8s API 对象的
.status / .spec 字段
- 错误信息(
fmt.Errorf("failed to connect: %v", err))中的连接字符串
runtime.Stack() 输出包含参数值
Sanitization(数据保护措施):
- Struct field tag
json:"-" -- JSON 序列化时忽略字段
String() / MarshalJSON() 方法 -- 自定义序列化隐藏敏感字段
- Log scrubbing 中间件 -- 过滤日志中的敏感模式
- K8s Secret
stringData -> base64 data 转换
- Error wrapping(
fmt.Errorf("connection failed: %w", ErrGeneric))-- 隐藏内部细节
检测路径:
grep -rn '%+v\|%#v' --include="*.go"
grep -rn 'log\.Print\|logrus\.\|zap\.\|logger\.' --include="*.go" | grep -i 'secret\|password\|token\|credential\|key'
grep -rn 'json:"-"' --include="*.go"
grep -rn 'v1.Secret\|corev1.Secret\|StringData\|\.Data\[' --include="*.go"
grep -rn 'fmt.Errorf\|errors.New\|errors.Wrap' --include="*.go"
grep -rn 'https://.*:.*@\|git.*token\|git.*password' --include="*.go"
grep -rn 'json.Marshal\|json.NewEncoder.*Encode' --include="*.go"
- 搜索敏感数据的定义位置(Secret struct、credential 字段、token 变量)
- 追踪数据流向,检查是否流入日志、API 响应、错误信息
- 验证是否有保护措施:
- 包含密钥的 struct 是否有
json:"-" tag?
- 日志是否使用了 scrubbing/redaction 过滤?
- API 响应是否使用专门的 DTO(而非直接返回内部对象)?
- K8s Secret 是否在 CRD status 中被明文暴露?
- 错误信息是否包含连接字符串或堆栈追踪?
- 若敏感数据可能泄露 -> 标记为候选漏洞
Detection Checklist
False Positive Exclusion Guide
以下模式不是此类漏洞:
- Debug 级别日志中的详细信息 -- 如果 debug 日志仅在开发环境启用且不会出现在生产日志中
json:"-" 用于内部 RPC struct -- 仅在服务内部使用的 struct 不需要隐藏字段
- 错误信息中的操作描述 --
"failed to create user" 不包含敏感数据
- 测试代码中的 mock Secret --
_test.go 中使用假密钥
以下模式需要深入检查:
json.Marshal(clusterObject) -- 集群对象是否包含 kubeconfig 或 bearer token 字段?
logrus.WithError(err).Error("operation failed") -- err 中是否包含连接字符串或凭证?
- CRD 的
status subresource -- status 通常有较宽松的 RBAC,其中的敏感数据更容易被低权限用户读取
- Rancher API 的
answers 字段 -- cluster template 的 answers 可能包含 cloud provider credentials
Real-World Cases
详见 references/cases.md(7 个真实案例,需要时加载)。