-
Notifications
You must be signed in to change notification settings - Fork 10.1k
CORS headers issue: origins filter still get ignored when emitting "Transport unknown" error #3415
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
Comments
The workaround is following monkey-patch: import engineio from 'engine.io';
const debug = require('debug')('engine');
const originalVerify = engineio.Server.prototype.verify;
engineio.Server.prototype.verify = function(req, upgrade, fn, ...rest) {
const transport = get(req, '_query.transport');
let error = false;
if (!transport) {
debug(`patched 'verify' method is invoked. req._query.transport is empty: emitting FORBIDDEN error`);
error = true;
} else if (this.transports.indexOf(transport) === -1) {
debug(`patched 'verify' method is invoked. req._query.transport=${transport} is unknown: emitting FORBIDDEN error`);
error = true;
}
if (error) {
// FORBIDDEN code will be eventually handled by Server::sendErrorMessage
// and response won't be populated with 'Access-Control-Allow-*' headers
return fn(engineio.Server.FORBIDDEN, false);
}
return originalVerify.call(this, req, upgrade, fn, ...rest);
}; |
This is extremely annoying, i am trying to debug the issue from past 16 Hours and still getting the same Cross Origin Issue.
The problem is pretty straight forward, it must not respond with a wild card entry in response, rather it should match with the request headers so that i may not get issues with it. Extremely annoying and pathetic problem, trying all my ups and downs to get it resolved but i couldn't. All the resources on Web are not solving the issue. |
Same issue is here. Will be fixed it? I think we should move the CORS part to the top of the function here in engine.io: function sendErrorMessage (req, res, code) {
var headers = { 'Content-Type': 'application/json' };
var isForbidden = !Server.errorMessages.hasOwnProperty(code);
if (isForbidden) {
res.writeHead(403, headers);
res.end(JSON.stringify({
code: Server.errors.FORBIDDEN,
message: code || Server.errorMessages[Server.errors.FORBIDDEN]
}));
return;
}
if (req.headers.origin) {
headers['Access-Control-Allow-Credentials'] = 'true';
headers['Access-Control-Allow-Origin'] = req.headers.origin;
} else {
headers['Access-Control-Allow-Origin'] = '*';
}
if (res !== undefined) {
res.writeHead(400, headers);
res.end(JSON.stringify({
code: code,
message: Server.errorMessages[code]
}));
}
} |
For future readers: the Documentation: |
Uh oh!
There was an error while loading. Please reload this page.
Found that CORS header Access-Control-Allow-Origin is still generated for any Origin ignoring origins filter.
This is related to already reported and closed issues #449, #331, #2850 and pr #452
Steps to reproduce (here is full commit with reproduction scenario in my app):
curl -GET -H "Origin: http://wertwertffff.com" --verbose http://localhost:8888/socket.io/
Expected behavior:
403 HTTP code and corresponding error is generated, no Access-Control-Allow-* headers are present in response.
Actual result:
Moreover, such behavior also causes security scanner (was tested with Burp Suite) to report websockets url as faulty.
The text was updated successfully, but these errors were encountered: