SlideShare a Scribd company logo
@BruntyCSP: Let’s Break Stuff
Content Security Policies
Let’s Break Stuff
@BruntyCSP: Let’s Break Stuff
Because you all totally care about this, right?!
About me
▸ Senior Software Engineer at Viva IT

(those folks in orange hoodies at some conferences & events
you may have been to)
▸ @Brunty
▸ @PHPem
▸ mfyu.co.uk
▸ matt@mfyu.co.uk
@BruntyCSP: Let’s Break Stuff
Blah blah… just get on with the talk
Things I do
▸ Dungeon master for D&D campaigns
▸ Mentor, lead & teach apprentices & junior developers
▸ Run & organise PHP East Midlands
▸ Speak at user groups and conferences
▸ Break production sites with incorrectly configured content
security policies
@BruntyCSP: Let’s Break Stuff
Disclaimer:
I don’t work with WordPress
@BruntyCSP: Let’s Break Stuff
Oh good, finally we’re getting started
A talk in 3 parts
▸ XSS

▸ CSP

▸ Break stuff

@BruntyCSP: Let’s Break Stuff
The scary stuff
@BruntyCSP: Let’s Break Stuff
First, some background
What is Cross-Site-Scripting (XSS)?
▸ XSS enables an attacker to inject client-side scripts into non-
malicious web pages viewed by other users
▸ In 2016 there was a 61% likelihood of a browser-based
vulnerability being found in a web application
▸ Of those browser based vulnerabilities, 86% were found to be
XSS related
▸ That’s just over 52% of all web application vulnerabilities

https://www.edgescan.com/assets/docs/reports/2016-edgescan-stats-report.pdf
@BruntyCSP: Let’s Break Stuff
I mean, it’s just a joke vulnerability, right?!
What can be done with XSS?
▸ Put pictures of cats in web pages
▸ alert(‘💩’);
▸ Rickroll a user
▸ Twitter self-retweeting tweet

https://www.youtube.com/watch?v=zv0kZKC6GAM
▸ Samy worm

https://en.wikipedia.org/wiki/Samy_(computer_worm)
@BruntyCSP: Let’s Break Stuff
Well… maybe it’s not a joke vulnerability
What can be done with XSS?
▸ Make modifications to the DOM
▸ Load additional scripts, resources, styles, images etc
▸ Access HTML5 APIs - webcam, microphone, geolocation
▸ Steal cookies (and therefore steal session cookies)
@BruntyCSP: Let’s Break Stuff
@BruntyCSP: Let’s Break Stuff
It’s really not a joke vulnerability
What can be done with XSS?
https://www.wired.com/2008/03/hackers-assault-epilepsy-patients-via-computer/
@BruntyCSP: Let’s Break Stuff
Types of XSS attack
Stored XSS (AKA Persistent or Type I)
▸ Occurs when input is stored - generally in a server-side
database, but not always
▸ This could also be within a HTML5 database, thus never being
sent to the server at all
▸ who.is was a site Rickrolled by a TXT record in the DNS of a
website (yes, really)
@BruntyCSP: Let’s Break Stuff
Types of XSS attack
Reflected XSS (AKA Non-persistent or Type II)
▸ Occurs when user input provided in the request is immediately
returned - such as in an error message, search string etc
▸ Data is not stored, and in some instances, may not even reach
the server (see the next type of XSS)
@BruntyCSP: Let’s Break Stuff
Types of XSS attack
DOM-Based XSS (AKA Type-0)
▸ The entire flow of the attack takes place within the browser
▸ For example, if JavaScript in the site takes input, and uses
something like document.write based on that input, it can be
vulnerable to a DOM-based XSS attack
@BruntyCSP: Let’s Break Stuff
Types of XSS attack
Self XSS
▸ Social-engineering form of XSS
▸ Requires the user to execute code in the browser
▸ Doing so via the console can’t be protected by a lot of methods
▸ Not considered a ‘true’ XSS attack due to requiring the user to
execute the code
@BruntyCSP: Let’s Break Stuff
Title Text
Body Level One
Body Level Two
Body Level Three
@BruntyCSP: Let’s Break Stuff @BruntyCSP: Let’s Break Stuff
Let’s fight back
@BruntyCSP: Let’s Break Stuff
HTTP response header to help reduce
XSS risks
What is a CSP?
@BruntyCSP: Let’s Break Stuff
It is not a silver bullet
What is a CSP?
@BruntyCSP: Let’s Break Stuff
It is an extra layer of security
What is a CSP?
@BruntyCSP: Let’s Break Stuff
It declares what resources are allowed
to load
How does a CSP work?
@BruntyCSP: Let’s Break Stuff
Browser support
@BruntyCSP: Let’s Break Stuff
Meh, it’s alright(ish)
Sorry IE users
@BruntyCSP: Let’s Break Stuff
CSP to the rescue!
What can we protect?
▸ default-src
▸ script-src
▸ style-src
▸ img-src
▸ form-action
▸ update-insecure-requests
@BruntyCSP: Let’s Break Stuff
Full reference:https://content-security-policy.com

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
@BruntyCSP: Let’s Break Stuff
img-src *
Allows any URL except data: blob:
filesystem: schemes.
@BruntyCSP: Let’s Break Stuff
object-src 'none'
Don’t load resources from any
source
@BruntyCSP: Let’s Break Stuff
style-src ‘self'
Allow loading from same scheme,
host and port
@BruntyCSP: Let’s Break Stuff
script-src 'unsafe-inline'
Allows use of inline source
elements such as style attribute,
onclick, or script tag bodies
@BruntyCSP: Let’s Break Stuff
Don’t use unsafe-inline
@BruntyCSP: Let’s Break Stuff
<script nonce="$RANDOM">...</script>
script-src 'self' 'nonce-$RANDOM'
@BruntyCSP: Let’s Break Stuff
Content-Security-Policy: default-src 'none'; script-
src 'self' https://*.google.com 'nonce-random123';
style-src 'self'; img-src 'self'; upgrade-insecure-
requests; form-action 'self';
@BruntyCSP: Let’s Break Stuff
I broke production with a bad CSP
Learn from my mistakes
@BruntyCSP: Let’s Break Stuff
Don’t do what I did
@BruntyCSP: Let’s Break Stuff
Report-URI
@BruntyCSP: Let’s Break Stuff
When a policy failure occurs, the
browser sends a JSON payload to
that URL
@BruntyCSP: Let’s Break Stuff
{
"csp-report": {
"blocked-uri": "self",
"document-uri": "https://mysite.com",
"line-number": 1,
"original-policy": "script-src 'self'",
"script-sample": "try { for(var lastpass_iter=0; lastpass...",
"source-file": "https://mysite.com",
"violated-directive": "script-src 'self'"
}
}
@BruntyCSP: Let’s Break Stuff
report-uri.io
@BruntyCSP: Let’s Break Stuff
@BruntyCSP: Let’s Break Stuff
Report-only
@BruntyCSP: Let’s Break Stuff
Content-Security-Policy-Report-Only: [policy]; report-
uri https://app.report-uri.io/r/default/csp/reportOnly;
@BruntyCSP: Let’s Break Stuff
Trial stuff before
Enforcing
@BruntyCSP: Let’s Break Stuff
There will be noise,
lots of noise
@BruntyCSP: Let’s Break Stuff
Ways to make dealing with a CSP easier
Tips
▸ Have an easy and quick way to disable the CSP in production if
required
▸ Better yet, have a way to switch it from enforced to report only
so you can get violations reported to help you debug
▸ Add the CSP at an application level if you need a nonce
@BruntyCSP: Let’s Break Stuff
Ways to make dealing with a CSP easier
Multiple policies
▸ They complicate things
▸ For a resource to be allowed, it must be allowed by all policies
declared (problematic if an enforced policy)
▸ I tend to avoid them where possible on enforced policies
▸ But with report-only mode they can be very useful to deploy
and test multiple policies at the same time (as nothing breaks
for the user)
@BruntyCSP: Let’s Break Stuff
Ways to remove barriers in development
Cryptographic nonces
▸ Don’t generate multiple nonces in the same request (but do
generate a new nonce on each separate request)
▸ If using a templating engine (such as twig) - add the nonce as a
global so it’s available in every template by default
▸ Write a helper in your template engine to generate script tags
with a nonce if it’s available
@BruntyCSP: Let’s Break Stuff
The problem with CSPs
and CMSs
@BruntyCSP: Let’s Break Stuff
Plugins
@BruntyCSP: Let’s Break Stuff
Inline scripts (without
nonces) are the enemy
@BruntyCSP: Let’s Break Stuff
Stop building dodgy
plugins, avoid inline
scripts & eval
Troy Hunt
@BruntyCSP: Let’s Break Stuff
[look at] making
WordPress more CSP
friendly
Scott Helme
@BruntyCSP: Let’s Break Stuff
Inline scripts (without
nonces) are the enemy
@BruntyCSP: Let’s Break Stuff
Demo time!
Let’s break stuff
@BruntyCSP: Let’s Break Stuff
@scott_helme
He knows his stuff!
@BruntyCSP: Let’s Break Stuff
@mr_goodwin
He first introduced me to
what a CSP is
@BruntyCSP: Let’s Break Stuff
Homework time!
Links & further reading
▸ https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
▸ https://content-security-policy.com
▸ https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
▸ https://report-uri.io
▸ https://scotthelme.co.uk/just-how-much-traffic-can-you-generate-using-csp/
▸ https://www.edgescan.com/assets/docs/reports/2016-edgescan-stats-report.pdf
▸ http://theharmonyguy.com/oldsite/2011/04/21/recent-facebook-xss-attacks-show-increasing-
sophistication/
▸ https://github.com/Brunty/csp-demo
@BruntyCSP: Let’s Break Stuff
Thank you
@BruntyCSP: Let’s Break Stuff
Questions?
@Brunty
@PHPem
mfyu.co.uk
matt@mfyu.co.uk

More Related Content

Similar to Content Security Policies: Let's Break Stuff for WordCamp London

Chaos Driven Development (Bruce Wong)
Chaos Driven Development (Bruce Wong)Chaos Driven Development (Bruce Wong)
Chaos Driven Development (Bruce Wong)
Future Insights
 
Chaos Driven Development
Chaos Driven DevelopmentChaos Driven Development
Chaos Driven Development
Bruce Wong
 
Debezium vs. the World: An Overview of the CDC Ecosystem
Debezium vs. the World: An Overview of the CDC EcosystemDebezium vs. the World: An Overview of the CDC Ecosystem
Debezium vs. the World: An Overview of the CDC Ecosystem
HostedbyConfluent
 
Shmoocon 2015 - httpscreenshot
Shmoocon 2015 - httpscreenshotShmoocon 2015 - httpscreenshot
Shmoocon 2015 - httpscreenshot
jstnkndy
 
Micro services
Micro servicesMicro services
Micro services
Alex Punnen
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
Andrew Kirkpatrick
 
Commit Hooks: the Subtle Hammer
Commit Hooks: the Subtle HammerCommit Hooks: the Subtle Hammer
Commit Hooks: the Subtle Hammer
Ben McGraw
 
Prometheus - Open Source Forum Japan
Prometheus  - Open Source Forum JapanPrometheus  - Open Source Forum Japan
Prometheus - Open Source Forum Japan
Brian Brazil
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header Security
Mikal Villa
 
2015-04-25-content-security-policy
2015-04-25-content-security-policy2015-04-25-content-security-policy
2015-04-25-content-security-policy
Sastry Tumuluri
 
Protecting Web App users in today’s hostile environment
Protecting Web App users in today’s hostile environmentProtecting Web App users in today’s hostile environment
Protecting Web App users in today’s hostile environment
ajitdhumale
 
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
DataStax Academy
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting ClassThe Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
Rob Fuller
 
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real WorldHow Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
Christopher Grant Ward
 
Velocity 2015 Amsterdam: Alerts overload
Velocity 2015 Amsterdam: Alerts overloadVelocity 2015 Amsterdam: Alerts overload
Velocity 2015 Amsterdam: Alerts overload
sarahjwells
 
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick StoxEverything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
patrickstox
 
Facilitating Release Planning Event
Facilitating Release Planning EventFacilitating Release Planning Event
Facilitating Release Planning Event
Ravi Tadwalkar
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
Chris Gates
 
[Cluj] CSP (Content Security Policy)
[Cluj] CSP (Content Security Policy)[Cluj] CSP (Content Security Policy)
[Cluj] CSP (Content Security Policy)
OWASP EEE
 

Similar to Content Security Policies: Let's Break Stuff for WordCamp London (20)

Chaos Driven Development (Bruce Wong)
Chaos Driven Development (Bruce Wong)Chaos Driven Development (Bruce Wong)
Chaos Driven Development (Bruce Wong)
 
Chaos Driven Development
Chaos Driven DevelopmentChaos Driven Development
Chaos Driven Development
 
Debezium vs. the World: An Overview of the CDC Ecosystem
Debezium vs. the World: An Overview of the CDC EcosystemDebezium vs. the World: An Overview of the CDC Ecosystem
Debezium vs. the World: An Overview of the CDC Ecosystem
 
Shmoocon 2015 - httpscreenshot
Shmoocon 2015 - httpscreenshotShmoocon 2015 - httpscreenshot
Shmoocon 2015 - httpscreenshot
 
Micro services
Micro servicesMicro services
Micro services
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
 
Commit Hooks: the Subtle Hammer
Commit Hooks: the Subtle HammerCommit Hooks: the Subtle Hammer
Commit Hooks: the Subtle Hammer
 
Prometheus - Open Source Forum Japan
Prometheus  - Open Source Forum JapanPrometheus  - Open Source Forum Japan
Prometheus - Open Source Forum Japan
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header Security
 
2015-04-25-content-security-policy
2015-04-25-content-security-policy2015-04-25-content-security-policy
2015-04-25-content-security-policy
 
Protecting Web App users in today’s hostile environment
Protecting Web App users in today’s hostile environmentProtecting Web App users in today’s hostile environment
Protecting Web App users in today’s hostile environment
 
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
Cassandra Summit 2014: Social Media Security Company Nexgate Relies on Cassan...
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting ClassThe Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
 
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real WorldHow Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
How Chunky Do You Need To Be?: Adaptive Content Strategies For The Real World
 
Velocity 2015 Amsterdam: Alerts overload
Velocity 2015 Amsterdam: Alerts overloadVelocity 2015 Amsterdam: Alerts overload
Velocity 2015 Amsterdam: Alerts overload
 
50 Ways To Love Your Project
50 Ways To Love Your Project50 Ways To Love Your Project
50 Ways To Love Your Project
 
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick StoxEverything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
Everything That Can Go Wrong Will Go Wrong - Tech SEO Boost 2017 - Patrick Stox
 
Facilitating Release Planning Event
Facilitating Release Planning EventFacilitating Release Planning Event
Facilitating Release Planning Event
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
 
[Cluj] CSP (Content Security Policy)
[Cluj] CSP (Content Security Policy)[Cluj] CSP (Content Security Policy)
[Cluj] CSP (Content Security Policy)
 

More from Matt Brunt

BDD & Behat for PHPUK
BDD & Behat for PHPUKBDD & Behat for PHPUK
BDD & Behat for PHPUK
Matt Brunt
 
BDD & Behat for PHPNE
BDD & Behat for PHPNEBDD & Behat for PHPNE
BDD & Behat for PHPNE
Matt Brunt
 
BDD & Behat for Glasgow PHP
BDD & Behat for Glasgow PHPBDD & Behat for Glasgow PHP
BDD & Behat for Glasgow PHP
Matt Brunt
 
BDD & Behat
BDD & BehatBDD & Behat
BDD & Behat
Matt Brunt
 
BDD & Behat for Srijan Technologies
BDD & Behat for Srijan TechnologiesBDD & Behat for Srijan Technologies
BDD & Behat for Srijan Technologies
Matt Brunt
 
CSP - What? Why? How? PHPNW16
CSP - What? Why? How? PHPNW16CSP - What? Why? How? PHPNW16
CSP - What? Why? How? PHPNW16
Matt Brunt
 
PHPNW16 Matt Brunt - BDD & Behat
PHPNW16 Matt Brunt - BDD & BehatPHPNW16 Matt Brunt - BDD & Behat
PHPNW16 Matt Brunt - BDD & Behat
Matt Brunt
 
