integrity protection for third-party javascript

103
<script src=”https://ajax.googl eapis.com/ajax/libs/jquery/1.8. 0/jquery.min.js” integrity=”typ e:text/javascript sha512-AODL7i dgffQeNsYdTzut09nz9AINcjhj4jHD7 2HcLirsidbC8tz+dof7gceOCQD8Wske uRFfJ9CsgZTHlMiOYg==”></script> Integrity protection for 3 rd -party JavaScript François Marier @fmarier mozilla

Upload: francois-marier

Post on 30-Jul-2015

49 views

Category:

Internet


0 download

Tags:

TRANSCRIPT

Page 1: Integrity protection for third-party JavaScript

<script src=”https://ajax.googl eapis.com/ajax/libs/jquery/1.8. 0/jquery.min.js” integrity=”typ e:text/javascript sha512-AODL7i dgffQeNsYdTzut09nz9AINcjhj4jHD7 2HcLirsidbC8tz+dof7gceOCQD8Wske uRFfJ9CsgZTHlMiOYg==”></script>

Integrity protection for3rd-party JavaScript

François Marier @fmarier mozilla

Page 2: Integrity protection for third-party JavaScript

FirefoxSecurity & Privacy

Page 3: Integrity protection for third-party JavaScript

Web Platform

Page 4: Integrity protection for third-party JavaScript

Web Platform

Page 5: Integrity protection for third-party JavaScript

Content Security Policyaka CSP

Page 6: Integrity protection for third-party JavaScript

Content Security Policyaka CSP

mechanism for preventing XSS

Page 7: Integrity protection for third-party JavaScript

telling the browser what externalcontent is allowed to load

Page 8: Integrity protection for third-party JavaScript

what does CSP look like?

Page 9: Integrity protection for third-party JavaScript

$ curl --head https://mega.nzHTTP/1.1 200 OKContent-Type: text/htmlContent-Length: 1989Content-Security-Policy:

default-src 'self' *.mega.co.nz *.mega.nzhttp://*.mega.co.nz http://*.mega.nz;

script-src 'self' mega.co.nz mega.nz data:blob:;

style-src 'self' 'unsafe-inline' *.mega.nz*.mega.co.nz data: blob:;

frame-src 'self' mega:;img-src 'self' *.mega.co.nz *.mega.nz data:

Page 10: Integrity protection for third-party JavaScript

Hi you<script>alert('p0wned');</script>!

Tweet!

What's on your mind?

Page 11: Integrity protection for third-party JavaScript

without CSP

Page 12: Integrity protection for third-party JavaScript

Hi you!John Doe - just moments ago

p0wnedOk

Page 13: Integrity protection for third-party JavaScript

with CSP

Page 14: Integrity protection for third-party JavaScript

Hi you!John Doe - just moments ago

Page 15: Integrity protection for third-party JavaScript

Content-Security-Policy:

script-src 'self'

https://cdn.example.com

Page 16: Integrity protection for third-party JavaScript

inline scripts are blocked unlessunsafe-inline is specified

Page 17: Integrity protection for third-party JavaScript

script-srcobject-srcstyle-srcimg-srcmedia-srcframe-srcfont-src

connect-src

Page 18: Integrity protection for third-party JavaScript

$ curl --head https://twitter.comHTTP/1.1 200 OKcontent-length: 58347content-security-policy: …report-uri https://twitter.com/csp_report

violation reports:

Page 19: Integrity protection for third-party JavaScript

"csp-report": { "document-uri":

"http://example.org/page.html", "referrer":

"http://evil.example.com/haxor.html", "blocked-uri":

"http://evil.example.com/image.png", "violated-directive": "default-src 'self'", "effective-directive": "img-src", "original-policy":

"default-src 'self';report-uri http://example.org/..."

}

Page 20: Integrity protection for third-party JavaScript
Page 21: Integrity protection for third-party JavaScript

support for inline scripts

Content-Security-Policy:

script-src 'sha256-YWIzOW...'

Page 22: Integrity protection for third-party JavaScript
Page 23: Integrity protection for third-party JavaScript

Strict Transport Securityaka HSTS

Page 24: Integrity protection for third-party JavaScript

Strict Transport Securityaka HSTS

mechanism for preventingHTTPS to HTTP downgrades

Page 25: Integrity protection for third-party JavaScript

telling the browser that your siteshould never be reached over HTTP

Page 26: Integrity protection for third-party JavaScript
Page 27: Integrity protection for third-party JavaScript

GET bank.com.au 301→

GET https://bank.com.au 200→

no HSTS, no sslstrip

Page 28: Integrity protection for third-party JavaScript

GET bank.com.au → 200

no HSTS, with sslstrip

Page 29: Integrity protection for third-party JavaScript

what does HSTS look like?

Page 30: Integrity protection for third-party JavaScript

$ curl -i https://login.xero.comHTTP/1.1 200 OKCache-Control: privateContent-Type: text/html; charset=utf-8Strict-Transport-Security: max-age=31536000X-Frame-Options: SAMEORIGIN

Page 31: Integrity protection for third-party JavaScript

with HSTS, with sslstrip

GET https://bank.com.au 200→

Page 32: Integrity protection for third-party JavaScript

silent client-side redirectsHTTP → HTTPS

Page 33: Integrity protection for third-party JavaScript

no HTTP traffic forsslstrip to tamper with

Page 34: Integrity protection for third-party JavaScript

except for the veryfirst connection

Page 35: Integrity protection for third-party JavaScript

https://hstspreload.appspot.com/

Page 36: Integrity protection for third-party JavaScript

pop quiz!how many .au sites are

on the preload list?

Page 37: Integrity protection for third-party JavaScript

aurainfosec.com.aubcm.com.aubigbrownpromotions.com.aucomssa.org.audata.qld.gov.audreamsforabetterworld.com.audylanscott.com.aufatzebra.com.aufreethought.org.aunetrider.net.aupublications.qld.gov.autechnotonic.com.authomastimepieces.com.autracktivity.com.autradingcentre.com.auwebandwords.com.au

16

Page 38: Integrity protection for third-party JavaScript

aurainfosec.com.aubcm.com.aubigbrownpromotions.com.aucomssa.org.audata.qld.gov.audreamsforabetterworld.com.audylanscott.com.aufatzebra.com.aufreethought.org.aunetrider.net.aupublications.qld.gov.autechnotonic.com.authomastimepieces.com.autracktivity.com.autradingcentre.com.auwebandwords.com.au

Page 39: Integrity protection for third-party JavaScript
Page 40: Integrity protection for third-party JavaScript
Page 41: Integrity protection for third-party JavaScript
Page 42: Integrity protection for third-party JavaScript
Page 43: Integrity protection for third-party JavaScript

2015?

Page 44: Integrity protection for third-party JavaScript
Page 45: Integrity protection for third-party JavaScript
Page 46: Integrity protection for third-party JavaScript
Page 47: Integrity protection for third-party JavaScript
Page 48: Integrity protection for third-party JavaScript

https://ajax.googleapis.com

/ajax/libs/jquery/1.8.0/

jquery.min.js

Page 49: Integrity protection for third-party JavaScript

how common is this?

Page 50: Integrity protection for third-party JavaScript
Page 51: Integrity protection for third-party JavaScript

what would happen if thatserver were compromised?

Page 52: Integrity protection for third-party JavaScript
Page 53: Integrity protection for third-party JavaScript

Bad Things™

steal sessionsleak confidential dataredirect to phishing sitesenlist DDoS zombies

Page 54: Integrity protection for third-party JavaScript

simple solution

Page 55: Integrity protection for third-party JavaScript

instead of this:

<scriptsrc=”https://ajax.googleapis.com...”>

Page 56: Integrity protection for third-party JavaScript

<scriptsrc=”https://ajax.googleapis.com...”integrity=”sha256-1z4uG/+cVbhShP...”>

do this:

Page 57: Integrity protection for third-party JavaScript

You owe me $10.00.

f4243c12541be6f79c73e539c426e07af2f6c4ef8794894f4903aee54542586d

Page 58: Integrity protection for third-party JavaScript

You owe me $1000.

1ebd7a8d15a6dab743f0c4d147f731bcfc6b74752afe43afa5389ba8830a2215

Page 59: Integrity protection for third-party JavaScript

guarantee:script won't changeor it'll be blocked

Page 60: Integrity protection for third-party JavaScript

limitation:won't work for scriptsthat change all the time

Page 61: Integrity protection for third-party JavaScript

3 types of scripts

Page 62: Integrity protection for third-party JavaScript

dynamically-generated script:

not a good fit for SRI

I

Page 63: Integrity protection for third-party JavaScript

immutable scripts:

perfect for SRI

II

Page 64: Integrity protection for third-party JavaScript

https://ajax.googleapis.com

/ajax/libs/jquery/1.8.0/

jquery.min.js

Page 65: Integrity protection for third-party JavaScript

what about your own scripts?

(they change, but you'rethe one changing them)

Page 66: Integrity protection for third-party JavaScript

IIIscripts under your control:

good fit for SRI

Page 67: Integrity protection for third-party JavaScript

can usually add the hashing toyour static resource pipeline

Page 68: Integrity protection for third-party JavaScript

#!/bin/sh

cat src/*.js > bundle.js

HASH=`sha256sum bundle.js |cut -f1 -d' '`

mv bundle.js public/bundle-${HASH}.js

Page 69: Integrity protection for third-party JavaScript

public/bundle-c2498bc358....js

Cache-Control: max-age=∞

Page 70: Integrity protection for third-party JavaScript

<script src=”widgets.js”><script src=”app.js”><script src=”menu.js”>

Page 71: Integrity protection for third-party JavaScript

<script src=”bundle-c2498bc....js”>

Page 72: Integrity protection for third-party JavaScript

<script src=”bundle-c2498bc....js” integrity=”sha256-c2498bc...”>

Page 73: Integrity protection for third-party JavaScript

what else?

Page 74: Integrity protection for third-party JavaScript

integrity=”

sha256-9Cm9ekBvKrtQ0A...

“ sha256-rKSr3LcX+EkeM=...

sha256-1z4uG/+cVbhShP...

sha384-RqG7UC/QK2TVRa...

sha512-AODL7idgffQeNs...

Page 75: Integrity protection for third-party JavaScript

integrity=”

sha256-9Cm9ekBvKrtQ0A...

sha256-rKSr3LcX+EkeM=...

sha256-1z4uG/+cVbhShP...

“ sha384-RqG7UC/QK2TVRa...

sha512-AODL7idgffQeNs...

Page 76: Integrity protection for third-party JavaScript

integrity=”

sha256-9Cm9ekBvKrtQ0A...

sha256-rKSr3LcX+EkeM=...

sha256-1z4uG/+cVbhShP...

sha384-RqG7UC/QK2TVRa...

sha512-AODL7idgffQeNs...

Page 77: Integrity protection for third-party JavaScript

what about cross-origin requests?

Page 78: Integrity protection for third-party JavaScript

“a web browser permits scripts contained in a firstweb page to access data in a second web page,but only if both web pages have the same origin”

same-origin policy

Page 79: Integrity protection for third-party JavaScript

example.com/index.html

Page 80: Integrity protection for third-party JavaScript

example.com/index.html

example.com/data.js:

var secret = 42;

Page 81: Integrity protection for third-party JavaScript

example.com/index.html

example.com/data.js:

var secret = 42;

evil.net/widget.js:

exfiltrate(secret);

Page 82: Integrity protection for third-party JavaScript

example.com/index.html

example.com/data.js:

var secret = 42;

evil.net/widget.js:

exfiltrate(secret);

Page 83: Integrity protection for third-party JavaScript
Page 84: Integrity protection for third-party JavaScript

on the server:

Access-Control-Allow-Origin: *

Page 85: Integrity protection for third-party JavaScript

on the server:

Access-Control-Allow-Origin: *

on the client:

crossorigin=”anonymous”

Page 86: Integrity protection for third-party JavaScript

<script

src=”https://ajax.googleapis.com...”

integrity=”sha256-1z4uG/+cVbhShP...”

crossorigin=”anonymous”>

complete example:

Page 87: Integrity protection for third-party JavaScript

<link rel="stylesheet"

href="style.css"

integrity="sha256-PgMdguwx/O..."

crossorigin=”anonymous”>

complete example:

Page 88: Integrity protection for third-party JavaScript

cat file.js

| openssl dgst -sha256 -binary

| openssl enc -base64 -A

Page 89: Integrity protection for third-party JavaScript

SRIhash.org

Page 90: Integrity protection for third-party JavaScript
Page 91: Integrity protection for third-party JavaScript

status?

Page 92: Integrity protection for third-party JavaScript

spec is being finalized

Page 93: Integrity protection for third-party JavaScript

(initial implementations)

Page 94: Integrity protection for third-party JavaScript

demo

Page 95: Integrity protection for third-party JavaScript

<html><head> <title>Bug 992096 - Implement SRI</title> <link rel="stylesheet" href="http://localhost/francois/sri/style.css" integrity=" sha256-PgMdguwx/O1ZJKqtGj54HIScoj0UEDV4ti5tLuc4DvA=" crossorigin="anonymous"></head>

<body> <h1>This should be red if the hash matches!</h1></body></html>

Page 96: Integrity protection for third-party JavaScript

h1 { color: red;}

Page 97: Integrity protection for third-party JavaScript
Page 98: Integrity protection for third-party JavaScript
Page 99: Integrity protection for third-party JavaScript

<html><head> <title>Bug 992096 - Implement SRI</title> <link rel="stylesheet" href="http://localhost/francois/sri/style.css" integrity=" sha256-bogus" crossorigin="anonymous"></head>

<body> <h1>This should be red if the hash matches!</h1></body></html>

Page 100: Integrity protection for third-party JavaScript
Page 101: Integrity protection for third-party JavaScript
Page 102: Integrity protection for third-party JavaScript

Questions?feedback:

[email protected]@w3.org

© 2015 François Marier <[email protected]>This work is licensed under aCreative Commons Attribution-ShareAlike 4.0 License.

Page 103: Integrity protection for third-party JavaScript

photo credits:

bank notes: https://www.flickr.com/photos/epsos/8463683689

web devs: https://www.flickr.com/photos/mbiddulph/238171366

explosion: https://www.flickr.com/photos/-cavin-/2313239884/