permessage-deflate: decide whether to reset the inflater when the peer agreed to no context takeover
Maintainers usually reply within 1 day
@ashtum is already working on this.
Since Oct 5, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
When the peer agreed to no context takeover (server_no_context_takeover for a client, client_no_context_takeover for a server), do_context_takeover_read in websocket/detail/impl_base.hpp is meant to reset the inflater after each message. Since Boost 1.70 that call has been a no-op, so Beast keeps the peer's window and silently accepts peers that break the promise.
#3114 makes zlib::inflate_stream::clear() work, which would change this to rejecting such peers, plus one allocation per message. To keep #3114 a pure port, the call is commented out there with a pointer to this issue. Behaviour with the call commented out matches develop.
History
- Boost ≤ 1.69:
pmd_->zi.reset()emptied the window and kept the buffer, so violating peers were rejected. - 8ea282e (Boost 1.70): deprecated
flat_static_buffer::resetin favour ofclearand renamed the websocket's buffer calls.pmd_->zi.reset()was renamed along with them, butziis azlib::inflate_stream, whoseclear()had been empty since 5089cf5 (2016). From 1.70 on, Beast accepts violating peers, by accident. - #3114: implements
clear()as documented (frees the window and resets the state), which would make Beast strict again.
RFC 7692
- §7.2.1: when the parameter is agreed, the sender MUST start compressing each new message with an empty window.
- §7.2.2: the receiver MAY then decompress each new message with an empty window; otherwise it MUST use the window from the previous message. Rejecting and accepting a violating peer are both conforming.
- §7.1.1.1 / §7.1.1.2: the parameters exist so the receiver does not have to reserve window memory between messages.
Decisions
- Reject or accept peers that agree to no context takeover but still refer back to earlier messages.
- If rejecting: keep the window buffer or free it between messages.
| Call at end of message | Violating peer | Allocations per message | Inflater memory between messages (15-bit window) |
|---|---|---|---|
| none (develop, #3114 as-is) | accepted | 0 | ~39.9 KB |
zi.reset() (≤ 1.69) |
rejected (zlib::error::invalid_distance) |
0 | ~39.9 KB |
zi.clear() |
rejected (zlib::error::invalid_distance) |
1 (32 KiB) | ~7.1 KB |
Measured on #3114 with GCC 13 at -O2. The deflater (~145 KB at websocket defaults) is unaffected: zo.reset() keeps its buffers either way. A rejected message fails the connection, as any other inflate error does.
Other implementations
| Implementation | Strict | Window between messages |
|---|---|---|
| Chromium | no | kept across messages |
| Firefox | no | kept across messages |
| ws | yes | kept, reset in place |
| OkHttp | yes | kept, reset in place |
| .NET | yes | freed after each message, recreated for the next |
| Netty | yes | freed after each message, recreated for the next |
| Tomcat | yes | kept, reset in place |
| Jetty (server role) | yes | released after each message |
| python-websockets | yes | freed after each message, recreated for the next |
| gorilla/websocket | yes | released after each message |
| aiohttp | no | kept across messages |
| uWebSockets | yes | one inflater shared by all connections, reset after each message |
| libwebsockets | yes | freed after each message, recreated for the next |
| Undertow | no | kept across messages |
| Cowboy/Gun (cowlib) | yes | kept, reset in place |
| coder/websocket | yes | released after each message |
| websocketpp | no | kept across messages |
| libsoup (WebKitGTK/WPE) | no | kept across messages |
| Autobahn-python | yes | kept until replaced by a new one at the next message |
The tolerant implementations all still reset their own compressor when they agreed to no context takeover.
- Dominant language
- C++
- Stars
- 4.8k
- Forks
- 697
- Avg merge
- 20h 38m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/beast
-
http::message::keep_alive disagrees with the parser for repeated Connection fieldsPossibly taken @ashtum claimed this 24 days ago. OpenBug
boostorg/beast#3124 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
boostorg/beast#3092 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
boostorg/beast#3064 · 6 comments ·
Maintainers usually reply within 1 day
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day