BindHeaders panics on nil or empty header value slices
维护者通常 1 天内回复
评估
调研方向
从 bind.go 开始,沿着 BindHeaders 经过 bindData,追踪 issue 中指出的标量 map 和带标签 struct 路径。使用提供的进程内复现代码检查 nil 和空的 header 值切片,然后检查全部三种目标类型以及指定的对照情况。完成标准是绑定不再引发 panic,且选定的行为由回归测试覆盖。
由索引模型根据 Issue 内容生成。
描述
Issue Description
BindHeaders panics when an in-process request header contains a key whose value is a nil or zero-length []string. This is different from []string{""}, which binds without a panic.
On current master, BindHeaders passes the header map to bindData. The scalar-map paths read v[0], and the tagged struct path reads inputValue[0], without checking the slice length. With Header["X-Empty"] = nil or []string{}, these paths panic with index out of range [0] with length 0 instead of returning normally/an error.
This reproduction constructs the request in-process. I have not demonstrated a way for a raw incoming HTTP header to produce this map state, and I am not claiming a remotely exploitable denial of service.
Working code to debug
package echo_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v5"
)
func TestEmptyHeaderValues(t *testing.T) {
for _, values := range [][]string{nil, {}} {
func() {
defer func() {
if p := recover(); p != nil {
t.Errorf("BindHeaders panicked: %v", p)
}
}()
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header["X-Empty"] = values
c := e.NewContext(req, httptest.NewRecorder())
var dst struct { Value string `header:"X-Empty"` }
if err := echo.BindHeaders(c, &dst); err != nil {
t.Errorf("BindHeaders: %v", err)
}
}()
}
}
I also reproduced the panic for ordinary *map[string]string and *map[string]any targets. A private table test against unchanged master produced 6 failing panic cases (nil/empty slices × three targets) and 6 passing no-panic controls (normal value/one empty string × three targets). Package go vet passed; no full-suite, race, other Go-version or OS run is claimed.
Proposed narrow follow-up
Would skipping entries with no values be the preferred treatment, or should binding return a specific error? I can prepare a narrow bind.go/regression follow-up after confirming this policy and coordination with #3150, which changes adjacent map assignment code but still indexes v[0]. This would not alter named-map conversions, first-value versus all-values behavior, []string{""} semantics, or existing custom multi-value unmarshalling without agreement. #2778's empty-string-to-nil-pointer proposal is a different input case.
Version/commit
- master
3882266a3641a36fc2111b48cd597adab1c1ecea, modulegithub.com/labstack/echo/v5 - Go 1.27.1, Linux/arm64; synthetic requests, no running application/provider
- OpenAI Codex assisted with source tracing and the reproduction. No production fix/PR has been submitted.
- 主要语言
- Go
- 星标
- 32.8k
- 派生
- 4.2k
- 平均合并
- 14 小时 51 分钟
- 30 天内合并 PR
- 32
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
labstack/echo 的其他 Issue
-
Group routes does not work without leading slash可能已有人在做 @team-humaki 于 23 天前认领。 未关闭enhancement router v5
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
enhancement v5
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
Rate limit middleware doesn't set headers or provide metadata via interface.可能已有人在做 @AdamMagued 于 5 天前认领。 未关闭enhancement middleware
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
enhancement router
难度 4/5 3-5 天 新手友好度 42/100
labstack/echo#2895 · 16 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
kind/bug
难度 1/5 1-3 小时 新手友好度 85/100
kubernetes-sigs/vsphere-csi-driver#4351 ·
维护者通常 1 天内回复
-
component/gpu-kubelet-plugin component/helm needs-triage
难度 2/5 1-3 小时 新手友好度 62/100
kubernetes-sigs/dra-driver-nvidia-gpu#1559 ·
维护者通常 1 天内回复
-
workflow: redundant goroutine in scheduleRetry可能已有人在做 @moodbased 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
JuliusBrussee/caveman#1266 · 2 条评论 ·
维护者通常 1 天内回复