-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
Issue with cyrillic symbols in location headers #1693
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I'm not sure if this is a bug, but it is always better to encode url manually: var http = require('http');
http.createServer(function(req, res) {
if (req.url === '/')
res.writeHead(302, {location:'?text=' + encodeURI('что-то русское')});
res.end();
}).listen(7777); |
As general advise, you're better off sticking to ASCII in HTTP headers. From RFC 7230:
Neither MIME (RFC 2047) nor ISO-8859-1 are widely supported. ASCII is the safest bet. |
Something like this happens: |
I understand that it would be reasonable to encode cyrillic or go without using these symbols, but we are creating a proxy server, whereas even quite well-known sites are sending headers with cyrillic. |
Do you have an example of a such website? It might be useful to mention a real-life example in the respective test should that be written. |
Adding |
@rlidwka |
Another workaround: var http = require('http');
http.createServer(function(req, res) {
if (req.url === '/') {
res.statusCode = 302;
res.setHeader('location', '?text=что-то русское');
res.flushHeaders();
}
res.end();
}).listen(7777); |
@vkurchatkin Does that mean that |
@LavrovArtem Yandex.Market gives properly encoded url in the |
Guess this link goes here: nodejs/node-v0.x-archive#25293 |
@ChALkeR I used Fiddler2 to view requests. Also, when I debug our proxy-server, I see the response coming from the original site with unencoded location header. |
@vkurchatkin thank you for workarounds |
Good to have those workarounds but this definitely feels like something that should be fixed. Granted, best practice would be to escape prior to setting but |
There is a similar problem with parsing: var http = require('http');
http.createServer(function(req, res) {
console.log(req.url);
console.log(req.headers)
res.end('');
}).listen(3000);
On node 0.10:
On io.js 3.2:
This is a seems like a major regression and I can't think of a proper workaround. |
@bnoordhuis Quick note. ISO-8859-1 is what's returned by var http = require('http');
http.createServer(function(req, res) {
console.log(req.headers);
res.end('bye\n');
}).listen(3000, makeRequest);
var options = {
port: 3000,
headers: { 'X-Test': 'Ä' },
};
function makeRequest() {
http.request(options, function (res) { }).end();
} Output:
|
Closing as per #2629 (comment). This is working as intended. The spec only allows ascii for security reasons. :S |
@Fishrock123 What about #1693 (comment) then? |
Hmm, I suppose that is an actual bug, but from my knowledge of internals quite difficult to reasonably (performantly) fix. The entire http headers API (internals) needs a rewrite/cleanup. |
Discrepancies I'm aware of:
The entire thing needs to be looked at. |
Related: #962 |
Just encountered a problem with this. Wanted to apply some headers containing non-ascii characters, to a response that is sitting behind IIS (which is proxying requests). IIS threw a fit over the header values, eventually leading me to use the module |
|
Just to be clear... RFC 7230 and it's additional docs replace RFC 2616: https://tools.ietf.org/html/rfc7230#section-3.2 The specific ABNF for Header field values is:
Also note the comment in Section 3.2.4:
Also, from Appendix A.2:
For backwards compatibility, header fields are generally always supposed to be treated as ISO-8859-1 but anything outside of the In other words, a header value must contain only bytes in the x20-xFF range, and should ONLY decode bytes x20-x7E while leaving bytes x80-xFF as "raw bytes". This range, of course, does happen to allow for valid UTF8 byte sequences. Interpretation of those, however, is considered "unspecified". |
The original testcase should be fixed in recent versions on all supported Node.js branches, it just throws errors now, as it should. Any reason for keeping this open? |
I'm going to close this. The behaviour is consistent now. #1693 (comment) is also fixed. |
To reproduce this bug, execute the code below and open http://localhost:777/ in the browser. This page redirects to a page from the location header, and browser should open http://localhost:777/?text=что-то%20русское .
In node.js version 0.10.15 and earlier, it works fine, but io.js opens the http://localhost:777/?text=GB>-B>%20@CAA:>5 url.
I think that the issue is linked to the writeHead function that incorrectly encodes headers and sends them to the browser.
The text was updated successfully, but these errors were encountered: