Skip to content

Conversation

@Seinzu
Copy link

@Seinzu Seinzu commented May 13, 2025

The kind of change this PR does introduce

  • a new feature

Current behaviour

Currently when an empty origin is passed and no referer header is provided then the request is automatically declined.

New behaviour

In the situation described above and a function has been provided in the configuration (as origins) then the normalised origin will be passed through to the provided function and a decision can be made in the function. Behaviour remains the same in the case that a string is provided.

Other information (e.g. related issues)

Browsers can choose to not send a referer header so it is possible that in a same-origin request we will get neither.

While websockets generally do not follow the same-origin rules, socket.io has an HTTP request to get an upgrade to wss that will fall under the same-origin rules.

@Seinzu Seinzu requested a review from timdown May 13, 2025 08:18
Copy link

@timdown timdown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and works in my testing. We'll also need a change in the real-time origin check because otherwise we'll get an error in URL.parse(origin).origin when origin is undefined. The simplest thing might be an explicit check and an early return, right at the start:

if (!origin) {
  // There is no Origin or Referer header. We're going to pass this anyway
  // for now but log it
  logger.warn({ req }, 'No Origin or Referer header')
  return true
}

lib/manager.js Outdated
~origins.indexOf('*:' + parts.port);
}
else {
this.log.warn('origin missing from handshake, yet required by config');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"handshake" is not always accurate because the websocket implementations use "websocket call" instead, but that's a minor issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change the original message (was line 904) which I had assumed was in the library already but maybe you added it?

Copy link

@timdown timdown May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the websocket ones that I was thinking of. They had the same origin check with a slightly different message, and I changed their origin check to use the one in Manager but kept the message (example).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've switched which message I considered redundant so that the one in the manager function is now removed and the others have been reinstated. Is that what you wanted?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to point out that the websocket message had changed, but I was happy to go with it. I do prefer the new version though 😄

package.json Outdated
{
"name": "socket.io"
, "version": "0.9.19-overleaf-11"
, "version": "0.9.20-overleaf-12"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming convention for our releases is 0.9.19-overleaf-x (i.e. the 19 doesn't get incremented).

@Seinzu
Copy link
Author

Seinzu commented May 13, 2025

Here's my version of the real-time code :)

Screenshot 2025-05-13 at 10 54 55

Pretty similar (the debug log was just for local testing and I don't think the header check is really necessary - it can be assumed).

@Seinzu Seinzu force-pushed the ar-allow-origin-function-to-consider-empty-origin branch from 6c0e041 to 0a9962f Compare May 13, 2025 10:05
@timdown
Copy link

timdown commented May 13, 2025

Here's my version of the real-time code :)
Screenshot 2025-05-13 at 10 54 55

Pretty similar (the debug log was just for local testing and I don't think the header check is really necessary - it can be assumed).

Great. Sorry to suggest code, which I know can be annoying. I just had some code that I added after getting an error while testing.

@Seinzu Seinzu force-pushed the ar-allow-origin-function-to-consider-empty-origin branch from 0a9962f to b059656 Compare May 13, 2025 10:14
@Seinzu
Copy link
Author

Seinzu commented May 13, 2025

Sorry to suggest code, which I know can be annoying.

No worries! I just thought it was funny that they were pretty similar.

@Seinzu Seinzu merged commit 7814a16 into 0.9.x May 16, 2025
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

Successfully merging this pull request may close these issues.

3 participants