Commit Graph

199 Commits

Author SHA1 Message Date
Ashish Sharma
e41ac40b86 fix(ws): enforce payload length encoding minimality and MSB constraints
Independently reported in parallel by DatanoiseTV <syso.berlin@icloud.com>
2026-09-04 12:03:15 +08:00
Ashish Sharma
ebd8108ccc fix(ws): reject RSV bits, reserved opcodes, fragmented control frames 2026-09-04 12:01:03 +08:00
Ashish Sharma
7d53b4740b fix(ws): enforce RFC 6455 §4.2.1 handshake requirements 2026-08-19 11:43:09 +08:00
Ashish Sharma
64287ae681 test(http_server): add mock TCP client for black-box WS testing 2026-08-19 11:43:08 +08:00
Mahavir Jain
a96952e277 Merge branch 'fix/httpd-content-length-truncation_v6.0' into 'release/v6.0'
fix(esp_http_server): reject Content-Length above UINT32_MAX (backport v6.0)

See merge request espressif/esp-idf!50493
2026-07-22 09:22:58 +05:30
Aditya Patwardhan
ce1dea564f fix(esp_http_server): reject Content-Length above UINT32_MAX
In httpd_parse.c, cb_headers_complete() converted the HTTP parser's
content_length (uint64_t) to the request's content_len (size_t) via an
unsafe cast through (int). On a 32-bit size_t target a Content-Length
above 4 GiB silently truncated, enabling request smuggling where the
server and an upstream proxy disagree on the body length (CWE-681).

Reject any Content-Length above UINT32_MAX with 413 Content Too Large
before any handler runs. UINT32_MAX is the largest body length the
server can represent in size_t content_len on every target, so this is
the maximum the server can support; no configuration knob is needed.

Closes SEC-102
Closes SEC-229

(cherry picked from commit 9d3f510c7f)
2026-07-20 10:29:46 +08:00
Ashish Sharma
ea005e8316 fix(esp_http_server): close UAF/double-free, buffer underflows, and OOB read 2026-07-16 18:24:47 +08:00
Benedek Brandschott
f1e3677381 fix(esp_http_server): report truncation when header value length matches buffer size
httpd_req_get_hdr_value_str() detected truncation with `val_size < full_size`, where full_size is the strlcpy() return value. strlcpy() returns strlen() of the source (the terminating null is not counted), so truncation actually occurs when strlen(src) >= val_size. At strlen(src) == val_size the value is copied as val_size - 1 chars + NUL (i.e. truncated) yet ESP_OK was returned, so the caller never learned the value was cut.

Use `val_size <= full_size` and correct the misleading comment about strlcpy()'s return value.

Same truncation-reporting class fixed for httpd_cookie_key_value in PR #16202; httpd_req_get_hdr_value_str was missed. No memory-safety impact: strlcpy() null-terminates if val_size > 0.
2026-07-10 14:40:24 +08:00
Ashish Sharma
9e8dc6cc7b test(httpd): cover URL query and header pointer accessors 2026-07-09 11:20:33 +08:00
Ashish Sharma
4341446b17 feat(httpd): add httpd_req_get_hdr_value_str_ptr() to avoid value copy 2026-07-09 11:20:33 +08:00
Ashish Sharma
1208d1c3b8 refactor(httpd): extract shared header field-value lookup helper 2026-07-09 11:20:33 +08:00
Ashish Sharma
60ce04db6d fix(httpd): validate buf_len in httpd_req_get_url_query_str_ptr() 2026-07-09 11:20:33 +08:00
0xFEEDC0DE64
629e6767fa feat(httpd): avoid useless string copy by introducing httpd_req_get_url_query_str_ptr() 2026-07-09 11:20:33 +08:00
Hrushikesh Bhosale
725e0b612d fix(esp_http_server): merge release/v6.0 to resolve backport conflict
Merge branch 'release/v6.0' into backport-48352-resolve to resolve a
conflict in esp_httpd_priv.h between this backport's sdkconfig.h
include and the ctrl-socket semaphore's freertos/semphr.h include.
2026-07-02 11:41:38 +05:30
Jiang Jiang Jian
0ad95fbb97 Merge branch 'fix/httpd_clang_tidy_missing_close_v6.0' into 'release/v6.0'
fix(network/http_server): fix clang-tidy warnings for missing close (v6.0)

See merge request espressif/esp-idf!49864
2026-06-29 15:42:34 +08:00
Ashish Sharma
64b488ebb3 fix(esp_http_server): take ctrl_sock_semaphore on shutdown and async wake
httpd_stop() and httpd_req_async_handler_complete() both pushed
messages onto the control mbox via cs_send_to_ctrl_sock() without
reserving a slot in ctrl_sock_semaphore. Once the silent-drop fix
made the semaphore unconditional, the bypass became a real bug:
when the mbox is saturated by pending httpd_queue_work() items the
unguarded sendto() can return ENOBUFS, and even when it succeeds it
leaves the semaphore overstating free slots until the consumer
drains the message — a window during which a concurrent
httpd_queue_work() can take a slot but still find the mbox full.