BDD - telling stories through code for PHPem
BDD - telling stories through code for PHPemBDD - telling stories through code for PHPem
BDD - telling stories through code for PHPem
Matt Brunt
 
BDD: Telling stories through code [For TechNotts]
BDD: Telling stories through code [For TechNotts]BDD: Telling stories through code [For TechNotts]
BDD: Telling stories through code [For TechNotts]
Matt Brunt
 

More from Matt Brunt (10)

BDD & Behat for PHPUK
BDD & Behat for PHPUKBDD & Behat for PHPUK
BDD & Behat for PHPUK
 
BDD & Behat for PHPNE
BDD & Behat for PHPNEBDD & Behat for PHPNE
BDD & Behat for PHPNE
 
BDD & Behat for Glasgow PHP
BDD & Behat for Glasgow PHPBDD & Behat for Glasgow PHP
BDD & Behat for Glasgow PHP
 
BDD & Behat
BDD & BehatBDD & Behat
BDD & Behat
 
BDD & Behat for Srijan Technologies
BDD & Behat for Srijan TechnologiesBDD & Behat for Srijan Technologies
BDD & Behat for Srijan Technologies
 
CSP - What? Why? How? PHPNW16
CSP - What? Why? How? PHPNW16CSP - What? Why? How? PHPNW16
CSP - What? Why? How? PHPNW16
 
PHPNW16 Matt Brunt - BDD & Behat
PHPNW16 Matt Brunt - BDD & BehatPHPNW16 Matt Brunt - BDD & Behat
PHPNW16 Matt Brunt - BDD & Behat
 
BDD - telling stories through code for PHPem
BDD - telling stories through code for PHPemBDD - telling stories through code for PHPem
BDD - telling stories through code for PHPem
 
BDD: Telling stories through code [For TechNotts]
BDD: Telling stories through code [For TechNotts]BDD: Telling stories through code [For TechNotts]
BDD: Telling stories through code [For TechNotts]
 
Intro to Gulp
Intro to GulpIntro to Gulp
Intro to Gulp
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Content Security Policies: Let's Break Stuff for WordCamp London

  • 1. @BruntyCSP: Let’s Break Stuff Content Security Policies Let’s Break Stuff
  • 2. @BruntyCSP: Let’s Break Stuff Because you all totally care about this, right?! About me ▸ Senior Software Engineer at Viva IT
 (those folks in orange hoodies at some conferences & events you may have been to) ▸ @Brunty ▸ @PHPem ▸ mfyu.co.uk ▸ matt@mfyu.co.uk
  • 3. @BruntyCSP: Let’s Break Stuff Blah blah… just get on with the talk Things I do ▸ Dungeon master for D&D campaigns ▸ Mentor, lead & teach apprentices & junior developers ▸ Run & organise PHP East Midlands ▸ Speak at user groups and conferences ▸ Break production sites with incorrectly configured content security policies
  • 4. @BruntyCSP: Let’s Break Stuff Disclaimer: I don’t work with WordPress
  • 5. @BruntyCSP: Let’s Break Stuff Oh good, finally we’re getting started A talk in 3 parts ▸ XSS
 ▸ CSP
 ▸ Break stuff

  • 6. @BruntyCSP: Let’s Break Stuff The scary stuff
  • 7. @BruntyCSP: Let’s Break Stuff First, some background What is Cross-Site-Scripting (XSS)? ▸ XSS enables an attacker to inject client-side scripts into non- malicious web pages viewed by other users ▸ In 2016 there was a 61% likelihood of a browser-based vulnerability being found in a web application ▸ Of those browser based vulnerabilities, 86% were found to be XSS related ▸ That’s just over 52% of all web application vulnerabilities
 https://www.edgescan.com/assets/docs/reports/2016-edgescan-stats-report.pdf
  • 8. @BruntyCSP: Let’s Break Stuff I mean, it’s just a joke vulnerability, right?! What can be done with XSS? ▸ Put pictures of cats in web pages ▸ alert(‘💩’); ▸ Rickroll a user ▸ Twitter self-retweeting tweet
 https://www.youtube.com/watch?v=zv0kZKC6GAM ▸ Samy worm
 https://en.wikipedia.org/wiki/Samy_(computer_worm)
  • 9. @BruntyCSP: Let’s Break Stuff Well… maybe it’s not a joke vulnerability What can be done with XSS? ▸ Make modifications to the DOM ▸ Load additional scripts, resources, styles, images etc ▸ Access HTML5 APIs - webcam, microphone, geolocation ▸ Steal cookies (and therefore steal session cookies)
  • 11. @BruntyCSP: Let’s Break Stuff It’s really not a joke vulnerability What can be done with XSS? https://www.wired.com/2008/03/hackers-assault-epilepsy-patients-via-computer/
  • 12. @BruntyCSP: Let’s Break Stuff Types of XSS attack Stored XSS (AKA Persistent or Type I) ▸ Occurs when input is stored - generally in a server-side database, but not always ▸ This could also be within a HTML5 database, thus never being sent to the server at all ▸ who.is was a site Rickrolled by a TXT record in the DNS of a website (yes, really)
  • 13. @BruntyCSP: Let’s Break Stuff Types of XSS attack Reflected XSS (AKA Non-persistent or Type II) ▸ Occurs when user input provided in the request is immediately returned - such as in an error message, search string etc ▸ Data is not stored, and in some instances, may not even reach the server (see the next type of XSS)
  • 14. @BruntyCSP: Let’s Break Stuff Types of XSS attack DOM-Based XSS (AKA Type-0) ▸ The entire flow of the attack takes place within the browser ▸ For example, if JavaScript in the site takes input, and uses something like document.write based on that input, it can be vulnerable to a DOM-based XSS attack
  • 15. @BruntyCSP: Let’s Break Stuff Types of XSS attack Self XSS ▸ Social-engineering form of XSS ▸ Requires the user to execute code in the browser ▸ Doing so via the console can’t be protected by a lot of methods ▸ Not considered a ‘true’ XSS attack due to requiring the user to execute the code
  • 17. Title Text Body Level One Body Level Two Body Level Three @BruntyCSP: Let’s Break Stuff @BruntyCSP: Let’s Break Stuff Let’s fight back
  • 18. @BruntyCSP: Let’s Break Stuff HTTP response header to help reduce XSS risks What is a CSP?
  • 19. @BruntyCSP: Let’s Break Stuff It is not a silver bullet What is a CSP?
  • 20. @BruntyCSP: Let’s Break Stuff It is an extra layer of security What is a CSP?
  • 21. @BruntyCSP: Let’s Break Stuff It declares what resources are allowed to load How does a CSP work?
  • 22. @BruntyCSP: Let’s Break Stuff Browser support
  • 23. @BruntyCSP: Let’s Break Stuff Meh, it’s alright(ish) Sorry IE users
  • 24. @BruntyCSP: Let’s Break Stuff CSP to the rescue! What can we protect? ▸ default-src ▸ script-src ▸ style-src ▸ img-src ▸ form-action ▸ update-insecure-requests
  • 25. @BruntyCSP: Let’s Break Stuff Full reference:https://content-security-policy.com
 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
  • 26. @BruntyCSP: Let’s Break Stuff img-src * Allows any URL except data: blob: filesystem: schemes.
  • 27. @BruntyCSP: Let’s Break Stuff object-src 'none' Don’t load resources from any source
  • 28. @BruntyCSP: Let’s Break Stuff style-src ‘self' Allow loading from same scheme, host and port
  • 29. @BruntyCSP: Let’s Break Stuff script-src 'unsafe-inline' Allows use of inline source elements such as style attribute, onclick, or script tag bodies
  • 30. @BruntyCSP: Let’s Break Stuff Don’t use unsafe-inline
  • 31. @BruntyCSP: Let’s Break Stuff <script nonce="$RANDOM">...</script> script-src 'self' 'nonce-$RANDOM'
  • 32. @BruntyCSP: Let’s Break Stuff Content-Security-Policy: default-src 'none'; script- src 'self' https://*.google.com 'nonce-random123'; style-src 'self'; img-src 'self'; upgrade-insecure- requests; form-action 'self';
  • 33. @BruntyCSP: Let’s Break Stuff I broke production with a bad CSP Learn from my mistakes
  • 34. @BruntyCSP: Let’s Break Stuff Don’t do what I did
  • 35. @BruntyCSP: Let’s Break Stuff Report-URI
  • 36. @BruntyCSP: Let’s Break Stuff When a policy failure occurs, the browser sends a JSON payload to that URL
  • 37. @BruntyCSP: Let’s Break Stuff { "csp-report": { "blocked-uri": "self", "document-uri": "https://mysite.com", "line-number": 1, "original-policy": "script-src 'self'", "script-sample": "try { for(var lastpass_iter=0; lastpass...", "source-file": "https://mysite.com", "violated-directive": "script-src 'self'" } }
  • 38. @BruntyCSP: Let’s Break Stuff report-uri.io
  • 40. @BruntyCSP: Let’s Break Stuff Report-only
  • 41. @BruntyCSP: Let’s Break Stuff Content-Security-Policy-Report-Only: [policy]; report- uri https://app.report-uri.io/r/default/csp/reportOnly;
  • 42. @BruntyCSP: Let’s Break Stuff Trial stuff before Enforcing
  • 43. @BruntyCSP: Let’s Break Stuff There will be noise, lots of noise
  • 44. @BruntyCSP: Let’s Break Stuff Ways to make dealing with a CSP easier Tips ▸ Have an easy and quick way to disable the CSP in production if required ▸ Better yet, have a way to switch it from enforced to report only so you can get violations reported to help you debug ▸ Add the CSP at an application level if you need a nonce
  • 45. @BruntyCSP: Let’s Break Stuff Ways to make dealing with a CSP easier Multiple policies ▸ They complicate things ▸ For a resource to be allowed, it must be allowed by all policies declared (problematic if an enforced policy) ▸ I tend to avoid them where possible on enforced policies ▸ But with report-only mode they can be very useful to deploy and test multiple policies at the same time (as nothing breaks for the user)
  • 46. @BruntyCSP: Let’s Break Stuff Ways to remove barriers in development Cryptographic nonces ▸ Don’t generate multiple nonces in the same request (but do generate a new nonce on each separate request) ▸ If using a templating engine (such as twig) - add the nonce as a global so it’s available in every template by default ▸ Write a helper in your template engine to generate script tags with a nonce if it’s available
  • 47. @BruntyCSP: Let’s Break Stuff The problem with CSPs and CMSs
  • 48. @BruntyCSP: Let’s Break Stuff Plugins
  • 49. @BruntyCSP: Let’s Break Stuff Inline scripts (without nonces) are the enemy
  • 50. @BruntyCSP: Let’s Break Stuff Stop building dodgy plugins, avoid inline scripts & eval Troy Hunt
  • 51. @BruntyCSP: Let’s Break Stuff [look at] making WordPress more CSP friendly Scott Helme
  • 52. @BruntyCSP: Let’s Break Stuff Inline scripts (without nonces) are the enemy
  • 53. @BruntyCSP: Let’s Break Stuff Demo time! Let’s break stuff
  • 54. @BruntyCSP: Let’s Break Stuff @scott_helme He knows his stuff!
  • 55. @BruntyCSP: Let’s Break Stuff @mr_goodwin He first introduced me to what a CSP is
  • 56. @BruntyCSP: Let’s Break Stuff Homework time! Links & further reading ▸ https://www.owasp.org/index.php/Cross-site_Scripting_(XSS) ▸ https://content-security-policy.com ▸ https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy ▸ https://report-uri.io ▸ https://scotthelme.co.uk/just-how-much-traffic-can-you-generate-using-csp/ ▸ https://www.edgescan.com/assets/docs/reports/2016-edgescan-stats-report.pdf ▸ http://theharmonyguy.com/oldsite/2011/04/21/recent-facebook-xss-attacks-show-increasing- sophistication/ ▸ https://github.com/Brunty/csp-demo
  • 57. @BruntyCSP: Let’s Break Stuff Thank you
  • 58. @BruntyCSP: Let’s Break Stuff Questions? @Brunty @PHPem mfyu.co.uk matt@mfyu.co.uk