Skip to content

feat(hmac-auth): add max_req_body_size to bound client request body during validation#13478

Merged
shreemaan-abhishek merged 1 commit into
apache:masterfrom
shreemaan-abhishek:feat/hmac-auth-max-req-body-size
Jun 9, 2026
Merged

feat(hmac-auth): add max_req_body_size to bound client request body during validation#13478
shreemaan-abhishek merged 1 commit into
apache:masterfrom
shreemaan-abhishek:feat/hmac-auth-max-req-body-size

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

The hmac-auth plugin reads the entire client request body into memory to verify the digest when validate_request_body is true. Today that read (core.request.get_body()) has no upper bound, so a client can force a worker to buffer an arbitrarily large body. The only existing backstop is the global nginx client_max_body_size, which operators routinely raise or disable for upload routes.

This adds a max_req_body_size option (integer, default 67108864 = 64 MiB, minimum 1) to hmac-auth, so that when body validation is enabled, oversized requests are rejected with 413 before the body is buffered:

  • hmac-auth: caps the body read for digest validation (passed to core.request.get_body()); enforced only on the validate_request_body = true path.

This complements the body-size hardening series started in #13466, which added max_req_body_size to forward-auth, ai-proxy, and ai-proxy-multi. That PR deliberately excluded hmac-auth; this PR closes that gap with the same default, the same 413 rejection behavior, and the same schema/docs conventions.

Docs and e2e tests are included.

⚠️ Default behavior change

hmac-auth now defaults max_req_body_size to 64 MiB. The change is observable only when all of the following hold:

  1. the route uses hmac-auth with validate_request_body = true; and
  2. the operator has raised nginx client_max_body_size above 64 MiB (or set it to 0); and
  3. a client sends a request body larger than 64 MiB.

In that case the request is now rejected with 413 instead of being buffered in full. Under the default client_max_body_size (1 MiB) there is no change. The limit is configurable via max_req_body_size to restore prior behavior.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (see the documented default behavior change above; configurable via max_req_body_size)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jun 8, 2026
@membphis

membphis commented Jun 8, 2026

Copy link
Copy Markdown
Member

One test needs to be updated before merge. This PR adds max_req_body_size to the hmac-auth route/service schema, but t/plugin/hmac-auth2.t still asserts the exact old response body for /apisix/admin/schema/plugins/hmac-auth. Once the admin schema includes the new property, that test should fail deterministically.

Please update the expected schema JSON, or narrow the assertion to the relevant schema fields, so it includes the new max_req_body_size property.

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor Author

hmac-auth2.t TEST 2 isn't an exact-match assertion. test_admin.test uses com_tab, which only checks the expected pattern is a subset of the response, ignoring extra keys. The expected JSON already omits signed_headers.default, realm, and anonymous_consumer and still passes. max_req_body_size is just another un-asserted extra key, so the test stays green — confirmed by the passing t/plugin/[a-k]*.t CI job.

@shreemaan-abhishek
shreemaan-abhishek merged commit 7f2eaa7 into apache:master Jun 9, 2026
22 checks passed
wistefan pushed a commit to wistefan/apisix that referenced this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants