Direct Sockets: Proposal for a future web platform API
github.com
github.com
If there's an API for "desktop application" web pages which can make arbitrary connections, what does the security model look like?
(And whether it's a severe vulnerability depends on what the web server provides. In many cases, this has been "RCE on your machine".)
Here's an example from 2018: https://bugs.chromium.org/p/project-zero/issues/detail?id=14...
Why?
The server can't be handing out arbitrary permissions, for two major reasons. One is that you just can't be putting up servers that are handing out permissions for other networks for a host of obvious reasons. The second is that while the Internet is sufficiently connected that we are often able to just pretend it's one big happy IP namespace, that's not true. The addresses reserved for local networks create one obvious exception (there's a ton of 192.168.1.1s in the world), but just in general what the server thinks another resource's identifier is may not be the identifier from the client's point of view. A lot of hacking opportunity in exploiting the gap between a server's concept of network identity and the client's.
DNS isn't enough, because I can set up a DNS subdomain to point at any IP I want. I'd need to pre-flight check the request to ensure a cert establishes at least some minimal level of ownership over the domain, and there's no protocol-generic way to check, so we have to reuse HTTPS.
Now, by the time this is all set up, you probably might as well just have set up a websocket proxy. You're certainly not using this to build a glorious P2P application or anything. (If you could convince your users to install a new root SSL cert, I can see making this work with some other grease, but without that I think you're stuck being the MitM router for all traffic, which is hardly P2P.)
There is also the YOLO option of just letting browsers open unrestricted sockets and letting the internet pick up the pieces. Which it eventually would. But would probably result in an even more restrictive set up than we have now.
> Attackers may use the API to by-pass third parties' CORS policies.
> Mitigation
> We could forbid the API from being used for TCP with the well known HTTPS port, whenever the destination host supports CORS.
I'm really curious about the implicit ethics here.
There's this idea that the web should be able to do everything that native apps can, an idea that I'm inclined to agree with. One thing that native apps can of course do is to bypass third parties' CORS policies. And there are may legitimate use cases for that, like feed readers for example. Right now, if you want a feed readers as a web app, you need a backend, to be able to request feeds (and homepages, for autodiscovery). For a native app, you could do that all client side.
I can understand that TCP connections could be abused by some websites (e.g. using your browser for spamming, accessing unsecured local services, etc.) but this can be solved with a permission style popup just like with the geolocation or webcam APIs.
In general though it’d be really nifty to have this functionality. Chromium already runs most apps it’s just right now they all ship their own Chromium.
Since this is meant for high trust anyway, perhaps just shipping the more familiar Node APIs for tcp/udp would be better? That would let people do cool things (including p2p) that actually works, and it’s pretty battletested. Or maybe I’m missing something? It was a while ago I used that.
Another thought: don’t we have too many streaming protocols already? Do we really need SSE, WebSocket, WebTransport and now raw sockets as well? It’s a lot, (but not this project's fault)
This certainly looks simpler than WebRTC, which is absolutely impenetrable.
I created https://webrtcforthecurious.com to try and solve the accessibility/education issues around WebRTC
Thanks for writing the book.
> https://webrtcforthecurious.com/docs/02-signaling/
The moment I open this page, which is ostensibly the first on the way to understanding WebRTC, it slaps me over the head with hundreds of terms I’ve never heard before. More importantly, I don’t understand why I should care about them.
I just want to do Server.serve(5648), and Client.connect(server, 5648) and then pass binary messages back and forth. This is the mental model I already have, and works fine when I’m anywhere other than a browser, and even for websockets (mostly, except no UDP) and whatever website explains WebRTC will first have to explain to me why such a simple thing cannot work.
With BitTorrent plenty of clients can't accept connections but that does not render them unusable.
CloudFlare/Deno etc. all have these workarounds around tunnelling but all that would disappear with this protocol. I made a service for writing servers on the web (https://webcode.run -- somewhat abandoned at this point but it is still running), and a big problem with the approach was the web's inability to make TCP connections.
The bridge just pushes the can down the road and you have to secure it. It assumes the internal network is safer which is kind of a security sham to begin with.
In the long run it would make the individual service software more robust because security vulnerabilities would get attention and get fixed. Therefore benefitting more than just the bridge owner.
That means that your web app could act like "psql" and open a direct TCP socket connection to "postgresql://user:pass@host:5432/db", which would change everything
You'd no longer need a backend just to middleman SQL requests, assuming you have proper RLS implemented.
(Whether or not this is a good idea/applicable to all cases is debatable, but it at least becomes possible if I'm reading right)
Wouldn't they be accessible to anyone reading the front end source files or plugins installed in the browser context?
You could just pass a single auth token to the database if it supported it for public data only and fetch it that way. Kinda like a bearer token, etc...
Therefore having direct access to the database from the client side only for public data.
This would be very beneficial to the web as a whole as a lot of the data is public data.
Then the separation of privilege/access has to happen directly at the database level which is totally possible.
Would be a nice addition to the web to treat public data differently.
data_access: private|public data_scope: single|composite data_exempt: age|gender|otherpiifield
Somewhat protecting PII by not allowing querries which would infringe PII rules when selecting multiple sensitive fields.
However that db backend is still listening for logins, it does not know who the client is.
What happens today imho is that you have access to pieces of the data tables not the whole database at once to run queries at will.
When you fill out an html form or click a button that runs business logic code which might run sql queries based on a token/id you passed.
That token/id does not have access to the whole database.
Temporary database wide sessions are still a risk in the browser context.
Connecting browsers directly to databases is generally a bad idea for other reasons.
I want to be able to write extensions that can do whatever the hell I want. It's my computer and it's my Browser. If necessary, I would enable it in the about:config. But there should be an option to allow me to do that.
https://github.com/mozilla/libdweb/issues/109#issuecomment-5...
Additionally things like form elements being able to POST to any address still is something everyone else needs to be aware of and protect against.
There will be new ways to DDoS but as it's already possible fill bandwidth on any TCP port, I don't think that it'll be drastic.
IMO main reason behind CORS is to send request with cookies to another domain. If you can send arbitrary queries from JS but you still not have access to cookies for that domain, it's not really adds obvious attack lines. Yes, you'll be able to issue arbitrary GET requests and read responses, but I never understood why is it a problem in the first place.
You can trivially find information on why all the security features that fall under the same-origin policy exist and what kind of vulnerabilities they prevent. I will not be repeating all that here. Most of these protections were added because actual exploits were demonstrated or found in the wild. They weren't added willy-nilly.
I'll just leave you with some reasons for not even allowing reading response of cookie-free cross-origin GET requests: You don't want websites to turn their users into web-scrapers or even use them to brute-force logins on another site that happens to use GET for some API endpoint. Maybe they'll even try some IP-addresses that often lie in personal or company intranet. Is the HTTP control page of your cheap printer not password protected? One GET request later the attacker's website is downloading your recent print jobs.
You're likely not the only to whom these are not obvious, because some of the attacks possible really aren't obvious. Be glad browser vendors are watching out too.
There's also an explanation at https://discourse.wicg.io/t/filling-the-remaining-gap-betwee....