You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Whitespace is allowed within Header names, should be an Invalid header #1362
When receiving a malformed Set-Cookie header containing a CRLF, the \r\n character is incorrectly included in the header value, causing requests to include it in the generated Cookie header.
Expected Result
Per RFC https://tools.ietf.org/html/rfc7230#section-3.2.4, "A user agent that receives an obs-fold in a response message that is not within a message/http container MUST replace each received obs-fold with one or more SP octets prior to interpreting the field value."
Or, just raise an error on the invalid HTTP header.
Actual Result
An invalid Set-Cookie value was returned containing a CRLF character.
That's a good callout @njsmith, it looks like this may be fixed, but urllib3 hasn't cut a release in almost a year. I don't have time to move the original repro to urllib3 tonight but can take a look tomorrow.
Went ahead and tested. I can't get this to work in Requests with the current urllib3 master, but that wasn't making sense. I made a urllib3-only repro and it appears to be fixed for the newline case. I'll dig into it on the Requests end and see if we're botching something.
urllib3 doesn't however handle the other case I posed in the first test of whitespace between a header name and the colon.
Same section of the RFC:
No whitespace is allowed between the header field-name and colon. In
the past, differences in the handling of such whitespace have led to
security vulnerabilities in request routing and response handling.
So that should probably still be handled, but I'm not sure if you want to track that here or not.
changed the title [-]Malformed `Set-Cookie` header containing CRLF is ignored[/-][+]Whitespace is allowed within Header names, should be an Invalid header[/+]on Apr 18, 2018
For the record since it came up in gitter: h11 does remove the \r\n when folding the lines in the original case, and does reject headers with stray whitespace before the colon. (It also refuses to send outgoing headers with \r or \n in them, but unfortunately does not currently validate the location field to prevent sending paths containing \r or \n. That has a bug here: python-hyper/h11#50)
@njsmith, just to clarify, does h11 only reject sending headers with white space between the name and colon or receiving as well? I’m not sure if we want to hard-fail on receipt but rather handle it by stripping it as per the proxy specification.
Making content unreachable from the library is likely going to create a negative user experience given how many bad servers are out there.
h11 errors out if it gets whitespace before the colon. If this ends up causing interop problems we can revisit it (and we should expect that we will have to handle some interop problems during the h11 rollout and budget for it, because no one actually knows how http works). But I would strongly prefer to wait until we see this in the wild, because as the spec notes, being too accepting here has led to security bugs. (For example: some kind of firewall is checking for EvilHeader:, but it doesn't check for EvilHeader :, so it allows the latter through. Then urllib3 silently converts that back to EvilHeader:. This is more of an issue for servers than clients, but I'd rather be conservative if we can.)
Hi maintainers, I reproduced this issue on the current main branch and confirmed that obs-folded response header values can still be exposed through HTTPHeaderDict.
I noticed there are already linked PRs working on this, including #5017 and #5020, so I do not want to duplicate ongoing work. I’m happy to help test/review the current approach or prepare a smaller alternative patch if maintainers prefer a different direction.
I have withdrawn #5013 to avoid duplicating or confusing the current work on this issue. #5017 appears to be the active PR linked to close the obs-fold response-header value scope, while #5013 covered a different whitespace-before-colon response-header-name path. Thanks, and I will defer to the ongoing maintainer review there.
Hi! I opened PR #5063 to address this (reject obs-fold / CRLF in response header values and add a regression test). Happy to adjust if you'd like different behavior/exception type. If this resolves the issue, please let me know how you'd like to handle the OpenCollective bounty.
It adds regression coverage for invalid outbound header names with whitespace and folded Set-Cookie response headers, plus the corresponding validation/normalization changes.
Activity
njsmith commentedon Apr 18, 2018
I'm surprised this wasn't fixed by #1318. Or was it, but requests is using an older version?
nateprewitt commentedon Apr 18, 2018
That's a good callout @njsmith, it looks like this may be fixed, but urllib3 hasn't cut a release in almost a year. I don't have time to move the original repro to urllib3 tonight but can take a look tomorrow.
sethmlarson commentedon Apr 18, 2018
Thanks all for the investigation! If someone can confirm this is already fixed I'll close this issue as duplicate. 🎉
nateprewitt commentedon Apr 18, 2018
Went ahead and tested. I can't get this to work in Requests with the current urllib3 master, but that wasn't making sense. I made a urllib3-only repro and it appears to be fixed for the newline case. I'll dig into it on the Requests end and see if we're botching something.
urllib3 doesn't however handle the other case I posed in the first test of whitespace between a header name and the colon.
Same section of the RFC:
So that should probably still be handled, but I'm not sure if you want to track that here or not.
sethmlarson commentedon Apr 18, 2018
We can track that here, thanks for the repro!
[-]Malformed `Set-Cookie` header containing CRLF is ignored[/-][+]Whitespace is allowed within Header names, should be an Invalid header[/+]njsmith commentedon Apr 18, 2018
For the record since it came up in gitter: h11 does remove the
\r\nwhen folding the lines in the original case, and does reject headers with stray whitespace before the colon. (It also refuses to send outgoing headers with\ror\nin them, but unfortunately does not currently validate the location field to prevent sending paths containing\ror\n. That has a bug here: python-hyper/h11#50)nateprewitt commentedon Apr 18, 2018
@njsmith, just to clarify, does h11 only reject sending headers with white space between the name and colon or receiving as well? I’m not sure if we want to hard-fail on receipt but rather handle it by stripping it as per the proxy specification.
Making content unreachable from the library is likely going to create a negative user experience given how many bad servers are out there.
njsmith commentedon Apr 18, 2018
h11 errors out if it gets whitespace before the colon. If this ends up causing interop problems we can revisit it (and we should expect that we will have to handle some interop problems during the h11 rollout and budget for it, because no one actually knows how http works). But I would strongly prefer to wait until we see this in the wild, because as the spec notes, being too accepting here has led to security bugs. (For example: some kind of firewall is checking for
EvilHeader:, but it doesn't check forEvilHeader :, so it allows the latter through. Then urllib3 silently converts that back toEvilHeader:. This is more of an issue for servers than clients, but I'd rather be conservative if we can.)10 remaining items
Add regression test for folded Set-Cookie headers
Add changelog entry for folded header fix
utadashang commentedon May 17, 2026
Hi maintainers, I reproduced this issue on the current main branch and confirmed that obs-folded response header values can still be exposed through
HTTPHeaderDict.I noticed there are already linked PRs working on this, including #5017 and #5020, so I do not want to duplicate ongoing work. I’m happy to help test/review the current approach or prepare a smaller alternative patch if maintainers prefer a different direction.
Thanks!
JoeyXi commentedon May 18, 2026
I have withdrawn #5013 to avoid duplicating or confusing the current work on this issue. #5017 appears to be the active PR linked to close the obs-fold response-header value scope, while #5013 covered a different whitespace-before-colon response-header-name path. Thanks, and I will defer to the ongoing maintainer review there.
aigrouphobinh commentedon May 19, 2026
Hi maintainers — I opened a PR that fixes this issue by rejecting invalid folded headers / CRLF in header values and adds regression tests.
PR: #5034
Fixes #1362
(Bounty $100 / OpenCollective)
liangtovi-debug commentedon May 19, 2026
Submitted fix in PR #5035 to sanitize folded response headers and add a regression test for folded Set-Cookie values.
liangtovi-debug commentedon May 19, 2026
/claim #1362
Implemented in PR #5035: #5035
Includes response-header obs-fold sanitization and regression coverage for folded Set-Cookie values.
Please associate this claim with the OpenCollective bounty if accepted.
minnhnh commentedon May 27, 2026
Hi! I opened PR #5063 to address this (reject obs-fold / CRLF in response header values and add a regression test). Happy to adjust if you'd like different behavior/exception type. If this resolves the issue, please let me know how you'd like to handle the OpenCollective bounty.
zhaog100 commentedon May 28, 2026
Claiming this bounty. Will implement the fix for whitespace in header names.
GitHub: zhaog100
Identity: 小米辣 🌶️
sethmlarson commentedon May 29, 2026
The pull request from @adityawrk seems the highest quality: #5020 I've closed all others.
darlina-bounty-codex commentedon May 29, 2026
I opened a PR for this issue here:
#5068
It adds regression coverage for invalid outbound header names with whitespace and folded
Set-Cookieresponse headers, plus the corresponding validation/normalization changes.adityawrk commentedon Jun 18, 2026
Thanks @sethmlarson. Please me know if you need anything else on the PR.
Merge 'build(deps): bump urllib3 from 2.7.0 to 2.8.0' from app/depend…