fix(P2): 修复4个P2轻微问题

P2-01: 通配符scope安全风险 (scope_auth.go)
- 添加hasWildcardScope()函数检测通配符scope
- 添加logWildcardScopeAccess()函数记录审计日志
- 在RequireScope/RequireAllScopes/RequireAnyScope中间件中调用审计日志

P2-02: isSamePayload比较字段不完整 (audit_service.go)
- 添加ActionDetail字段比较
- 添加ResultMessage字段比较
- 添加Extensions字段比较
- 添加compareExtensions()辅助函数

P2-03: regexp.MustCompile可能panic (sanitizer.go)
- 添加compileRegex()安全编译函数替代MustCompile
- 处理编译错误,避免panic

P2-04: StrategyRoundRobin未实现 (router.go)
- 添加selectByRoundRobin()方法
- 添加roundRobinCounter原子计数器
- 使用atomic.AddUint64实现线程安全的轮询

P2-05: 错误信息泄露内部细节 - 已在MED-09中处理,跳过
This commit is contained in:
Your Name
2026-04-03 09:39:32 +08:00
parent 732c97f85b
commit b2d32be14f
8 changed files with 289 additions and 19 deletions

View File

@@ -315,6 +315,9 @@ func isSamePayload(a, b *model.AuditEvent) bool {
if a.Action != b.Action {
return false
}
if a.ActionDetail != b.ActionDetail {
return false
}
if a.CredentialType != b.CredentialType {
return false
}
@@ -330,5 +333,30 @@ func isSamePayload(a, b *model.AuditEvent) bool {
if a.ResultCode != b.ResultCode {
return false
}
if a.ResultMessage != b.ResultMessage {
return false
}
// 比较Extensions
if !compareExtensions(a.Extensions, b.Extensions) {
return false
}
return true
}
// compareExtensions 比较两个map是否相等
func compareExtensions(a, b map[string]any) bool {
if len(a) != len(b) {
return false
}
for k, v1 := range a {
v2, ok := b[k]
if !ok {
return false
}
// 简单的值比较不处理嵌套map的情况
if v1 != v2 {
return false
}
}
return true
}