Skip to content

Commit 72360fd

Browse files
jcjonesjsha
authored andcommitted
Tighten CSP (#69)
Move Google Analytics to its own file and load it per guidance: https://developers.google.com/analytics/devguides/collection/analyticsjs/#alternative_async_tracking_snippet This in combination with PR #61 permits the following, much tighter CSP policy: > Content-Security-Policy "default-src 'self'; style-src 'unsafe-inline' 'self'; script-src 'unsafe-eval' 'self' https://www.google-analytics.com; img-src 'self' data: https://www.google-analytics.com;" This can land whenever, but the CSP policy shouldn't be updated until #61 lands. Additionally, the CSP policy should be updated with care and tested as well as possible before being left alone.
1 parent 317e96a commit 72360fd

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

_includes/footer.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ <h2>Support Us</h2>
6666
</div>
6767

6868
<script src="/js/main.js"></script>
69+
<script src="/js/ga.js"></script>
70+
<script async src='https://www.google-analytics.com/analytics.js'></script>
6971
</footer>

_includes/head.html

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,4 @@
2727
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
2828

2929
<link rel="alternate" href="https://letsencrypt.org/feed.xml" type="application/rss+xml" title="Let's Encrypt Blog Feed" />
30-
31-
<script>
32-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
33-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
34-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
35-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
36-
37-
ga('create', 'UA-56433935-1', 'auto');
38-
ga('send', 'pageview');
39-
</script>
4030
</head>

js/ga.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Google Analytics startup, per:
2+
// https://developers.google.com/analytics/devguides/collection/analyticsjs/#alternative_async_tracking_snippet
3+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
4+
ga('create', 'UA-56433935-1', 'auto');
5+
ga('send', 'pageview');

0 commit comments

Comments
 (0)