Skip to content

Commit d0c3821

Browse files
committed
a whole bunch of edits, instructions, and an image
1 parent 00e81ae commit d0c3821

2 files changed

Lines changed: 86 additions & 16 deletions

File tree

assets/images/mixed-content.png

7.13 KB
Loading

pages/mixed-content.md

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,104 @@ title: Mixed Content
44
permalink: /mixed-content/
55
---
66

7-
### What is mixed content?
7+
When an HTTPS website references insecure (HTTP) resources, this is called **[mixed content](http://www.w3.org/TR/mixed-content/)**.
88

9-
When you view a page in your browser, it is almost never just a single request. Almost every web page contains resources, such as Javascript, CSS, and images, which cause additional requests. Sometimes these requests are to the same servers as the rest of the site, other times they are external resources (such as Google Analytics snippets of JavaScript).
9+
Browsers prevent an HTTPS website from loading most insecure resources, like fonts, scripts, etc. Migrating an existing website from HTTP to HTTPS means identifying and fixing or replacing mixed content.
1010

11-
When the main page is loaded over `HTTPS` and these sub-resources are loaded over `HTTP` this is called **mixed content**.
11+
[Mixed content](http://www.w3.org/TR/mixed-content/) comes in two varieties:
1212

13-
Mixed content comes in two varieties:
13+
**Active** mixed content includes resources that can greatly change the behavior of a website, such as JavaScript, CSS, fonts, and iframes. Browsers refuse to load active mixed content, which often results in affected pages being completely unstyled or broken. Browsers treat these very aggressively because of the consequences if they were compromised. For example, a single compromised Javascript file compromises the entire website, regardless of how other resources are loaded.
1414

15-
**Active** mixed content includes resources that can greatly change the behavior of a website, such as JavaScript, CSS, fonts, and iframes. Browsers refuse to load active mixed content, which often results in affected pages being completely unstyled or broken. Browsers treat these very aggressively because of the consequences if they were compromised, for example a single compromised Javascript file compromises the entire website, regardless of how other resources are loaded.
15+
**Passive** mixed content includes resources whose impact on the page's overall behavior is more minimal, such as images, audio, and video. Browsers will load passive mixed content, but will typically change the HTTPS indicator.
1616

17-
**Passive** mixed content includes resources whose impact on the page's overall behavior is more minimal, such as images, audio, and video. Browsers will load passive mixed content, but will typically change the HTTPS indicator. For example, in Chrome this means that the "green lock" icon becomes a gray lock with a yellow triangle over it.
17+
In Chrome, a website indicator for passive mixed content looks like this:
1818

19-
### Why is mixed content a problem?
19+
![fedramp in chrome](/assets/images/mixed-content.png)
2020

21-
Mixed content is a problem because, were browsers to allow it, an attacker would be able to conduct a MITM attack against it the same way they could the main page. Even where browsers do allow it, as with images, attackers can manipulate what the page looks like, and so the yellow-lock icon is intended to communicate that security has been weakened and user confidence should be reduced. In addition, an attacker will be able to read any cookies for that domain which do have the `Secure` flag, and set cookies.
21+
### Migration strategy
2222

23-
When a website is `HTTP`-only, loading other `HTTP` sub-resources does not generate any sort of warning, and so websites operating over `HTTP` often accumulate many of these sub-resources.
23+
Every website's mixed content situation will be different, but the general approach is:
2424

25-
When an `HTTP` website tries to migrate to `HTTPS`, these can often become a source of difficulty.
25+
* Enable `https://` for your website, but don't force a redirect. Continue to present the `http://` version as the canonical URL to search engines.
26+
* Identify the most obvious and widespread pieces of mixed content by loading your website in a browser over `https://` and observing breakages. Chrome and Firefox will log any mixed content warnings to the console, which should point out necessary site-wide changes. Use these to [secure your resource links](#linking-to-resources-securely).
27+
* After fixing them, tackle the long tail by [scanning your code](#scanning-your-code), [crawling your website](#crawling-your-website), and potentially adding [automatic mixed content reporting](#automatic-mixed-content-reporting).
28+
* Finally, force the redirect to HTTPS, and tell search engines that your new URL starts with `https://`.
2629

27-
### Strategies for dealing with mixed content
30+
Note: the below instructions use tools **optimized for an OS X or Linux environment**. Documentation for Windows-based tools would be a welcome contribution to this guide.
2831

29-
The easiest approach is to use relative URLS (e.g. `<img src="https://github.com/media/my-picture.png" />`) for links which are on your domain. These will work with both `HTTP` and `HTTPS` websites. For external resources you can simply always use `https://`. Ocasionally you will find that some media you wish to hotlink is on a third-party which doesn't support HTTPS. This is a great opportunity to improve your website's privacy and to lessen your dependency on third parties by hosting that media on your own server instead (you can also encourage the host for that media to begin offering `https://` support on their website).
32+
### Linking to resources securely
3033

31-
In order to locate mixed content, the easiest way to start is to load your website in a browser over `https://` and see if it looks ok. Both Chrome and Firefox will log any mixed content to the console. This gives a quick way to get a sense of how large the problem is.
34+
Most commonly used third party services, such as Google Analytics or AddThis, **will automatically adapt** when migrating to HTTPS.
3235

33-
Another approach is to grep your codebase for any explicit `http://` URLs, since these will always cause a problem.
36+
Other services may require manual updates, but have an `https://` version ready:
3437

35-
### Tools
38+
```html
39+
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
40+
```
3641

37-
* [`mixed-content-scan`](https://github.com/bramus/mixed-content-scan) can crawl a website to see if it contains any references to insecure resources. It can work on either `HTTP` or `HTTPS` websites.
42+
Generally speaking, for content on your own domain, stick to site-relative URLs wherever possible:
43+
44+
```html
45+
<img src="/media/my-picture.png" />
46+
```
47+
48+
When migrating a site with a lot of user- or staff-submitted content (e.g. a blog), you may find media hotlinked from a third-party domain which doesn't support HTTPS.
49+
50+
This is a great opportunity to improve your website's privacy and lessen your dependency on third parties, by copying those media files to your own server instead and hosting them yourself.
51+
52+
### Scanning your code
53+
54+
After identifying and fixing the obvious issues, you can scan your website's files for leads. On a Mac or Linux-based system, `grep` is very handy:
55+
56+
Images and scripts:
57+
58+
grep -r "src=\"http:" *
59+
60+
Stylesheets and fonts:
61+
62+
grep -r "href=\"http:" * | grep "<link"
63+
64+
CSS imports and references:
65+
66+
grep -r "url(\"http:"
67+
68+
Finding links in JavaScript is more challenging, but you can look for all `http:` references and try to exclude hyperlinks in HTML or Markdown:
69+
70+
grep -r "http:" | grep -v "href=\"http:"
71+
grep -r "http:" | grep -v "](http:"
72+
73+
74+
### Crawling your website
75+
76+
[`mixed-content-scan`](https://github.com/bramus/mixed-content-scan) is a very handy command line tool that can crawl an `http://` or `https://` website to see if it contains any references to insecure resources. This is especially helpful if your content is primarily managed in a CMS.
77+
78+
`mixed-content-scan` requires PHP, then [installing Composer](https://getcomposer.org/doc/00-intro.md). [Install with Composer](https://github.com/bramus/mixed-content-scan#installation), then use it with your domain:
79+
80+
```bash
81+
mixed-content-scan https://https.cio.gov
82+
```
83+
84+
You should see something like this:
85+
86+
```
87+
[2015-03-15 16:56:48] MCS.NOTICE: Scanning https://https.cio.gov/ [] []
88+
[2015-03-15 16:56:49] MCS.INFO: 00000 - https://https.cio.gov/ [] []
89+
[2015-03-15 16:56:49] MCS.INFO: 00001 - https://https.cio.gov/faq/ [] []
90+
[2015-03-15 16:56:49] MCS.INFO: 00002 - https://https.cio.gov/hsts/ [] []
91+
[2015-03-15 16:56:49] MCS.INFO: 00003 - https://https.cio.gov/resources/ [] []
92+
[2015-03-15 16:56:49] MCS.NOTICE: Scanned 4 pages for Mixed Content [] []
93+
```
94+
95+
Any discovered mixed content will be listed as a `WARNING`. You can also get the results as newline-separated JSON objects:
96+
97+
```bash
98+
mixed-content-scan https://https.cio.gov --format=json
99+
```
100+
101+
### Why do browsers block mixed content?
102+
103+
If mixed content were not blocked, an attacker could control the main website by conducting a MITM attack against any of its active resources.
104+
105+
Even with passive content like images, attackers can manipulate what the page looks like, and so the yellow-lock icon is intended to communicate that security has been weakened and user confidence should be reduced. In addition, an attacker will be able to read any cookies for that domain which do have the `Secure` flag, and set cookies.
106+
107+
When a website is accessible over `http://`, loading other insecure resources does not generate any sort of warning, and so websites operating over plain HTTP often accumulate many of these sub-resources.

0 commit comments

Comments
 (0)