-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[vcl] Avoid conditional hashing when possible #29360
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
Conversation
Hi @gquintard. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
Hi @ihor-sviziev, thank you for the review. |
|
Dev experience is required for testing of this PR. Please note that Manual testing has not been performed. |
@gquintard could you please describe how can I check it manually? |
Hi @engcom-Charlie , This PR plugs the exploit of this snippet: if (req.http.Store) {
hash_data(req.http.Store);
}
if (req.http.Content-Currency) {
hash_data(req.http.Content-Currency);
} To see it, you will need a page
With the old code, you should never be able to have both pages at the same time because their hashes will collide. Let me know if that's not clear, I'll be happy to discuss it in greater details |
@gquintard I try to check on 2.4-develop by the next scenario:
AR: Could you please take a look? |
@engcom-Charlie , alright, can you do please do this please:
It could be that magento is adding a |
Hi @gquintard . There are varnish logs on two requests:
|
alright, you are getting the right response because you are sending a if (req.method != "GET" && req.method != "HEAD") {
return (pass);
} if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
return (pass);
} So, the
And the question is: does that ever happens, and if it does, is Magento's response different based on the If yes, then you can test with this to confirm the VCL works, if no, then we can simplify the VCL because we are hashing useless data. |
@gquintard just checked on 2.4-develop by the next scenario:
AR: |
can show me some logs for those requests? (same |
@gquintard Yes of course |
Hi, So, looking at the logs, you are still getting passes, so Varnish is not caching anything:
and this is because of this VCL snippet:
Are you able to send requests without authorization headers? Alternatively, is it actually useful to try and cache |
Hi, |
Hi, We are almost there, promise. On this run, you used To recap, we need:
|
Hi, @gquintard . First request: Second request: |
There we go! The first request is a miss, and the second one is a hit, even though it shouldn't. This PR should take care of that |
hi, we are almost at the one-year anniversary of that PR, is there something I can do to make it happen? |
@gquintard can you rebase the code so we can proceed this one |
Conditional hashing can lead to collisions and should be avoided. As an example, this code: ``` vcl sub vcl_hash { if (req.http.a) { hash_data(req.http.a); } if (req.http.b) { hash_data(req.http.b); } } ``` will return the same hash for these two requests: ``` GET / HTTP/1.1 a: foo ``` and ``` GET / HTTP/1.1 b: foo ``` whereas ``` vcl sub vcl_hash { hash_data(req.http.a); hash_data(req.http.b); } ``` is correct and simpler.
@mrtuvn , here you go |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
Could somebody look at the test I added and point at where it would show up in the test results? |
I'm closing this and will reopen one, WITH TESTS! |
Hi @gquintard, Thank you for your contribution! As per this, should we close this PR. Let us know when you are ready with the test coverage, will reopen it. Thank you! |
yes, please close this one. |
This depends on #28928 and extends the
vcl_hash
clean up started there.Conditional hashing creates opportunities for collisions and should be avoided. It it's not possible, like in the case of the
X-Magento-Vary
cookie, a balancinghash_data
call is added.Note that it's not necessary to balance the calls in the
/graphql
since the URL is already part of the hash (via the built-in vcl) so we operate in a restricted subspace and collisions are not possible.Contribution checklist (*)