Skip to content

Limit conn, limit req, stream limit conn: reject an overlong key - #1583

Draft
VadimZhestikov wants to merge 2 commits into
nginx:masterfrom
VadimZhestikov:fix/limit-overlong-key-failclosed
Draft

Limit conn, limit req, stream limit conn: reject an overlong key#1583
VadimZhestikov wants to merge 2 commits into
nginx:masterfrom
VadimZhestikov:fix/limit-overlong-key-failclosed

Conversation

@VadimZhestikov

@VadimZhestikov VadimZhestikov commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

When the evaluated key exceeded the storable length (255 bytes for limit_conn, 65535 for limit_req), the modules logged an error and continued, silently skipping the limit -- so a request/connection with an overlong key was not limited (fail-open). With a single zone in the location it passed unlimited.

The overlong-key branch now fails closed: the request/connection is rejected like any other limited one (honouring dry_run, and releasing already-locked/registered state first). Keys within the length limit -- including the usual $binary_remote_addr -- are unaffected (that branch is never taken for bounded keys).

Covers three modules, in separate commits:

  • ngx_http_limit_conn_module and ngx_http_limit_req_module -- reject with the configured limit_*_status code.
  • ngx_stream_limit_conn_module -- reject the connection (NGX_STREAM_SERVICE_UNAVAILABLE). (There is no stream limit_req -- limit_req is http-only.)

Priority / type

Low-priority hardening (fail-open -> fail-closed).

Testing

Built with -Werror.

  • http: with a key from a request header, short key -> 200, overlong key (>255 for limit_conn, >65535 for limit_req) -> 503.
  • stream: with a zone keyed on an overlong value, under limit_conn 1, all concurrent connections were accepted before the change (fail-open) and are rejected after it; a bounded key is unaffected.

Test PR: nginx/nginx-tests#87 (http limit_conn.t / limit_req.t and stream stream_limit_conn.t).

When the evaluated key exceeded the length the modules can store (255
bytes for limit_conn, 65535 for limit_req), the request was logged and
the limit was silently skipped with "continue", so a request with an
overlong key was not limited (fail-open).

Such a request is now rejected with the configured status code, like any
other limited request, so an oversized key can no longer be used to
escape the limit.  Keys within the length limit, including the usual
$binary_remote_addr, are unaffected.

Reported by Hcamael.
@saikrishnakumarreddy

Copy link
Copy Markdown
Contributor

how about similar fix in stream limit conn module?

@saikrishnakumarreddy
saikrishnakumarreddy self-requested a review July 22, 2026 02:43
When the evaluated key exceeded the length the module can store (255
bytes), the connection was logged and the limit was silently skipped
with "continue", so a connection with an overlong key was not limited
(fail-open).

Such a connection is now rejected, like any other limited connection,
so an oversized key can no longer be used to escape the limit.  Keys
within the length limit, including the usual $binary_remote_addr, are
unaffected.

Reported by Hcamael.
@VadimZhestikov

Copy link
Copy Markdown
Contributor Author

how about similar fix in stream limit conn module?

Good call -- stream limit_conn had the identical fail-open (if (key.len > 255) { ...; continue; }), so an
overlong key escaped the limit. Reproduced under limit_conn 1: 4/4 concurrent connections passed with an overlong
key vs 1/4 for a bounded key.

Added a commit that fails it closed the same way (releases state, honours limit_conn_dry_run, rejects the
connection); overlong now 0/4, bounded unchanged. There's no stream limit_req (http-only), so that's the only stream
module affected. Test PR nginx/nginx-tests#87 updated with a stream_limit_conn.t case (TODO until released).

@VadimZhestikov VadimZhestikov changed the title Limit req, limit conn: reject requests with an overlong key Limit conn, limit req, stream limit conn: reject an overlong key Jul 22, 2026
@sindhushiv sindhushiv modified the milestones: nginx-1.31.4, nginx-1.31.5 Jul 23, 2026
@Maryna-f5 Maryna-f5 modified the milestones: nginx-1.31.5, nginx-1.31.6 Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants