Files

4.4 KiB

Task Spec: M-NET-01..05 — P2 Network Hardening, Native HTTP/1.1 Codec, Connection Pool, Safe Static Open & RFC 6455 WebSockets

  • Branch: feat/roadmap-p2-wave9 (baseline main at 3e25405, building on VL-004/VL-005 in 66baae7 + 9920bfd).
  • Roadmap authority: docs/roadmap/modules/Net.md (M-NET-01..M-NET-05), ARCHITECTURE.md C-02..C-06, C-11, C-13.
  • Error domain: Void::Result::kNetErrorDomain = 26 (NetErrorCode in include/Void/Net/Http.hpp).

Scope & Deliverables

  1. Native Incremental HTTP/1.1 Codec (include/Void/Net/HttpCodec.hpp, src/Net/HttpCodec.cpp):
    • HttpCodecLimits (defaults: max_start_line_bytes = 8 KiB, max_header_bytes = 32 KiB, max_headers = 100, max_body_bytes = 8 MiB, max_chunk_ext_bytes = 1 KiB, max_trailer_bytes = 8 KiB).
    • HttpRequestParser and HttpResponseParser: byte-by-byte / arbitrary-split incremental RFC 9110/9112 state machines.
    • Strict CRLF framing, header field-name token validation, rejection of duplicate/conflicting Content-Length, rejection of Transfer-Encoding + Content-Length smuggling ambiguity, handling of 1xx informational responses, HEAD/204/304 no-body responses, chunked transfer encoding with chunk extensions and trailers, close-delimited response bodies (finish_eof()), and explicit connection_reusable() check.
  2. Bounded HTTP/1.1 Connection Pool (include/Void/Net/Pool.hpp, src/Net/Pool.cpp):
    • PoolLimits (defaults: max_total_connections = 256, max_per_origin = 8, max_idle_connections = 128, idle_timeout = 30s).
    • PoolKey keyed by {scheme, host, port, proxy_identity, tls_policy_generation} (so changing proxy or trust generation never reuses stale connections).
    • ConnectionPool using injectable Void::Time::MonotonicClock for deterministic idle eviction, returning RAII ConnectionLease handles that only return clean, reusable connections to the pool (mark_reusable(true)); abandoned/unmarked/dirty/expired leases close cleanly.
  3. Descriptor-Pinned Static File Opening (include/Void/Net/Server.hpp, src/Net/Server.cpp):
    • OpenedStaticFile (move-only RAII descriptor + content_type + size, read_all(), native_handle()).
    • StaticFileResolver::open_safe(std::string_view request_path) walking components beneath a retained root directory fd (O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC), rejecting symlinks/traversal/non-regular files without pathname TOCTOU.
  4. Redirect Compliance in HttpClient (src/Net/Http.cpp):
    • Follow only 301, 302, 303, 307, 308; 303 converts non-HEAD to GET and strips body + Content-Length/Content-Type; 307/308 preserve method/body; resolve relative Location references against current URL; reject HTTPS->HTTP downgrade unless allow_insecure_redirects; strip Authorization, Cookie, Proxy-Authorization, X-Api-Key on cross-origin hops; enforce single absolute steady deadline across redirect hops.
  5. Native RFC 6455 WebSocket Wire Framing & Loopback Transport (include/Void/Net/WebSocket.hpp, src/Net/WebSocket.cpp, include/Void/Net/HttpServer.hpp, src/Net/HttpServer.cpp):
    • compute_websocket_accept(key) (RFC 6455 SHA-1 + Base64), validate_websocket_upgrade_request() (version 13, Upgrade: websocket, Connection: Upgrade, 16-byte base64 key, optional origin/subprotocol policy).
    • WebSocketOpcode, WebSocketLimits (max_message_bytes = 1 MiB, max_output_messages = 64, max_output_bytes = 4 MiB), WebSocketFrame, encode_websocket_frame(), WebSocketFrameDecoder enforcing client masking / server non-masking, fragmentation, control-frame rules (<= 125 bytes, FIN=1), strict RFC 3629 UTF-8 validation for text frames & close reasons, ping/pong, and single close handshake.
    • HttpServer::add_websocket_route(pattern, WebSocketSessions&, WebSocketUpgradeOptions) upgrading incoming HTTP/1.1 requests into live RFC 6455 connections integrated with WebSocketSessions, plus loopback WebSocketClient for full client/server wire verification.

Verification

  • Standalone Net;Testing (-DVOID_WARNINGS_AS_ERRORS=ON): split-byte smuggling & chunked/trailer/1xx/HEAD codec corpus, pool eviction & key isolation, open_safe symlink-swap rejection, redirect 303/307/relative/cross-origin tests, RFC 6455 wire & loopback WebSocketClient/HttpServer ping/pong/fragmented/UTF-8/close/shutdown tests.
  • ctest NetOnly installed consumer, full RelWithDebInfo, Debug ASan+UBSan, Debug TSan.