-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Fixed 'Via' header regex #60547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.4
Are you sure you want to change the base?
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Hello @thecaliskan, In order to have all the information we need if we ever work on this part of the code again later, could you tell us the exact scenario in which you encountered the problem? Which proxy server do you use? |
Hello @GromNaN, I’ve updated the PR to target the 6.4 branch as requested and force-pushed the changes accordingly. The issue was encountered while running the application behind Nginx as a reverse proxy. Specifically, the problem is related to detecting the protocol version used between the client and the proxy. In Nginx, the Via header can be forwarded using the following configuration:
This results in headers such as:
or
depending on the protocol version. The Symfony code tries to parse this value using a regular expression, but the original regex expected a trailing space, which is not present in Nginx’s output. This causes the match to fail and fall back to the default SERVER_PROTOCOL. This PR adjusts the regular expression to support both variants, with or without a trailing space, to ensure compatibility with real-world proxy headers such as those set by Nginx. 📚 Reference:
Let me know if you'd like me to include a test case or further clarify anything. Thanks again! |
|
📝 Purpose
This MR updates the regular expression used to extract the HTTP protocol version from the
Via
header in theRequest::getProtocolVersion()
method.🎯 Summary of Changes
Old regex:
This pattern failed to match valid values like HTTP/1.1 or 2.0 when there was no trailing space. As a result, values passed from proxies (e.g., via proxy_set_header Via $server_protocol;) were not detected correctly.
New regex:
✅ Benefits
\b
(word boundary), allowing the regex to match both space-terminated and non-space-terminated inputs.Via
header formats such as:HTTP/1.1
2.0
HTTP/2.0 nginx-proxy
1.1 custom-hop
Via
header may vary in format.