Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:6.4fromthecaliskan:7.2
May 30, 2025

Conversation

thecaliskan
Copy link

@thecaliskanthecaliskan commentedMay 26, 2025
edited by GromNaN
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
Issues-
LicenseMIT

📝 Purpose

This MR updates the regular expression used to extract the HTTP protocol version from theVia header in theRequest::getProtocolVersion() method.

🎯 Summary of Changes

Old regex:

~^(HTTP/)?([1-9]\.[0-9]) ~

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:

~^(HTTP/)?([1-9]\.[0-9])\b~

✅ Benefits

  • Replaces dependency on a trailing space with\b (word boundary), allowing the regex to match both space-terminated and non-space-terminated inputs.
  • Correctly handles commonVia header formats such as:
    • HTTP/1.1
    • 2.0
    • HTTP/2.0 nginx-proxy
    • 1.1 custom-hop
  • Ensures compatibility with reverse proxy configurations (e.g., Nginx, Traefik) where theVia header may vary in format.
  • Improves robustness and reliability of HTTP version detection in proxied environments.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.3 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbotcarsonbot changed the titleFixed 'Via' header regex[HttpFoundation] Fixed 'Via' header regexMay 26, 2025
@GromNaN
Copy link
Member

GromNaN commentedMay 26, 2025
edited
Loading

Hello@thecaliskan,
Thank you very much for working on this PR. Since it's a bug fix, it should target the oldest supported version, which iscurrently 6.4. We can change the target version before merging, but you can also force-push on the branch to apply the commit on top of the branch 6.4.

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?

@thecaliskan
Copy link
Author

Hello@GromNaN,
Thank you for the feedback! 🙏

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:

proxy_set_header Via $server_protocol;

This results in headers such as:

Via: HTTP/2.0

or

`Via: HTTP/1.1`

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!

@MatTheCat
Copy link
Contributor

Via: HTTP/2.0 looks invalid since it doesn’t include a pseudonym.https://httpwg.org/specs/rfc9110.html#field.via says it’s required.

@nicolas-grekasnicolas-grekas modified the milestones:7.2,6.4May 30, 2025
@nicolas-grekas
Copy link
Member

Thank you@thecaliskan.

@nicolas-grekasnicolas-grekas merged commitf405d3a intosymfony:6.4May 30, 2025
1 check failed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@OskarStarkOskarStarkAwaiting requested review from OskarStark

@jderussejderusseAwaiting requested review from jderusse

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

5 participants
@thecaliskan@carsonbot@GromNaN@MatTheCat@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp