You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting the nginx option passenger_request_buffering off; corrupts requests larger than ~10 KB.
With that option set, nginx buffers the headers and first part of the request body in memory rather than a temporary file. After opening a connection to the Passenger socket, nginx sends all these initial buffers at once. However, if the request is big enough for the body to require more than a couple of buffers (e.g. a file upload), the first two buffers get duplicated when they are sent to Passenger. I believe the end of the body (overflow after Content-Length) gets discarded, but I'm not sure in what part of the stack. The result is a request body with the right size but corrupted contents.
At the indicated place above five buffers get written, corresponding to the request headers (rewritten with Passenger annotations) and the first two request body buffers, twice. This can be confirmed by using strace on the nginx worker (relevant section formatted for clarity):
Question 5: Your app's programming language (including any version managers) and framework (including versions):
Ruby 3.1 / rack 3.1.8 (sample app) and ruby 3.3.6 / rails 8.0 (production)
Question 6: Are you using a PaaS and/or containerization? If so which one?
Docker (sample app) and Debian 12 VM (production).
Question 7: Anything else about your setup that we should know?
Once or twice the problem seemed to resolve after restarting nginx during troubleshooting, so it might not be entirely deterministic.
The text was updated successfully, but these errors were encountered:
thedanbob
changed the title
passenger_request_buffering off corrupts file uploadspassenger_request_buffering off corrupts request body
Nov 19, 2024
Issue report
Question 1: What is the problem?
Setting the nginx option
passenger_request_buffering off;
corrupts requests larger than ~10 KB.With that option set, nginx buffers the headers and first part of the request body in memory rather than a temporary file. After opening a connection to the Passenger socket, nginx sends all these initial buffers at once. However, if the request is big enough for the body to require more than a couple of buffers (e.g. a file upload), the first two buffers get duplicated when they are sent to Passenger. I believe the end of the body (overflow after Content-Length) gets discarded, but I'm not sure in what part of the stack. The result is a request body with the right size but corrupted contents.
Repo with a sample app and reproduction steps: https://github.com/thedanbob/passenger-bug
Sample nginx debug logs:
At the indicated place above five buffers get written, corresponding to the request headers (rewritten with Passenger annotations) and the first two request body buffers, twice. This can be confirmed by using strace on the nginx worker (relevant section formatted for clarity):
It can also be confirmed by inspecting the resulting file.
Question 2: Passenger version and integration mode:
Open source Passenger 6.0.23/nginx 1.22.1
Question 3: OS or Linux distro, platform (including version):
Debian 12, x86_64
Question 4: Passenger installation method:
Phusion APT repo
Question 5: Your app's programming language (including any version managers) and framework (including versions):
Ruby 3.1 / rack 3.1.8 (sample app) and ruby 3.3.6 / rails 8.0 (production)
Question 6: Are you using a PaaS and/or containerization? If so which one?
Docker (sample app) and Debian 12 VM (production).
Question 7: Anything else about your setup that we should know?
Once or twice the problem seemed to resolve after restarting nginx during troubleshooting, so it might not be entirely deterministic.
The text was updated successfully, but these errors were encountered: