Hardened WebSocket transport and permessage-deflate for RFC 6455/7692 conformance

Fixed the client permessage-deflate encoder, which stripped the flush trailer on every
fragment and could truncate a SYNC_FLUSH, so a compressed message split across frames now
decodes, and an empty final fragment is encoded as a single 0x00 octet; the frame writer
derives the masking key from SecureRandom. The client no longer offers client_max_window_bits,
since the JDK Deflater cannot honour a reduced window, and rejects a handshake response that
echoes it. The session engine fails the connection on RSV1 set on a control frame, no longer
delivers a truncated message after a 1009 close, and surfaces a selection key cancelled during
shutdown as an I/O error on write so the engine takes its close path instead of retaining the
frame as back-pressure.

Extension negotiation on the server is stricter. Offers are parsed from every
Sec-WebSocket-Extensions field and combined as RFC 6455 requires, so a client's fallback offer
in a later field is still examined; a parameter repeated within an offer drops that offer; and
the permessage-deflate factory accepts only recognised parameters with well-formed values, the
no-context-takeover parameters carrying no value and the window-bits parameters being exactly
15, the only size the JDK Deflater supports. A given extension name is accepted only once, and
an unacceptable offer is declined rather than failing the handshake.

On the HTTP/2 server the handler advertises a bounded inbound flow-control window and bounds
the outbound queue by a byte budget, splitting large writes into chunks and signalling the
reactor after each so a write larger than the budget cannot deadlock; the frame reader rejects
a 64-bit length with the most significant bit set, the frame writer enforces the 125-byte
control frame limit and truncates the CLOSE reason, and the processor fails a data frame
received in the middle of a fragmented message. The HTTP/2 client accepts any 2xx handshake
response.

Both permessage-deflate implementations release their Deflater and Inflater when the session
ends. The extension chains close every codec they hold even if one of them fails, the
negotiation closes each extension exactly once, and the session engine coordinates the encoder
and decoder close with try/finally so a failure in one still releases the other.
39 files changed
tree: 9b27c87e55d30f648e6679505476a609a44d7099
  1. .github/
  2. .mvn/
  3. httpclient5/
  4. httpclient5-cache/
  5. httpclient5-fluent/
  6. httpclient5-jakarta-rest-client/
  7. httpclient5-observation/
  8. httpclient5-sse/
  9. httpclient5-testing/
  10. httpclient5-websocket/
  11. src/
  12. test-CA/
  13. .asf.yaml
  14. .gitattributes
  15. .gitignore
  16. BUILDING.txt
  17. CODE_OF_CONDUCT.md
  18. doap_HttpComponents_Client.rdf
  19. LICENSE.txt
  20. mvnw
  21. mvnw.cmd
  22. NOTICE.txt
  23. pom.xml
  24. README.md
  25. RELEASE_NOTES.txt
  26. run-example.sh
  27. SECURITY.md
README.md

Apache HttpComponents Client

Welcome to the HttpClient component of the Apache HttpComponents project.

GitHub Actions Status Maven Central License

Building Instructions

For building from source instructions please refer to BUILDING.txt.

Dependencies

HttpClient main module requires Java 8 compatible runtime and depends on the following external libraries:

Other dependencies are optional.

(for detailed information on external dependencies please see pom.xml)

Protocol conformance

  • RFC 9110 - HTTP Semantics
  • RFC 9111 - HTTP Caching
  • RFC 9112 - Hypertext Transfer Protocol Version 1.1 (HTTP/1.1)
  • RFC 9113 - Hypertext Transfer Protocol Version 2 (HTTP/2)
  • RFC 7541 - HPACK: Header Compression for HTTP/2
  • RFC 1945 - Hypertext Transfer Protocol -- HTTP/1.0
  • RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax
  • RFC 6265 - HTTP State Management Mechanism (Cookies)
  • RFC 7616 - HTTP Digest Access Authentication
  • RFC 7617 - HTTP ‘Basic’ Authentication Scheme
  • RFC 5861 - HTTP Cache-Control Extensions for Stale Content
  • RFC 2817 - Upgrading to TLS Within HTTP/1.1
  • RFC 9218 - Extensible Prioritization Scheme for HTTP
  • RFC 7804 - Salted Challenge Response HTTP Authentication Mechanism
  • RFC 10008 - The HTTP QUERY Method

Licensing

Apache HttpComponents Client is licensed under the Apache License 2.0. See the files LICENSE.txt and NOTICE.txt for more information.

Contact

Cryptographic Software Notice

This distribution may include software that has been designed for use with cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See https://www.wassenaar.org/ for more information.

The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache Software Foundation distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.

The following provides more details on the included software that may be subject to export controls on cryptographic software:

Apache HttpComponents Client interfaces with the Java Secure Socket Extension (JSSE) API to provide

  • HTTPS support

Apache HttpComponents Client does not include any implementation of JSSE.