views:

307

answers:

3

My sites run off a subdomain (yyy.xxx.com), but I'm required to include CSS files from the main domain (xxx.com). We run a CMS that doesn't let me do any server-side stuff during the preview stage, so I'm stuck sending a page over https that includes a CSS import to http. All my IE users get a mixed content warning because of this.

Is there any client side way for me to prevent this, other than maintaining separate security settings for the domain on every client machine?

+3  A: 

As far as I know, there's no way to avoid that warning. It's there particularly for this purpose: alert you to the fact that even though you believe your page is SSL-encrypted, some of its content isn't. You'll either need to serve the original page over HTTP (not recommended), or serve the CSS file over HTTPS.

Traveling Tech Guy
We do that (serve the CSS file over HTTPS.) Just change your cert to a wildcard to allow for all subdomains.
seanmonstar
Though that would solve the problem, serving CSS and Javascript over HTTPS would slow their download time, since HTTPS is a slower process. It's especially hard for pages that utilize frameworks that contain many small files.
Dan Bowling
I would argue that the slowness of HTTPS compared to HTTP is almost negligible for samll files. Also, the browser will cache the js and css files, so you only suffer the penalty the first time.
Traveling Tech Guy
I think that the slowness becomes more apparent when you use a framework (such as Dojo), when each of those files get a HTTPS request. The delay becomes multiplied. Though the browser caching issue should take care of much of it.
Dan Bowling
+1  A: 

When you say that you cannot do "server-side" stuff, do you mean that you cannot touch your CMS, or that you do not have root access to your HTTP server?

Because if you do have access to your HTTP server, you could set up a very simple reverse proxy (with mod_proxy if you are using Apache). This would allow you to use relative paths in your HTML, while the HTTP server would be acting as a proxy to any "remote" location. In fact this technique can also be used to mitigate some cross-site scripting issues.

The fundamental configuration directive to set up a reverse proxy in mod_proxy is the ProxyPass. You would typically use it as follows:

ProxyPass     /css/     http://xxx.com/css_dir/

In this case, the browser would be requesting https://yyy.xxx.com/css/main.css but the server would serve this by acting as a proxy to http://xxx.com/css_dir/main.css. It will not raise the browser warning, and works fine with SSL.

Daniel Vassallo
This is a good idea, but the CMS is a closed box as far as I am concerned, so I cannot do any rewriting.
Dan Bowling
+2  A: 

Make use of protocol-relative URL's in the CSS links.

Thus so

<link rel="stylesheet" type="text/css" href="//example.com/style.css">

instead of

<link rel="stylesheet" type="text/css" href="http://example.com/style.css"&gt;

It will automatically pick the protocol of the parent request, which should work fine for HTTPS as well.

BalusC
Wow. I've never heard of this before!
Dan Bowling
Thanks BalusC. I just tested out the method this afternoon, and it solved the issue! Is there any reason not to always do this?
Dan Bowling
Yes, when you stick to only one protocol :)
BalusC