News for hackers. Stuff that matters.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tootie on Sunday September 02, 2018 @10:49AM (#17897169)
My number one solution to any and all CORS issues is to never ever set up an api.* domain. Always do /api on the same domain. If the requests are for third parties, put a proxy on your own hostname if at all possible.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by JoachimSchipper on Sunday September 02, 2018 @12:57PM (#17897615)
Putting a proxy on your own hostname solves the performance problem, but you need something that parses and re-sends requests, not just a general HTTP proxy - otherwise, the third party can e.g. serve malicious Javascript code to your users within your origin.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tootie on Sunday September 02, 2018 @05:20PM (#17898714)
I'm assuming this is a trusted endpoint. Either something you own or a vendor with a contract. If you're calling random endpoints from your pages, then that's another kettle of fish.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by JoachimSchipper on Monday September 03, 2018 @02:59PM (#17904288)
Yes, sorry for writing such a short message - I figured you were probably aware of these considerations, but I was pretty sure that not all your readers were. ;-)
Re:The Performance Cost of CORS Requests on Single-Page Appl... by yomly on Sunday September 02, 2018 @01:01PM (#17897635)
Are you able to elaborate further on what attack vector you're thinking of (if only so I can google it) - JSON hijacking maybe?

The implicit assumption being that internally everything trusts the proxy?

Re:The Performance Cost of CORS Requests on Single-Page Appl... by graystevens on Sunday September 02, 2018 @01:26PM (#17897751)
I believe they are referring to proxying requests to third parties, rather than the first part of the post which refers to proxying to your own backend.

Proxying requests to a third-party will mean browser security features like CORS will assume they are entirely safe due to them appearing to come from your domain, and not “gist.github.com” etc.

Re:The Performance Cost of CORS Requests on Single-Page Appl... by dasil003 on Sunday September 02, 2018 @01:05PM (#17897656)
I'm not following this. In the given example you would configure a proxy to route /api requests to your API cluster. How would an attacker inject a different backend origin?
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tptacek on Sunday September 02, 2018 @03:16PM (#17898161)
They wouldn't, but if you proxy arbitrary requests for UnicornGifs.sexy through your CatSharing.com backend, and UnicornGifs.sexy gets owned up (or even just mischievous), it can now generate malicious content in the same origin as CatSharing.com --- the browser can't differentiate which is which. And that forged CatSharing content will be valid in any page on CatSharing.com, not just the specific pages that include it.

The point is that when you serverside-proxy requests to third parties, you're implicitly trusting the third party to control the DOM for any app in your domain.

Re:The Performance Cost of CORS Requests on Single-Page Appl... by dasil003 on Sunday September 02, 2018 @04:23PM (#17898455)
Oh right, I missed the last sentence where OP suggested proxying to third parties.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by krallja on Sunday September 02, 2018 @04:45PM (#17898548)
How is that different from the unproxied scenario? If unicorngifs.sexy gets pwned, your users get pwned, whether or not there’s a proxy in the middle.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by wolf550e on Monday September 03, 2018 @09:23AM (#17902440)
If you load javascript from there - yes, but if you iframe to there - no. You can design a solution that uses cross-origin browser protection to protect your users from getting owned in case a partner is compromised.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by makmanalp on Sunday September 02, 2018 @11:29AM (#17897304)
I think this a good interim "solution", but it won't work for everyone. On a larger scale it's rife with issues: e.g. browsers often have a limit to how many downloads they'll do from a single domain in parallel, so stuffing API, assets and pages all into the same domain can limit performance. The other thing is that using DNS to load balance between servers is much more lightweight than using an HTTP proxy / load balancer to direct traffic.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by panarky on Sunday September 02, 2018 @11:48AM (#17897379)
HTTP/2 virtually eliminates the limit on concurrent requests. For example Firefox allows 100 concurrent requests by default with H2.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by londons_explore on Sunday September 02, 2018 @12:33PM (#17897533)
Nobody has an excuse not to use either HTTP/2 or QUIC on a modern website.

They should also use just one domain - DNS lookups are a pretty slow and flaky part of the process of loading a webpage, and downloading loads of HTTPS certificates for all the domains involved isn't great either.

Managing just one domain is also a lot easier - less to monitor, less to maintain, simpler architecture, etc.

The only remaining reason for extra domains is to act as a security boundary - for example when you're running untrusted user javascript.

Re:The Performance Cost of CORS Requests on Single-Page Appl... by chrismorgan on Sunday September 02, 2018 @01:00PM (#17897634)
Your statements are overly definite.

> Nobody has an excuse not to use either HTTP/2 or QUIC on a modern website.

Sure they do. HTTP/2 is not uniformly superior to HTTP/1.1, primarily due to head-of-line blocking; so that on a poor quality network connection, with multiple HTTP/1.1 connections it’s quite possible that one will come through while another takes longer due to packet loss, while on HTTP/2 it’s all on one TCP connection, so that packet loss affects all requests. That’s what QUIC is about fixing. HTTP/2 is also currently incompatible with WebSockets (there’s a draft in progress for resolving that), so HTTP/2 offers no benefit for WebSocket domains or little-to-no benefit for WebSocket-heavy stuff. HTTP/2 also works differently from HTTP/1.1, so that certain moderately obscure combinations of types of long-lived requests can’t be cleanly terminated in HTTP/2 as they can be in HTTP/1.1 (sorry I’m being vague—I can’t recall the details off-hand). And there’s just the usual “existing software that doesn’t support HTTP/2” justification as well.

(Despite the listed criticisms of HTTP/2, I do agree that almost everyone should be using HTTP/2.)

As for QUIC (Google or IETF variant), it’s still experimental, with various unknowns that are being nutted out, and is not suitable for wide deployment by most entities just yet.

> The only remaining reason for extra domains is to act as a security boundary

No, that’s merely one of the best justifications for additional domains. There are other reasons for using other domains, though I would agree with a less strongly worded version of your initial declaration: that they should try, if convenient, to use just one domain.

Re:The Performance Cost of CORS Requests on Single-Page Appl... by kevin_thibedeau on Sunday September 02, 2018 @01:34PM (#17897784)
This isn't a practical solution for embedded web servers where even six concurrent requests can be taxing.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by bdcravens on Sunday September 02, 2018 @12:38PM (#17897547)
Wouldn't it make sense to put the assets that don't need need API access on other domains?
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tootie on Sunday September 02, 2018 @05:04PM (#17898627)
Concurrent connections per domain is much less of an issue now. The max is high enough most apps will never hit it.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by gweinberg on Sunday September 02, 2018 @01:28PM (#17897760)
My third party requests are to a CDN. I think adding a proxy to my own domain completely defeats the point of using a CDN.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by izelnakri on Sunday September 02, 2018 @12:21PM (#17897489)
Yes, exactly. This is also very easy to implement since most webservers have a proxy like nginx. It is also very easy in Kubernetes via Ingress resource.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tachang on Sunday September 02, 2018 @02:44PM (#17898053)
What if you can’t because you want to use a hosted provider for your homepage like wix? Which doesn’t support reverse producing?
Re:The Performance Cost of CORS Requests on Single-Page Appl... by tootie on Sunday September 02, 2018 @04:55PM (#17898592)
The you have to deal with CORS. But any site that has real complex interactions to design around isn't going to be hosted on Wix.
Re:The Performance Cost of CORS Requests on Single-Page Appl... by jessaustin on Sunday September 02, 2018 @03:31PM (#17898213)
Why not have your frontend proxy running somewhere else, pointing both to Wix and to the evil ad network? Wix will still think it's the host, so it should be fine.