Skip to content

fix: avoid attaching botched content-length header#136

Merged
keynslug merged 1 commit intomasterfrom
fix/botched-content-length-header
Mar 30, 2026
Merged

fix: avoid attaching botched content-length header#136
keynslug merged 1 commit intomasterfrom
fix/botched-content-length-header

Conversation

@keynslug
Copy link
Copy Markdown
Contributor

Before this commit, #{<<"content-length">> => 0} attached to response headers of body-less reponses can cause literal NULL byte to appear in the response stream as part of this header.

This was possible because header-value was fed into a stream verbatim, and sub-256 integer is a valid piece of iodata().

E.g. in cow_http1, as part of cowboy_http:commands/3 -> cow_http:response/3 -> cow_http1:response/3 call chain:

headers(Headers) ->
    [[N, <<": ">>, V, <<"\r\n">>] || {N, V} <- Headers]

Before this commit, `#{<<"content-length">> => 0}` attached to
response headers of body-less reponses can cause literal NULL
byte to appear in the response stream as part of this header.

This was possible because header-value was fed into a stream
verbatim, and sub-256 integer is a valid piece of `iodata()`.

E.g. in `cow_http1`:
```
headers(Headers) ->
    [[N, <<": ">>, V, <<"\r\n">>] || {N, V} <- Headers]
```
@keynslug keynslug merged commit 21cd824 into master Mar 30, 2026
2 checks passed
@keynslug keynslug deleted the fix/botched-content-length-header branch March 31, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants