SlideShare a Scribd company logo
<script src=”https://ajax.
googleapis.com/ajax/libs/j
query/1.8.0/jquery.min.js”
integrity=”type:text/javas
cript sha512-AODL7idgffQeN
sYdTzut09nz9AINcjhj4jHD72H
cLirsidbC8tz+dof7gceOCQD8W
skeuRFfJ9CsgZTHlMiOYg==”><
/script>
Integrity protection for
3rd
-party JavaScript
François Marier @fmarier mozilla
Firefox
Security & Privacy
Web Platform
Web Platform
Integrity protection for third-party JavaScript
Content Security Policy
aka CSP
Content Security Policy
aka CSP
mechanism for preventing XSS
telling the browser what external
content is allowed to load
what does CSP look like?
$ curl --head https://mega.nz
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1989
Content-Security-Policy:
default-src 'self' *.mega.co.nz
*.mega.nz http://*.mega.co.nz
http://*.mega.nz;
script-src 'self' mega.co.nz mega.nz
data: blob:;
style-src 'self' 'unsafe-inline'
*.mega.co.nz *.mega.nz data: blob:;
frame-src 'self' mega:;
img-src 'self' *.mega.co.nz *.mega.nz
data: blob:
Hi you<script>
alert('p0wned');
</script>!
Tweet!
What's on your mind?
(of course, in a real web application,
this would never be a problem)
(the JS would be filtered out
during input sanitisation)
without CSP
Hi you!
Freedom Fighter @whaledumper - just moments ago
p0wned
Ok
with CSP
Hi you!
Freedom Fighter @whaledumper - just moments ago
Content-Security-Policy:
script-src 'self'
https://cdn.example.com
inline scripts are blocked unless
unsafe-inline is specified
directives:
script-src
object-src
style-src
img-src
media-src
frame-src
marquee-src
font-src
connect-src
directives:
script-src
object-src
style-src
img-src
media-src
frame-src
marquee-src
font-src
connect-src
$ curl --head https://twitter.com
HTTP/1.1 200 OK
content-length: 58347
content-security-policy: …
report-uri https://twitter.com/csp_report
violation reports:
"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/..."
}
Integrity protection for third-party JavaScript
new directives
form-action
plugin-types
support for inline scripts
Content-Security-Policy:
script-src 'sha256-YWIzOW...'
https://connect.microsoft.com/IE/feedback/details/793746/ie11-feature-request-support-for-the-content-security-policy-header
Integrity protection for third-party JavaScript
HTTP Strict
Transport Security
aka HSTS
HTTP Strict
Transport Security
aka HSTS
mechanism for preventing
HTTPS to HTTP downgrades
telling the browser that your site
should never be reached over HTTP
Integrity protection for third-party JavaScript
GET asb.co.nz 301→
GET https://asb.co.nz 200→
no HSTS, no sslstrip
GET asb.co.nz → 200
no HSTS, with sslstrip
what does HSTS look like?
$ curl -i https://login.xero.com
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Strict-Transport-Security: max-age=31536000
X-Frame-Options: SAMEORIGIN
with HSTS, with sslstrip
GET https://asb.co.nz 200→
silent client-side redirects
HTTP → HTTPS
no HTTP traffic for
sslstrip to tamper with
except for the very
first connection
https://hstspreload.appspot.com/
pop quiz!
how many .nz sites are
on the preload list?
$ grep .nz force-https.json
{ "name": "mega.co.nz" },
{ "name": "api.mega.co.nz" },
http://blogs.msdn.com/b/ie/archive/2015/02/16/http-strict-transport-security-comes-to-internet-explorer.aspx
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
wanna know more?
https://speakerdeck.com/fmarier/defeating-cross-site-scripting-with-content-security-policy-updated
2015?
no need to add
any extra headers
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
https://ajax.googleapis.com
/ajax/libs/jquery/1.8.0/
jquery.min.js
how common is this?
Integrity protection for third-party JavaScript
what would happen if that
server were compromised?
Integrity protection for third-party JavaScript
Bad Things™
steal sessions
leak confidential data
redirect to phishing sites
enlist DDoS zombies
simple solution
<script
src=”https://ajax.googleapis.com...”>
instead of this:
<script
src=”https://ajax.googleapis.com...”
integrity=”sha256-1z4uG/+cVbhShP...”>
do this:
You owe me $10.00.
f4243c12541be6f79c73e539c426e07a
f2f6c4ef8794894f4903aee54542586d
You owe me $1000.
1ebd7a8d15a6dab743f0c4d147f731bc
fc6b74752afe43afa5389ba8830a2215
guarantee:
script won't change
or it'll be blocked
limitation:
won't work for scripts
that change all the time
3 types of scripts
dynamically-generated script:
not a good fit for SRI
https://ajax.googleapis.com
/ajax/libs/jquery/1.8.0/
jquery.min.js
immutable scripts:
perfect for SRI
what about your own scripts?
(they change, but you're
the one changing them)
scripts under your control:
good fit for SRI
can usually add the hashing to
your static resource pipeline
#!/bin/sh
cat src/*.js > bundle.js
HASH=`sha256sum bundle.js |cut -f1 -d' '`
mv bundle.js public/bundle-${HASH}.js
public/bundle-c2498bc358....js
Cache-Control: max-age=∞
<script src=”widgets.js”>
<script src=”app.js”>
<script src=”menu.js”>
<script src=”bundle-c2498bc....js”>
<script src=”bundle-c2498bc....js”
integrity=”sha256-c2498bc...”>
what else?
integrity=”
sha256-1z4uG/+cVbhShP...
”
integrity=”
type:application/javascript
sha256-1z4uG/+cVbhShP...
”
integrity=”
type:application/javascript
sha512-AODL7idgffQeNs...
”
integrity=”
type:application/javascript
sha256-1z4uG/+cVbhShP...
sha384-RqG7UC/QK2TVRa...
sha512-AODL7idgffQeNs...
”
<link rel="stylesheet"
href="style.css"
integrity="sha256-PgMdguwx/O...">
stylesheet support
violation reports
Content-Security-Policy:
integrity-policy block
violation reports
Content-Security-Policy:
integrity-policy report;
report-uri https://...
cat file.js
| openssl dgst -sha256 -binary
| openssl enc -base64 -A
SRIhash.org
Integrity protection for third-party JavaScript
status?
spec is approaching
“last call”
(initial implementations)
© 2015 François Marier <francois@mozilla.com>
This work is licensed under a
Creative Commons Attribution-ShareAlike 4.0 License.
Questions?
feedback:
francois@mozilla.com
mozilla.dev.security
public-webappsec@w3.org
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/

More Related Content

PDF
Integrity protection for third-party JavaScript
PDF
URL to HTML
PDF
Security and Privacy on the Web in 2016
PDF
Security and Privacy on the Web in 2015
PDF
Defeating Cross-Site Scripting with Content Security Policy (updated)
PPTX
Java script, security and you - Tri-Cities Javascript Developers Group
PDF
JavaScript Security
PPTX
Javascript Security
Integrity protection for third-party JavaScript
URL to HTML
Security and Privacy on the Web in 2016
Security and Privacy on the Web in 2015
Defeating Cross-Site Scripting with Content Security Policy (updated)
Java script, security and you - Tri-Cities Javascript Developers Group
JavaScript Security
Javascript Security

What's hot (20)

PPTX
Honing headers for highly hardened highspeed hypertext
PDF
Content Security Policy
PDF
20190516 web security-basic
PDF
[CB16] 80時間でWebを一周:クロムミウムオートメーションによるスケーラブルなフィンガープリント by Isaac Dawson
PDF
Mitigate Maliciousness -- jQuery Europe 2013
PDF
Two scoops of Django - Security Best Practices
PPTX
Mitigating CSRF with two lines of codes
PPTX
Django Web Application Security
PPTX
Client-side JavaScript Vulnerabilities
PDF
Http security response headers
PDF
Practical django secuirty
PDF
Site Security Policy - Yahoo! Security Week
PDF
Preventing XSS with Content Security Policy
PDF
Modern Web Application Defense
PDF
HTTP For the Good or the Bad - FSEC Edition
PDF
HTTP Security Headers Every Java Developer Must Know
PDF
Top Ten Web Hacking Techniques (2010)
PDF
Protecting Java EE Web Apps with Secure HTTP Headers
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
PDF
Java EE 6 Security in practice with GlassFish
Honing headers for highly hardened highspeed hypertext
Content Security Policy
20190516 web security-basic
[CB16] 80時間でWebを一周:クロムミウムオートメーションによるスケーラブルなフィンガープリント by Isaac Dawson
Mitigate Maliciousness -- jQuery Europe 2013
Two scoops of Django - Security Best Practices
Mitigating CSRF with two lines of codes
Django Web Application Security
Client-side JavaScript Vulnerabilities
Http security response headers
Practical django secuirty
Site Security Policy - Yahoo! Security Week
Preventing XSS with Content Security Policy
Modern Web Application Defense
HTTP For the Good or the Bad - FSEC Edition
HTTP Security Headers Every Java Developer Must Know
Top Ten Web Hacking Techniques (2010)
Protecting Java EE Web Apps with Secure HTTP Headers
Case Study of Django: Web Frameworks that are Secure by Default
Java EE 6 Security in practice with GlassFish
Ad

Viewers also liked (6)

PDF
Supporting Debian machines for friends and family
PDF
URL to HTML
PDF
Privacy and Tracking Protection in Firefox
PDF
Hardening Firefox for Security and Privacy
PDF
Don't be rich, Live rich - One year on the road - The good and the bad
PDF
Foot Notes
Supporting Debian machines for friends and family
URL to HTML
Privacy and Tracking Protection in Firefox
Hardening Firefox for Security and Privacy
Don't be rich, Live rich - One year on the road - The good and the bad
Foot Notes
Ad

Similar to Integrity protection for third-party JavaScript (20)

PDF
Securing the client side web
PDF
Rails security: above and beyond the defaults
PDF
Content Security Policy - Lessons learned at Yahoo
PDF
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
PDF
W3C Content Security Policy
PDF
Breaking Bad CSP
PDF
Content Security Policies: Let's Break Stuff for WordCamp London
PPTX
W3 conf hill-html5-security-realities
PDF
Defeating Cross-Site Scripting with Content Security Policy
PPTX
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
PDF
CSPs: Let's Break Stuff for PHP Benelux
PDF
Content Security Policies: Let's Break Stuff @ PHP London, Sept 2017
PDF
Content Security Policies: Let's Break Stuff @ Scotland PHP
PDF
Web Security - CSP & Web Cryptography
PPTX
Protecting Web App users in today’s hostile environment
PDF
Web Application Security 2nd Edition (Early Release) Andrew Hoffman
PDF
Web Application Security 2nd Edition (Early Release) Andrew Hoffman
PDF
Content Security Policies: Let's Break Stuff for PHPSW at Bath Digital
PDF
Content Security Policies: Let's Break Stuff
PDF
Content Security Policy
Securing the client side web
Rails security: above and beyond the defaults
Content Security Policy - Lessons learned at Yahoo
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
W3C Content Security Policy
Breaking Bad CSP
Content Security Policies: Let's Break Stuff for WordCamp London
W3 conf hill-html5-security-realities
Defeating Cross-Site Scripting with Content Security Policy
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
CSPs: Let's Break Stuff for PHP Benelux
Content Security Policies: Let's Break Stuff @ PHP London, Sept 2017
Content Security Policies: Let's Break Stuff @ Scotland PHP
Web Security - CSP & Web Cryptography
Protecting Web App users in today’s hostile environment
Web Application Security 2nd Edition (Early Release) Andrew Hoffman
Web Application Security 2nd Edition (Early Release) Andrew Hoffman
Content Security Policies: Let's Break Stuff for PHPSW at Bath Digital
Content Security Policies: Let's Break Stuff
Content Security Policy

More from Francois Marier (20)

PDF
Security and Privacy settings for Firefox Power Users
PDF
Getting Browsers to Improve the Security of Your Webapp
PDF
Supporting Debian machines for friends and family
PDF
Outsourcing your webapp maintenance to Debian
PDF
Easy logins for Ruby web applications
PDF
Easy logins for JavaScript web applications
PDF
You're still using passwords on your site?
PDF
Killing Passwords with JavaScript
PDF
Securing the Web without site-specific passwords
PDF
Easy logins for PHP web applications
PDF
Persona: a federated and privacy-protecting login system for the whole Web
PDF
Taking the pain out of signing users in
PDF
Mozilla Persona for your domain
PDF
Passwords and freedom: can we lose the former and retain the latter?
PDF
Login de usuários: podemos fazer algo melhor que usar senhas ou serviços cent...
PDF
The problem with passwords on the web and what to do about it
PDF
Securing the Web without site-specific passwords
PDF
Persona: un système d'identité pour le Web
PDF
Passwords suck, but centralized proprietary services are not the answer
PDF
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Security and Privacy settings for Firefox Power Users
Getting Browsers to Improve the Security of Your Webapp
Supporting Debian machines for friends and family
Outsourcing your webapp maintenance to Debian
Easy logins for Ruby web applications
Easy logins for JavaScript web applications
You're still using passwords on your site?
Killing Passwords with JavaScript
Securing the Web without site-specific passwords
Easy logins for PHP web applications
Persona: a federated and privacy-protecting login system for the whole Web
Taking the pain out of signing users in
Mozilla Persona for your domain
Passwords and freedom: can we lose the former and retain the latter?
Login de usuários: podemos fazer algo melhor que usar senhas ou serviços cent...
The problem with passwords on the web and what to do about it
Securing the Web without site-specific passwords
Persona: un système d'identité pour le Web
Passwords suck, but centralized proprietary services are not the answer
Building Persona: federated and privacy-sensitive identity for the Web (Open ...

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Nekopoi APK 2025 free lastest update
PPTX
ai tools demonstartion for schools and inter college
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Essential Infomation Tech presentation.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
AI in Product Development-omnex systems
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administraation Chapter 3
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Introduction to Artificial Intelligence
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How to Migrate SBCGlobal Email to Yahoo Easily
Nekopoi APK 2025 free lastest update
ai tools demonstartion for schools and inter college
L1 - Introduction to python Backend.pptx
Essential Infomation Tech presentation.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
AI in Product Development-omnex systems
CHAPTER 2 - PM Management and IT Context
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administraation Chapter 3
Upgrade and Innovation Strategies for SAP ERP Customers
Which alternative to Crystal Reports is best for small or large businesses.pdf
Softaken Excel to vCard Converter Software.pdf
Introduction to Artificial Intelligence
PTS Company Brochure 2025 (1).pdf.......
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

Integrity protection for third-party JavaScript