Acquire the semaphore (portMAX_DELAY) before both sends and give it
back on send failure so the take/give invariant is preserved. The
httpd task is the consumer in both paths, so blocking is bounded
and deadlock-free. Reword the stale "no-op give on full" comment in
httpd_process_ctrl_msg() to reflect that only the recv-error path
relies on the cap behavior now.
2026-06-25 10:41:17 +08:00
Ashish Sharma
8939340af8 fix(esp_http_server): prevent silent message drop in httpd_queue_work
Closes https://github.com/espressif/esp-idf/issues/18563
2026-06-25 10:41:17 +08:00
Tomas Rohlinek
25714429f0 fix(network/http_server): fix clang-tidy warnings for missing close
Cherry-picked from 68b37333049383659d6ea73fa11a1d942994535a
2026-06-22 11:01:48 +02:00
hrushikesh.bhosale
9bb92507ac fix(http_server): Removed the build failure due to unused variables
There were build failure due the unused variable last_error when
ESP_HTTPS_SERVER_EVENTS and HTTPD_ENABLE_EVENTS are disabled
2026-05-27 11:58:58 +05:30
Jimmy Wennlund
6036ec961d feat(esp_http_server): Make HTTP(S)_SERVER_EVENT events optional
Make it possible to disable http(s) server events. This improves
performance of the server, as http server creates events on every signle
read or write to the socket.
2026-05-27 11:58:58 +05:30
Ashish Sharma
a493b3f890 fix(esp_http_server): fixes websocket recv error handling
Closes https://github.com/espressif/esp-idf/issues/18483
2026-05-10 19:25:59 +08:00
Ashish Sharma
6a36ec6d07 feat(esp_http_server): adds check for crlf in response creation 2026-04-13 10:32:24 +08:00
Ashish Sharma
a519271c3e fix: fixes memory leak with subprotocols 2026-03-23 18:41:42 +08:00
Ashish Sharma
0dc4ee7537 fix: fixes websocket server possible null dereference 2026-03-23 18:41:42 +08:00
Peter Backeris
b830f81296 fix(esp_http_server): Dispatch PONG frames to WebSocket handler
PONG frames (opcode 0xA) were never dispatched to the user's WebSocket
handler despite an existing comment stating they should be. The dispatch
condition `ra->ws_type < HTTPD_WS_TYPE_CLOSE` excluded PONG (0xA)
since CLOSE is 0x8.

This caused a critical secondary bug: when the server sends PING frames
and the client responds with PONG, httpd_ws_recv_frame() is never
called for the PONG, leaving the remaining frame bytes (second_byte
plus 4-byte mask_key) unconsumed in the TCP buffer. On the next
WebSocket read, these orphaned bytes are misinterpreted as a new frame
header, causing either "WS frame is not properly masked" errors or
EAGAIN timeouts with garbage length values, effectively destroying
the connection.

Add `ra->ws_type == HTTPD_WS_TYPE_PONG` to the dispatch condition so
PONG frames reach the user handler, which calls httpd_ws_recv_frame()
to properly consume the frame bytes from the socket.

Closes https://github.com/espressif/esp-idf/issues/18227
2026-03-20 15:10:52 +08:00
Jiang Jiang Jian
b32f2828aa Merge branch 'fix/remove_unused_psa_migration_code_http_server_v6.0' into 'release/v6.0'
Fix/remove unused psa migration code http server (v6.0)

See merge request espressif/esp-idf!46558
2026-03-20 10:46:35 +08:00
Ashish Sharma
4e9367bc41 fix(esp_http_server): fix ws server subprotocol match 2026-03-12 17:03:21 +08:00
Ashish Sharma
222d470312 feat(http_server): improve websocket server handling
1. Adds post handshake callback
2. Removes requirement to handle HTTP_GET message in websocket handler

Closes https://github.com/espressif/esp-idf/issues/18215
2026-03-04 14:00:12 +08:00
Jiang Jiang Jian
b89e7a0fbc Merge branch 'fix/fix_possible_ws_server_deadlock_v6.0' into 'release/v6.0'
fix: fix potential ws server deadlock with blocking work queue (v6.0)

See merge request espressif/esp-idf!45364
2026-01-30 14:29:59 +08:00
Ashish Sharma
0559222711 fix: stop reading ws data when peer closes the connection
Closes https://github.com/espressif/esp-idf/issues/17822
2026-01-22 18:16:26 +08:00
Ashish Sharma
63f3072c9c fix: fixes potential ws server deadlock with blocking work queue
Closes https://github.com/espressif/esp-idf/issues/17591
2026-01-22 18:10:24 +08:00
Aditya Patwardhan
574a60289d feat(protocomm): Migrate to PSA api interface 2025-12-18 21:18:58 +08:00
Aditya Patwardhan
eb5e92063f feat(mbedtls): Update the protocol components with PSA APis 2025-12-18 21:18:58 +08:00
hrushikesh.bhosale
cfc056018c fix(esp_http_server): Fix async requests on same socket blocking issue
1. In async requests, if the two or more requests are made on same
socket then it used to block the second request.
2. The main thread is used to block on select call. And there done
no FD_SET for particular fd.

Closes https://github.com/espressif/esp-idf/issues/16998
2025-09-16 15:02:05 +05:30
Joonline
9e7074dd35 fix(http_server): Corrected initialization value for lru_counter at http session creation
Closes https://github.com/espressif/esp-idf/pull/17470
2025-09-12 15:31:27 +08:00
Mahavir Jain
b789445a67 Merge branch 'contrib/github_pr_17501' into 'master'
fix(esp_http_server): fix memory leak in httpd_req_async_handler_begin (GitHub PR)

Closes IDFGH-16361

See merge request espressif/esp-idf!41748
2025-09-10 13:15:36 +05:30
Salvatore Mesoraca
fd33d02563 fix(esp_http_server): fix memory leak in httpd_req_async_handler_begin
Free scratch memory when response headers allocation fails
2025-08-29 02:11:13 +02:00
Alexey Lapshin
28ced4efad fix(config): actualize newlib Kconfig options 2025-08-28 12:25:09 +08:00
Marek Fiala
9d35d63651 feat(cmake): Update minimum cmake version to 3.22 (whole repository) 2025-08-19 14:44:32 +02:00
Marius Vikhammer
4065fb20f3 Merge branch 'feature/esp_test_utils_component' into 'master'
change(test_utils): moved test_utils out of unit-test-app project

See merge request espressif/esp-idf!40678
2025-08-01 11:04:37 +08:00
Aditya Patwardhan
a783974d00 Merge branch 'feat/support_authentication_feature_for_ws' into 'master'
Added pre handshake callback for websocket

Closes IDF-13605

See merge request espressif/esp-idf!40706
2025-07-31 15:04:07 +05:30
hrushikesh.bhosale
a40ceffb19 feat(esp_http_server): Added pre handshake callback for websocket
1. If the user wants authenticate the request, then user needs to do
this before upgrading the protocol to websocket.
2. To achieve this, added pre_handshake_callack, which will execute
before handshake, i.e. before switching protocol.
2025-07-31 11:06:18 +05:30
Ashish Sharma
6b02906822 fix(security): improve memory allocation handling in multiple components 2025-07-28 10:05:50 +08:00
Marius Vikhammer
bf84ab652a change(test_utils): moved test_utils component to tools/test_apps/components/ 2025-07-21 14:05:50 +08:00
Mahavir Jain
464d03f999 Merge branch 'contrib/github_pr_15767' into 'master'
fix(esp_http_server): WebSocket frame parsing errors (GitHub PR)

Closes IDFGH-15086 and IDFGH-14461

See merge request espressif/esp-idf!40076
2025-07-16 13:58:37 +05:30
Vincent Hamp
ab07377b11 fix(esp_http_server): WebSocket frame parsing errors
Fixes the Websocket frame pasring error, by making sure
that two bytes are read compulsary for length bytes 126.

Closes https://github.com/espressif/esp-idf/pull/15767
Closes https://github.com/espressif/esp-idf/issues/15235
2025-07-15 11:26:35 +05:30
hrushikesh.bhosale
9f6ab55a5b feat(http_server): Added API to get scratch buffer data
1. Added the API in esp_http_server to get the raw headers data
from the scratch buffer.
2. This data will be unparsed.

Closes https://github.com/espressif/esp-idf/issues/15857
2025-07-09 18:36:52 +05:30
iranl
42704821d2 fix(esp_http_server): Fix regression in httpd_cookie_key_value
Fix regression in httpd_cookie_key_value introduced by commit 4a47cf8
2025-07-02 08:39:20 +02:00
hrushikesh.bhosale
542d07d34a feat(http_server): httpd register handler strdup failure case check
In httpd_register_uri_handler api, for the strdup function failure case was not
checked and not returned any error by freeing previously allocated memory, if the memory
allocation for strdup function did not gets successful.

Closes https://github.com/espressif/esp-idf/issues/15878
2025-05-13 11:27:02 +05:30
hrushikesh.bhosale
b6d4fa2c2e fix(async_handler): Async handler example scratch buffer fix
1. In httpd_req_async_handler_begin, the httpd_req_aux is locally malloced
and data is  done memcpy to local httpd_req_aux from request'ss httpd_req_aux for
async request use-case, this causes scartch pointer from these two structs
pointing to same memory address.
2. In current workflow, the request's sratch buffer is freed in httpd_parse.c
httpd_req_cleanup api. Therefore if the user try to fetch the data (like headers)
from the scratch buffer, data will be not available.
3. Each request should have the deep copy of the scratch buffer. To retrive
the data later.

Closes https://github.com/espressif/esp-idf/issues/15587
2025-04-28 14:57:21 +08:00