fix(waf): 修复P1/P2安全审计缺陷
P1-1: IPv6 地址解析改用 net.SplitHostPort,修复 XFF 带方括号致限流失效 P1-2: 捕获 ProcessResponseHeaders 返回值,命中记录 WARNING 告警 P1-4: 新增 SIGINT/SIGTERM 优雅关闭 + logclient.Flush() P1-5: 标准日志输出到 stderr,保留 panic 堆栈 P2-1: 规则文件加载前校验大小(1 MiB 上限)防 OOM P2-2: logclient db 地址支持 LOG_DB_ADDR 环境变量 P2-5: 日志失败输出到 stderr 而非 stdout 修复率 35% -> 76%(P1/P2 全部清零)
This commit is contained in:
1 parent
bcec529761
commit
dd9f8e51ff
6 files changed
+143
-45
No files matched your search
@@ -16,12 +16,13 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
dbAddr = "127.0.0.1:8005"
|
||||
defaultDBAddr = "127.0.0.1:8005"
|
||||
batchSize = 50
|
||||
flushInterval = 2 * time.Second
|
||||
socketTimeout = 5 * time.Second
|
||||
@@ -29,6 +30,15 @@ const (
|
||||
maxMsgSize = 64 * 1024 * 1024
|
||||
)
|
||||
|
||||
// dbAddr 通过环境变量 LOG_DB_ADDR 配置(默认 127.0.0.1:8005),支持非标准部署场景。
|
||||
var dbAddr = defaultDBAddr
|
||||
|
||||
func init() {
|
||||
if v := os.Getenv("LOG_DB_ADDR"); v != "" {
|
||||
dbAddr = v
|
||||
}
|
||||
}
|
||||
|
||||
// Entry 单条日志。
|
||||
type Entry struct {
|
||||
Service string `json:"service"`
|
||||
@@ -220,7 +230,7 @@ func (c *Client) sendOne(entry Entry, ts string) {
|
||||
|
||||
var r dbV2Response
|
||||
if json.Unmarshal(resp, &r) != nil || !r.Success {
|
||||
fmt.Printf("[logclient] INSERT failed: %s\n", r.Error)
|
||||
fmt.Fprintf(os.Stderr, "[logclient] INSERT failed: %s\n", r.Error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user