-
Notifications
You must be signed in to change notification settings - Fork 507
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
base: main
Are you sure you want to change the base?
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? |
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.