5 ms·
Why do browsers let websites send AJAX requests to localhost anyway? I feel like that's bound to cause trouble.
by TazeTSchnitzel 11y ago
Why do browsers let websites send AJAX requests to localhost anyway? I feel like that's bound to cause trouble.
- gradys 11y agoSeems useful for any kind of local web development for one, plus there are lots of consumer applications that run locally as a web app, like Plex, for instance.
- TazeTSchnitzel 11y agoSure, for local web dev and apps. But why can websites on the Internet make requests to localhost?
- Tossrock 11y agoIt's pretty standard when you're developing a web application. Your backend runs on your machine, your frontend requests stuff from within the browser.
- TazeTSchnitzel 11y agoSure, but why can external sites access localhost?
- Tyr42 11y agoThey external sites don't access it, they just ask the browser to load an image. So the external site can't read the result, but that's not actually stopping them from owning your machine.
- deleted 11y ago[deleted]
- deathanatos 11y agoArbitrary requests to localhost aren't permitted, unless the page itself is on localhost. (Just as evil.com can't make arbitrary requests to google.com.) That said, there's a bunch of exceptions. They don't really matter here: the bug reported showed than an exploit was possible with a GET request, and you don't need AJAX to make a GET request. A <script> or an <img> tag is, under the hood, a GET request. Taking the second case (making a GET request through an <img> tag), the response likely won't be an image, so it won't display, but we don't know that until long after the request has executed, so it's too late. You'd have to restrict where images can come from (people wouldn't be able to use CDNs?), where scripts come from (a lot of sites load jQuery from Google), you couldn't allow JS redirects. You'd have to forbid JS from automatically submitting <forms>. CSS on odd domains. Webfonts. Videos, audio. I'm sure there are things I'm missing. Back on the AJAX side of things, JS can make GET requests through AJAX. The server has to send back a special header for the script to get the response, but if it doesn't, the request is still executed. (The idea being that, since you can execute GET requests using any of the aforementioned methods, allowing JS to do it isn't going to allow anything new. GET also isn't supposed to have side effects like this buggy endpoint has … GET was an extremely poor choice here.) More arbitrary requests are permitted, but only under the condition explicitly allows them with what is called a preflight request. (Note that GET isn't the only exception to preflighting, see [1].) [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_con...
- TazeTSchnitzel 11y agoYeah, I forgot about the exceptions to the Same Origin Policy for a moment there. Still, I don't see why sites should ever be able to make any request to localhost.
- landryraccoon 11y agoIt shouldn't cause a problem unless malicious software is already installed on the user's machine.