Skip to content
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

origins not checked when url has sid #552

Open
1 of 2 tasks
barisusakli opened this issue Dec 30, 2017 · 1 comment
Open
1 of 2 tasks

origins not checked when url has sid #552

barisusakli opened this issue Dec 30, 2017 · 1 comment
Milestone

Comments

@barisusakli
Copy link

barisusakli commented Dec 30, 2017

You want to:

  • report a bug
  • request a feature

Current behaviour

When the url does not have the sid parameter the request is checked against the allowed origins here, after this subsequent requests are not checked against allowed origins.

Steps to reproduce

Set origins to mydomain.com
Make a request from evildomain.com spoof the origin header to match mydomain.com and get a valid sid.
Make request from evildomain with the valid sid and origin is no longer checked.

Expected behaviour

All requests to be checked against allowed origins

Other information (e.g. stacktraces, related issues, suggestions how to fix)

I changed the code to this and seems to work but wanted to get some feedback.

Server.prototype.verify = function (req, upgrade, fn) {
  // transport check
  var transport = req._query.transport;
  if (!~this.transports.indexOf(transport)) {
    debug('unknown transport "%s"', transport);
    return fn(Server.errors.UNKNOWN_TRANSPORT, false);
  }

  // 'Origin' header check
  var isOriginInvalid = checkInvalidHeaderChar(req.headers.origin);
  if (isOriginInvalid) {
    req.headers.origin = null;
    return fn(Server.errors.BAD_REQUEST, false);
  }

  // sid check
  var sid = req._query.sid;
  if (sid) {
    if (!this.clients.hasOwnProperty(sid)) {
      return fn(Server.errors.UNKNOWN_SID, false);
    }
    if (!upgrade && this.clients[sid].transport.name !== transport) {
      debug('bad request: unexpected transport without upgrade');
      return fn(Server.errors.BAD_REQUEST, false);
    }
  } else {
    // handshake is GET only
    if ('GET' !== req.method) return fn(Server.errors.BAD_HANDSHAKE_METHOD, false);
  }
  if (!this.allowRequest) return fn(null, true);
  return this.allowRequest(req, fn);
};

This calls allowRequest function for all requests instead of just the initial one.

@kevinhodges
Copy link

kevinhodges commented Jan 8, 2018

Seeing similar symptoms, be good to get a resolution!

@darrachequesne darrachequesne added this to the 7.0.0 milestone Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants