Skip to content

fix: reframe request body forwarded upstream in serverless plugins - #13798

Open
shreemaan-abhishek wants to merge 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/serverless-request-smuggling
Open

fix: reframe request body forwarded upstream in serverless plugins#13798
shreemaan-abhishek wants to merge 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/serverless-request-smuggling

Conversation

@shreemaan-abhishek

@shreemaan-abhishek shreemaan-abhishek commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

The openfunction, aws-lambda and azure-functions plugins share apisix/plugins/serverless/generic-upstream.lua. It forwarded every inbound client header verbatim, including Transfer-Encoding, while supplying the request body already de-chunked by nginx (ngx.req.get_body_data()).

resty.http then keeps Transfer-Encoding: chunked, drops Content-Length, and writes the now-unframed body raw without re-chunking. The forwarded upstream request advertised chunked framing over a body that had none, so a keep-alive upstream could misread where the message ends.

Fix: strip the client's Transfer-Encoding and Content-Length before forwarding, so the HTTP client recomputes a correct Content-Length from the actual body and never emits chunked framing over an unframed body. The strip runs before each plugin's request processor, so aws-lambda SigV4 signs a clean header set.

Added an end-to-end case in t/plugin/aws-lambda.t: a chunked client request through the plugin, asserting the upstream receives a reframed body with a correct Content-Length and no Transfer-Encoding.

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

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working plugin labels Aug 10, 2026
The openfunction, aws-lambda and azure-functions plugins share
generic-upstream.lua, which forwarded every inbound client header verbatim,
including Transfer-Encoding, while supplying the request body already de-chunked
by nginx. resty.http then kept Transfer-Encoding: chunked and wrote the unframed
body raw, so the upstream request advertised chunked framing over a body that
had none, letting the upstream misread the message length.

Drop transfer-encoding and content-length before forwarding so the http client
reframes the body with a correct Content-Length. Adds an end-to-end test that a
chunked client body reaches the upstream reframed.
@shreemaan-abhishek
shreemaan-abhishek force-pushed the fix/serverless-request-smuggling branch from cca5583 to 8d9df64 Compare August 10, 2026 11:18
@shreemaan-abhishek shreemaan-abhishek changed the title fix: strip client framing headers in serverless plugins fix: reframe request body forwarded upstream in serverless plugins Aug 10, 2026
AlinsRan
AlinsRan previously approved these changes Aug 11, 2026
…est-smuggling

# Conflicts:
#	apisix/plugins/serverless/generic-upstream.lua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working plugin size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants