fix(forward-auth): re-frame buffered POST body for the auth request#13642
Open
shreemaan-abhishek wants to merge 1 commit into
Open
fix(forward-auth): re-frame buffered POST body for the auth request#13642shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
The POST path buffers the client body and re-sends it as a whole to the auth service, but still forwarded the client Transfer-Encoding, Content-Length and Expect headers. After the body is de-chunked and buffered those framing headers no longer match, so the auth service can receive a Transfer-Encoding: chunked request whose body is not chunk-framed. Only keep Content-Encoding, which still applies to the buffered bytes, and let the http client set a fresh Content-Length.
There was a problem hiding this comment.
Pull request overview
This PR fixes an inconsistency in the forward-auth plugin when request_method: POST is used with a buffered request body by stopping the plugin from copying client-side framing headers (Transfer-Encoding, Content-Length, Expect) into the auth subrequest, and adding a regression test to ensure chunked client POSTs are re-framed correctly for the auth request.
Changes:
- Stop forwarding client
Transfer-Encoding/Content-Length/Expectheaders on the POST auth-request path; keep onlyContent-Encoding. - Add a test route that captures what framing headers the auth service actually receives.
- Add a regression test that sends a chunked POST and asserts the auth service does not see
Transfer-Encoding: chunked.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apisix/plugins/forward-auth.lua | Removes forwarding of framing headers for buffered POST auth requests (keeps Content-Encoding). |
| t/plugin/forward-auth.t | Adds regression coverage for chunked POST re-framing behavior seen by the auth endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nic-6443
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
forward-authis configured withrequest_method: POST, the plugin buffers the client request body and re-sends it as a whole to the auth service. However it also copied the client'sTransfer-Encoding,Content-LengthandExpectheaders verbatim into the auth request.Once the body has been read it is de-chunked and buffered, so those framing headers no longer describe the bytes actually sent. In particular, a client using
Transfer-Encoding: chunkedcaused the auth service to receive aTransfer-Encoding: chunkedrequest whose body was not chunk-framed, leaving the auth request internally inconsistent.These framing headers were originally added when the body was streamed to the auth service via a body reader (#10589). That streaming path was later reverted to a buffered body (#12404), but the header copy was left behind and no longer matches the buffered send.
This change keeps only
Content-Encoding(which still applies to the buffered bytes, since nginx does not decode request content-encoding) and lets the HTTP client set a fresh, correctContent-Lengthfor the buffered body.Transfer-Encoding,Content-LengthandExpectare no longer forwarded from the client on the POST path.Which issue(s) this PR fixes:
Fixes #
Checklist