-
Notifications
You must be signed in to change notification settings - Fork 517
Fix header corruption due to comma treated as header separators #5678
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
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
The splitting here definitely looks wrong. At the very least it needs to be taking quoted strings into consideration. That said, any change on this is likely to need a compatibility flag as changing this is likely breaking for existing workers. |
|
On my side, this change has corrected my workers, not broken them! No more incorrectly sent UAs! |
|
Understood. However, it's conceivable that changing this could break other workers, which means fixing it would require a compatibility flag so that those existing workers would be unaffected by the change. |
|
Compat flags can be inspected using the |
|
Yeah maybe we should do |
|
If I remember correctly, I believe @anonrig has some code in the node compat stuff for parsing headers out with quoted strings handled as part of the |
|
Looking at the node.js implementation I see |
|
I think there’s a conceptual mix-up here between:
Many standard headers legitimately contain commas, and commas do not imply "multiple header instances" unless the specific header definition says so (and even then quoted strings must be respected). So I don’t think the fix should be "split appropriately". The fix should be "do not split at all at this layer". What do you think @dom96? |
|
Well, when I say we need to split the headers up appropriately I mean we need to handle the |
dom96
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a real bug, I think your fix is a good start, just needs to handle the Set-Cookie case, add a compat flag and make some changes to our tests.
If you're up for that, I can give you some hints on what changes you need:
- Add a flag that is similar to https://github.com/cloudflare/workerd/blob/main/src/workerd/io/compatibility-date.capnp#L1198-L1201 with an enable date that's 3 weeks in the future
- Access those compat flags using the new module that was introduced here: #5713
- You'll need to change the existing
Requestheader tests in https://github.com/cloudflare/workerd/blob/main/src/workerd/server/tests/python/sdk/worker.py#L410-L418 and add some new tests too (for user-agent and set-cookie). - You'll also need to add the new compat flag you added to https://github.com/cloudflare/workerd/blob/main/src/workerd/server/tests/python/sdk/sdk.wd-test#L10
If you want to run the test you can use bazel run //src/workerd/server/tests/python:sdk_0.28.2@
Totally understand if that's too much, just let me know and I'll open a PR, but since you created this one I wanted to give you a chance to complete it :)
|
I am keen on giving-it a try. Could you please tell me how to verify that everything is good when I want to test my changes? |
|
Running |
|
Thanks for your help with this @n3rada! |
CodSpeed Performance ReportMerging this PR will degrade performance by 42.52%Comparing Summary
Performance Changes
Footnotes
|
…as and distinct Set-Cookie values
|
Cheers for the advice, @dom96! I tried to make the changes you asked me to. I have tried a few things, but I am raising the white flag 🏳️. I would need a full tutorial on how this project is managed to understand how to know whether my tests are correct or not. I will leave it to you to sort out the PR. You can add commits straight to this PR if you want to keep my original contribution, I would be please. I'd be interested to know what I've done wrong to get this kind of CodSpeed Performance Report. And how to read it properly. |
This is just spam for what it's worth. |
|
You were very close, the surprise I think was that the test was running with an old compat date and so getSetCookie wasn't defined. Thanks for reporting this and helping out with the fix! Here is the PR I just created: #5915. |
Hello maintainers 👋
The current implementation of the
headersproperty incorrectly splits header values on commas. Many standard HTTP headers legitimately contain commas inside their values (e.g.,Accept,Accept-Language,User-Agent). Splitting these values destroys their ordering, semantics, and meaning, resulting in invalid or incomplete headers being exposed to Python.Additionally, because
HTTPMessage[key] = valueoverwrites previous entries for the same header name, the split logic also caused the last fragment to override all earlier fragments.Before the fix, a request with:
was exposed as:
Similarly, a User-Agent such as:
was incorrectly truncated because commas inside parentheses were interpreted as separators.
I don't know if it was the intended way of doing it, but it solved my problem.