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

any website can grab the server connection from browser dialer on localhost #3236

Closed
mmmray opened this issue Apr 5, 2024 · 7 comments · Fixed by #3295
Closed

any website can grab the server connection from browser dialer on localhost #3236

mmmray opened this issue Apr 5, 2024 · 7 comments · Fixed by #3295

Comments

@mmmray
Copy link
Collaborator

mmmray commented Apr 5, 2024

When running xray's browser dialer on localhost:3000, any website can connect to ws://localhost:3000, wait for a dialing attempt, and learn about the used proxy that way.

Steps to reproduce:

  1. Create some kind of websocket xray config (ws+vless, ws+vmess, does not matter), and launch it like so: XRAY_BROWSER_DIALER=127.0.0.1:3000 ./xray
  2. the port 3000 can be changed to something else as well
  3. have something connect to the xray instance and initiate connections to the internet -- it does not matter if they are successful or whether an actual dialer browser is running
  4. open http://mmmray.github.io/dialer-detector in a browser -- browser may use a proxy, but must not route localhost connections through it
  5. the website initiates a full port scan, and will print the xray server's hostname when successful

The idea is that a domestic website could use this to detect whether somebody is connecting through xray, and through which server, then ban that server. It does not matter if the website itself has been accessed through xray, so the geosite:cn best-practice does nothing.

Some notes:

  • I am reporting this publicly because I think this is at most a minor security issue with no people impacted, and because it is not actively exploited and only theoretical. I could not find a security contact.
  • The port scanner is very slow and naive. It can be optimized easily, for example it could attempt common ports like 3000 first.

Any one of these changes to xray could fix the issue:

  • Xray could reject the websocket connection if Origin is wrong, and ideally log a warning
  • some kind of CSRF token in the browser dialer which is passed from xray to the browser via HTML, and passed from the browser to xray when opening the websocket connection.
  • dialer is not hosted on / but some secret, user-defined subpath

Users who use the browser dialer (are there any?) can defend against this today without code changes by:

  • Turn off websockets entirely in their browser, and use a separate browser instance as dialer
  • Run xray's browser dialer on a different IP address than 127.0.0.1, or for example in a docker container. Then the attacker website would have to scan many IPs...
@Fangliding
Copy link
Member

In fact, malicious JavaScript can obtain much more information than this, so I don't think that's a big problem (

@mmmray
Copy link
Collaborator Author

mmmray commented Apr 11, 2024 via email

@Fangliding
Copy link
Member

can you elaborate? I don't think this is true, or shouldn't be.

-------- Original Message --------
On 11 Apr 2024, 11:13, 风扇滑翔翼 wrote: Closed #3236 as completed. — Reply to this email directly, [view it on GitHub](#3236 (comment)), or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

Browser exposure of local web services is indeed a security issue
I recommend reporting this question to Google and Mozilla

@mmmray
Copy link
Collaborator Author

mmmray commented Apr 11, 2024 via email

@Fangliding Fangliding reopened this Apr 11, 2024
@dyhkwong
Copy link
Contributor

Isn't it expected behavior for popular browsers? There are so many legit use cases. If you do care about this, just add https://github.com/uBlockOrigin/uAssets/blob/master/filters/lan-block.txt to your ad-blocker. Also https://wicg.github.io/private-network-access/ is currently only a draft. Adding some authentication functions are enough.

@mmmray
Copy link
Collaborator Author

mmmray commented Apr 21, 2024 via email

@mmmray
Copy link
Collaborator Author

mmmray commented Apr 21, 2024

I'm arguing too much, here's a possible fix for the issue: #3295

RPRX added a commit that referenced this issue Apr 26, 2024
Fixes #3236

---------

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants