GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(bind): treat an empty header value slice as an absent key by methakon · Pull Request #3175 · labstack/echo

Conversation

@methakon

@methakon methakon commented Oct 14, 2026

Copy link
Copy Markdown

Problem

BindHeaders panics when a header's value slice is nil or empty:

panic: runtime error: index out of range [0] with length 0

BindHeaders passes the request header map straight to bindData, which reads
v[0] on the scalar-map paths (bind.go:245, bind.go:249) and inputValue[0]
on the tagged-struct paths (bind.go:337, bind.go:364) without checking the
length. Header["X-Empty"] = nil or []string{} therefore panics instead of
binding nothing.

Note this is not reachable from a raw incoming HTTP request — net/http never
produces an empty value slice — so it is not a remote denial of service. It is
reachable for any in-process caller that builds or mutates a Header map, and
for anything calling bindData with a map it controls.

Change

Guard both reads. An empty value slice is treated like an absent key.

[]string{""} — a present but empty value — still binds, so the check keys on
length rather than on the value being empty. TestBindHeadersEmptyStringValueStillBinds
pins that distinction.

Testing

Four tests in bind_empty_header_test.go:

  • TestBindHeadersEmptyValueSlice — nil and []string{} into a tagged struct,
    as subtests, since they are distinct states reaching the same panic.
  • TestBindHeadersEmptyValueSliceIntoMap — the scalar-map destination path.
  • TestBindHeadersPresentValueStillBinds — the guard does not swallow a real value.
  • TestBindHeadersEmptyStringValueStillBinds — []string{""} still binds.

With bind.go reverted and the tests kept, the run fails with the exact panic
above. With the change, all four pass and the full root suite stays green
(ok github.com/labstack/echo/v5), including the 86 existing binding tests.

gofmt -l is clean on both changed files; go vet is clean. echo.go and
middleware/decompress.go are flagged by gofmt on master and are untouched here.

Closes #3169

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@methakon
fix(bind): treat an empty header value slice as an absent key
3d97c0f
bindData indexed inputValue[0] on the scalar-map paths and on the
tagged-struct paths without checking the length, so a header whose value
slice was nil or empty panicked with "index out of range [0] with length 0"
instead of binding nothing. BindHeaders passes the request header map
straight to bindData, so BindHeaders inherited the panic.

Guard both reads. An empty slice now behaves like an absent key, while
[]string{""} - a present but empty value - still binds, so the check keys
on length rather than on the value being empty.

Closes labstack#3169
@vishr vishr mentioned this pull request Nov 12, 2026
fix(bind): skip empty scalar header values #3223
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BindHeaders panics on nil or empty header value slices

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@methakon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.