-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Can no longer parse header "X-Custom-Header-Bytes: …" despite browsers doing this fine #281
Comments
Quote from RFC 7230:
Thus only ASCII characters are allowed in header values. We were more permissive in the past, but it turns out that this could be used as an attack vector against intermediate proxies. IMO, this is won't fix, since it is implemented according to spec. Thanks for asking, though! |
More from the spec:
|
I think we should endeavor to be as permissive as browsers. I don't suggest parsing it as a sequence of Unicode characters, but we should at least be interoperable with the most common HTTP processing libraries on the planet. Otherwise, people can't write software (like jsdom) which has the same capabilities as browsers. |
At the very least, I need some sort of option. Is there a way to plug in browser-like header parsing to Node.js, without reimplementing all of |
It's also not clear to me that the section you quoted supports erroring. All it says is that you should process the byte sequence So I think the current behavior of erroring is wrong per spec, and the spec actually is fairly clear about what should happen here. I agree the |
@domenic idk, maybe @mscdex or @bnoordhuis has an opinion on this. I wonder if it should be fixed in browsers instead? It is really strange that browsers implement behavior that is strictly prohibited by HTTP spec. |
@domenic yeah, I agree, superset quote was kind of off-topic. Anyway, |
(EDIT: upon further reading of the error handling section of the RFC, this post is mostly incorrect.) Mid-air comment collision, but to reiterate my main point:
The HTTP spec is pretty clear that clients are required to implement this behavior. http-parser's current behavior is not spec-compliant, and in fact violates the MUST in
No, the HTTP RFC specifically disallows this kind of behavior. A server must only emit valid |
@domenic one more question, could you please quote the part of spec that says:
I didn't really see anything like this there, but maybe I am missing something. |
In https://tools.ietf.org/html/rfc7230#section-2.5,
In contrast, the only applicability of ABNF to the receiver is
(i.e. you MUST be able to parse valid header values, but nothing is said about invalid header values.) Later:
So I agree that it is within Node.js's rights to reject invalid values. (My above post is wrong; I've edited it with a disclaimer at the top.) But I'd really appreciate some ability to be able to do browser-like header parsing in Node.js, so that I can interface with real-world web servers that work in all browsers today. |
Untested but perhaps https://github.com/creationix/http-parser-js works for you? It's more lenient than node's parser. |
@bnoordhuis that seems like it would be an option, if there were a way to scope it to a particular HTTP request instead of monkeypatching private APIs. Is that something Node.js could consider allowing, in order to provide a mitigation for those of us affected by this regression? |
Even better of course would be a targeted fix that allows per-HTTP-request changes to the header validation policy, since then I wouldn't have to parse the entire request. |
I think an undocumented
That's not so easy without a major http_parser bump. I'm also a little worried about performance regressions; |
Could be fixed in #283? |
This is due to a regression in Node's HTTP parser that makes it less capable than browsers: nodejs/http-parser#281. Closes #1380. We probably won't be able to fix this until Node either fixes the regression or makes HTTP header parsing customizable.
This is due to a regression in Node's HTTP parser that makes it less capable than browsers: nodejs/http-parser#281. Closes #1380. We probably won't be able to fix this until Node either fixes the regression or makes HTTP header parsing customizable.
This is due to a regression in Node's HTTP parser that makes it less capable than browsers: nodejs/http-parser#281. Closes #1380. We probably won't be able to fix this until Node either fixes the regression or makes HTTP header parsing customizable.
This is due to a regression in Node's HTTP parser that makes it less capable than browsers: nodejs/http-parser#281. Closes #1380. We probably won't be able to fix this until Node either fixes the regression or makes HTTP header parsing customizable.
This is due to a regression in Node's HTTP parser that makes it less capable than browsers: nodejs/http-parser#281. Closes jsdom#1380. We probably won't be able to fix this until Node either fixes the regression or makes HTTP header parsing customizable.
This is causing jsdom to fail several web-platform-tests where it is tested that its behavior emulates XMLHttpRequest (jsdom/jsdom#1380). I believe this is a regression as of Node.js 5.6.0.
The test is a combination of https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/resources/headers.py and https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/getresponseheader-special-characters.htm where it tests that the server setting
results in the client receiving
"\xE2\x80\xA6"
(i.e."�"
).We would like to be able to achieve this behavior in jsdom just like browsers are specified to do.
/cc @annevk for the standards-based perspective. I imagine it's something like "HTTP underspecifies interoperable behavior" but couldn't find anything in Fetch that specifically addresses the issue of what to do when headers are not valid according to HTTP's
field-content
production. Maybe the test is wrong?The text was updated successfully, but these errors were encountered: