From vuln-skills
Audits Go code for DoS vulnerabilities like goroutine leaks, channel deadlocks, unbounded allocations, io.ReadAll misuse, panic handling, and resource exhaustion.
npx claudepluginhub yhy0/ghsa-skill-builder --plugin vuln-skillsThis skill uses the workspace's default tool permissions.
当审计 Go 代码中涉及 goroutine 管理、channel 操作、HTTP 请求处理、资源分配、panic 恢复时加载此 Skill。
Audits, reviews, and secures Golang code against injections (SQL, command, XSS), crypto flaws, secrets leaks, network issues, and more. For writing, reviewing, or auditing Go projects.
Audits Go code for SSRF, XSS, and CSRF vulnerabilities in HTTP clients, URL handling, HTML templates, web frameworks like Gin/Echo/Fiber, webhooks, and CSRF protection.
Audits Go apps for security: input validation, SQL injection prevention, authentication/authorization, secrets management, TLS, OWASP Top 10, secure coding patterns. Use for vulnerability checks, hardening services, auth reviews.
Share bugs, ideas, or general feedback.
当审计 Go 代码中涉及 goroutine 管理、channel 操作、HTTP 请求处理、资源分配、panic 恢复时加载此 Skill。
Sources(攻击入口):
Sinks(资源消耗点):
go func() -- 无限制的 goroutine 创建make([]byte, userSize) / make([]T, userSize) -- 用户控制的内存分配io.ReadAll(r) / ioutil.ReadAll(r) -- 读取整个 body 到内存json.NewDecoder(r).Decode(&v) -- 无大小限制的 JSON 解码yaml.Unmarshal(data, &v) -- YAML 解码(支持 anchor/alias 指数扩展)proto.Unmarshal(data, msg) -- protobuf 解码无嵌套限制panic() 在 HTTP handler 中未被 recover() 捕获ch <- v 阻塞、<-ch 永久等待)Sanitization(资源限制屏障):
io.LimitReader(r, maxSize) -- 限制读取大小http.MaxBytesReader(w, r.Body, maxSize) -- HTTP body 大小限制context.WithTimeout / context.WithDeadline -- 超时控制semaphore.Weighted)recover() 在 goroutine 入口golang.org/x/time/rate)select with default检测路径:
# Goroutine 创建
grep -rn "go func\|go .*(" --include="*.go"
# 无限制读取
grep -rn "io.ReadAll\|ioutil.ReadAll\|io.Copy" --include="*.go"
# 内存分配
grep -rn "make(\[\]byte\|make(\[\]" --include="*.go"
# Panic/Recover
grep -rn "panic(\|recover()" --include="*.go"
# JSON/YAML/Protobuf 解码
grep -rn "json.NewDecoder\|json.Unmarshal\|yaml.Unmarshal\|proto.Unmarshal" --include="*.go"
# 资源限制
grep -rn "LimitReader\|MaxBytesReader\|context.WithTimeout" --include="*.go"
# Channel 操作
grep -rn "make(chan\|<-.*chan" --include="*.go"
io.ReadAll 之前是否有 LimitReader/MaxBytesReader?make([]T, size) 的 size 是否有上限检查?recover() 中间件防止 panic 导致进程崩溃?go func() 内部是否有退出条件?是否监听 ctx.Done() 或 done channel?无退出条件的 goroutine 在请求取消后仍会占用资源。io.ReadAll 无限制审计 (CWE-770):是否直接 io.ReadAll(r.Body) 而未使用 http.MaxBytesReader 或 io.LimitReader 限制?攻击者可发送超大 body 导致 OOM。make([]byte, size) 分配审计 (CWE-789):size 是否来自用户输入?是否有上限检查?直接 make([]byte, userSize) 可用于 OOM 攻击。net/http 的 Server 内置了 per-request recover(),单个 handler panic 不会导致进程崩溃(但会关闭该连接)。第三方框架(如 gin/echo)通常也有内置 recovery 中间件。真正危险的是在 handler 中启动的 子 goroutine 中 panic(不受 HTTP server recover 保护)。对于不安全的类型断言(如 data["key"].(string)),应使用 comma-ok 模式 v, ok := data["key"].(string) 避免 panic。make(chan T))在发送端/接收端缺失时是否会永久阻塞?select 是否包含 default 或 timeout 分支?json.NewDecoder(r).Decode() 是否限制了输入大小?YAML 的 anchor/alias 是否允许指数级扩展("billion laughs")?Protobuf 嵌套深度是否有限制?MaxConcurrentStreams?是否容易受到 rapid reset 攻击(CVE-2023-44487)?SetReadLimit?是否有消息频率限制?以下模式不是此类漏洞:
go func() 在 init() 中启动的后台 worker -- 生命周期与进程相同,不会泄漏io.ReadAll 读取小文件或内部配置 -- 来源可信且大小可控panic 用于编程错误检测 -- 如 panic("unreachable") 在 switch default 中context.WithTimeout 的 goroutine -- 有超时退出机制以下模式需要深入检查:
go func() 在 HTTP handler 中 -- 每个请求创建 goroutine 且无 pool 限制json.Decoder 在 API endpoint -- 未设置 MaxBytesReader 的 HTTP handlerrecover() 在 goroutine 内但不在 HTTP handler 链 -- 可能只保护了子 goroutine 但 handler 本身可 panicselect {} 永久阻塞 -- 在某些情况下是有意设计,但也可能是 bug详见 references/cases.md(7 个真实案例,需要时加载)。