SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
@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

(that group in orange hoodies at some conferences &
events)
▸ @Brunty
▸ @PHPem
▸ mfyu.co.uk
▸ matt@mfyu.co.uk
@BruntyCSP: Let’s Break Stuff
BECAUSE YOU ALL TOTALLY CARE ABOUT THIS, RIGHT?!
THINGS I DO
▸ Dungeon master for D&D campaigns with friends
▸ Mentor, lead & teach apprentices and 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
WHY DO WE NEED
A CSP?
@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
FIRST, SOME BACKGROUND
WHAT CAN BE DONE WITH XSS?
▸ Things a site owner can do in JS can be done in an XSS
attack
▸ Make modifications to the DOM (you could replace an
entire page and control data going in/out)
▸ Use XMLHttpRequest to send HTTP requests
▸ Access HTML5 APIs - webcam, microphone, geolocation
▸ Steal cookies (and therefore steal session cookies)
@BruntyCSP: Let’s Break Stuff
@BruntyCSP: Let’s Break Stuff
FIRST, SOME BACKGROUND
WELL KNOWN XSS ATTACKS
▸ Twitter self-retweeting tweet

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

https://en.wikipedia.org/wiki/Samy_(computer_worm)
▸ Facebook XSS attacks

http://theharmonyguy.com/oldsite/2011/04/21/recent-facebook-xss-attacks-show-increasing-
sophistication/
▸ And so many more…
@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
@BruntyCSP: Let’s Break Stuff
console.log("%cStop!", "font: 5em sans-serif; font-weight: bold; color: red;");
@BruntyCSP: Let’s Break Stuff
STOP THE HACKERS
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
DECLARES WHAT RESOURCES
ARE ALLOWED TO LOAD
HOW DOES A CSP WORK?
@BruntyCSP: Let’s Break Stuff
WHAT CAN WE
PROTECT?
@BruntyCSP: Let’s Break Stuff
DEFAULT-SRC
@BruntyCSP: Let’s Break Stuff
SCRIPT-SRC
@BruntyCSP: Let’s Break Stuff
STYLE-SRC
@BruntyCSP: Let’s Break Stuff
UPGRADE-
INSECURE-REQUESTS
@BruntyCSP: Let’s Break Stuff
FORM-ACTION
@BruntyCSP: Let’s Break Stuff
WORKER-SRC

BASE-URI

PLUGIN-TYPES

SANDBOX

FRAME-ANCESTORS

CONNECT-SRC

CHILD-SRC

AND MANY MORE…
@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
A FEW EXAMPLES
OF DIRECTIVES
@BruntyCSP: Let’s Break Stuff
IMG-SRC *
WILDCARD, 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 ORIGIN (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-
pahsbdlensudsmslnaf7adn'; style-src ‘self'; img-src:
'self'; upgrade-insecure-requests; form-action ‘http://
mysite.com'; report-uri https://mfyu.report-uri.io/r/
default/csp/reportOnly;
@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
IMPLEMENTATION
ADVICE
@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
REPORT-ONLY
@BruntyCSP: Let’s Break Stuff
Content-Security-Policy-Report-Only: script-src 'self'
https://*.google.com; style-src 'self'; report-uri
https://mfyu.report-uri.io/r/default/csp/reportOnly;
@BruntyCSP: Let’s Break Stuff
USE REPORT-ONLY
@BruntyCSP: Let’s Break Stuff
TRIAL STUFF
BEFORE ENFORCING
@BruntyCSP: Let’s Break Stuff
LOVE REPORT-ONLY
@BruntyCSP: Let’s Break Stuff
BUT THERE WILL BE
NOISE, LOTS OF NOISE
@BruntyCSP: Let’s Break Stuff
HATE REPORT-ONLY
@BruntyCSP: Let’s Break Stuff
WAYS TO REMOVE BARRIERS IN DEVELOPMENT
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 to generate tags with a nonce if it’s
available
@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 -
be careful with doing it at a vhost config level (as changes
require web server config reload)
@BruntyCSP: Let’s Break Stuff
BROWSER
SUPPORT
@BruntyCSP: Let’s Break Stuff
@BruntyCSP: Let’s Break Stuff
DEMO
@BruntyCSP: Let’s Break Stuff
@SCOTT_HELME
(HE KNOWS HIS STUFF!)
(THIS ISN’T ME)
@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://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://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
▸ https://github.com/Brunty/csp-demo
@BruntyCSP: Let’s Break Stuff
THANK YOU
@BruntyCSP: Let’s Break Stuff
HTTPS://JOIND.IN/TALK/E45C8
@BruntyCSP: Let’s Break Stuff
QUESTIONS?
@BRUNTY
@PHPEM
MFYU.CO.UK
MATT@MFYU.CO.UK

Más contenido relacionado

Similar a Content Security Policies: Let's Break Stuff @ PHP South Coast 2017

Programming for non-programmers
Programming for non-programmersProgramming for non-programmers
Programming for non-programmers
Pancho Goldaracena
 
Browser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security PolicyBrowser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security Policy
George Boobyer
 
Building a Modern Security Engineering Organization. Zane Lackey
 Building a Modern Security Engineering Organization. Zane Lackey Building a Modern Security Engineering Organization. Zane Lackey
Building a Modern Security Engineering Organization. Zane Lackey
Yandex
 

Similar a Content Security Policies: Let's Break Stuff @ PHP South Coast 2017 (20)

DrupalCamp London 2017 - Web site insecurity
DrupalCamp London 2017 - Web site insecurity DrupalCamp London 2017 - Web site insecurity
DrupalCamp London 2017 - Web site insecurity
 
Prototyping: Helping to take away the suck
Prototyping: Helping to take away the suckPrototyping: Helping to take away the suck
Prototyping: Helping to take away the suck
 
Smart mobile storytelling christy robinson - denver news train - april 11-1...
Smart mobile storytelling   christy robinson - denver news train - april 11-1...Smart mobile storytelling   christy robinson - denver news train - april 11-1...
Smart mobile storytelling christy robinson - denver news train - april 11-1...
 
Building Better Responsive Websites
Building Better Responsive WebsitesBuilding Better Responsive Websites
Building Better Responsive Websites
 
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
 
Skynet vs planet of apes
Skynet vs planet of apesSkynet vs planet of apes
Skynet vs planet of apes
 
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
 
Christopher Guess presents Push
Christopher Guess presents PushChristopher Guess presents Push
Christopher Guess presents Push
 
Content wants to be free (from projects) - J.boye Aarhus 2015
Content wants to be free (from projects) - J.boye Aarhus 2015Content wants to be free (from projects) - J.boye Aarhus 2015
Content wants to be free (from projects) - J.boye Aarhus 2015
 
Enhance system transparency and truthfulness with request tracing
Enhance system transparency and truthfulness with request tracingEnhance system transparency and truthfulness with request tracing
Enhance system transparency and truthfulness with request tracing
 
Happy Browser, Happy User! WordSesh 2019
Happy Browser, Happy User! WordSesh 2019Happy Browser, Happy User! WordSesh 2019
Happy Browser, Happy User! WordSesh 2019
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header Security
 
DVC202_The Open Guide to AWS
DVC202_The Open Guide to AWSDVC202_The Open Guide to AWS
DVC202_The Open Guide to AWS
 
Programming for non-programmers
Programming for non-programmersProgramming for non-programmers
Programming for non-programmers
 
Beyond Mirai: The new age of MDDoS attacks
Beyond Mirai: The new age of MDDoS attacksBeyond Mirai: The new age of MDDoS attacks
Beyond Mirai: The new age of MDDoS attacks
 
Browser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security PolicyBrowser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security Policy
 
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
 
Building a Modern Security Engineering Organization. Zane Lackey
 Building a Modern Security Engineering Organization. Zane Lackey Building a Modern Security Engineering Organization. Zane Lackey
Building a Modern Security Engineering Organization. Zane Lackey
 
20160816 amlight popbahia_rnp_ansp
20160816 amlight popbahia_rnp_ansp20160816 amlight popbahia_rnp_ansp
20160816 amlight popbahia_rnp_ansp
 

Más de Matt Brunt

Más de 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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Content Security Policies: Let's Break Stuff @ PHP South Coast 2017

  • 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
 (that group in orange hoodies at some conferences & events) ▸ @Brunty ▸ @PHPem ▸ mfyu.co.uk ▸ matt@mfyu.co.uk
  • 3. @BruntyCSP: Let’s Break Stuff BECAUSE YOU ALL TOTALLY CARE ABOUT THIS, RIGHT?! THINGS I DO ▸ Dungeon master for D&D campaigns with friends ▸ Mentor, lead & teach apprentices and 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 WHY DO WE NEED A CSP?
  • 5. @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
  • 6. @BruntyCSP: Let’s Break Stuff FIRST, SOME BACKGROUND WHAT CAN BE DONE WITH XSS? ▸ Things a site owner can do in JS can be done in an XSS attack ▸ Make modifications to the DOM (you could replace an entire page and control data going in/out) ▸ Use XMLHttpRequest to send HTTP requests ▸ Access HTML5 APIs - webcam, microphone, geolocation ▸ Steal cookies (and therefore steal session cookies)
  • 8. @BruntyCSP: Let’s Break Stuff FIRST, SOME BACKGROUND WELL KNOWN XSS ATTACKS ▸ Twitter self-retweeting tweet
 https://www.youtube.com/watch?v=zv0kZKC6GAM ▸ Samy worm
 https://en.wikipedia.org/wiki/Samy_(computer_worm) ▸ Facebook XSS attacks
 http://theharmonyguy.com/oldsite/2011/04/21/recent-facebook-xss-attacks-show-increasing- sophistication/ ▸ And so many more…
  • 9. @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)
  • 10. @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)
  • 11. @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
  • 12. @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
  • 14. @BruntyCSP: Let’s Break Stuff console.log("%cStop!", "font: 5em sans-serif; font-weight: bold; color: red;");
  • 15. @BruntyCSP: Let’s Break Stuff STOP THE HACKERS LET’S FIGHT BACK
  • 16. @BruntyCSP: Let’s Break Stuff HTTP RESPONSE HEADER TO HELP REDUCE XSS RISKS WHAT IS A CSP?
  • 17. @BruntyCSP: Let’s Break Stuff DECLARES WHAT RESOURCES ARE ALLOWED TO LOAD HOW DOES A CSP WORK?
  • 18. @BruntyCSP: Let’s Break Stuff WHAT CAN WE PROTECT?
  • 19. @BruntyCSP: Let’s Break Stuff DEFAULT-SRC
  • 20. @BruntyCSP: Let’s Break Stuff SCRIPT-SRC
  • 21. @BruntyCSP: Let’s Break Stuff STYLE-SRC
  • 22. @BruntyCSP: Let’s Break Stuff UPGRADE- INSECURE-REQUESTS
  • 23. @BruntyCSP: Let’s Break Stuff FORM-ACTION
  • 24. @BruntyCSP: Let’s Break Stuff WORKER-SRC
 BASE-URI
 PLUGIN-TYPES
 SANDBOX
 FRAME-ANCESTORS
 CONNECT-SRC
 CHILD-SRC
 AND MANY MORE…
  • 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 A FEW EXAMPLES OF DIRECTIVES
  • 27. @BruntyCSP: Let’s Break Stuff IMG-SRC * WILDCARD, ALLOWS ANY URL EXCEPT DATA: BLOB: FILESYSTEM: SCHEMES.
  • 28. @BruntyCSP: Let’s Break Stuff OBJECT-SRC 'NONE' DON’T LOAD RESOURCES FROM ANY SOURCE
  • 29. @BruntyCSP: Let’s Break Stuff STYLE-SRC ‘SELF' ALLOW LOADING FROM SAME ORIGIN (SAME SCHEME, HOST AND PORT)
  • 30. @BruntyCSP: Let’s Break Stuff SCRIPT-SRC 'UNSAFE-INLINE' ALLOWS USE OF INLINE SOURCE ELEMENTS SUCH AS STYLE ATTRIBUTE, ONCLICK, OR SCRIPT TAG BODIES
  • 31. @BruntyCSP: Let’s Break Stuff DON’T USE UNSAFE-INLINE
  • 32. @BruntyCSP: Let’s Break Stuff <script nonce="$RANDOM">...</script> script-src 'self' 'nonce-$RANDOM'
  • 33. @BruntyCSP: Let’s Break Stuff Content-Security-Policy: default-src: 'none'; script-src 'self' https://*.google.com 'nonce- pahsbdlensudsmslnaf7adn'; style-src ‘self'; img-src: 'self'; upgrade-insecure-requests; form-action ‘http:// mysite.com'; report-uri https://mfyu.report-uri.io/r/ default/csp/reportOnly;
  • 34. @BruntyCSP: Let’s Break Stuff I BROKE PRODUCTION WITH A BAD CSP LEARN FROM MY MISTAKES
  • 35. @BruntyCSP: Let’s Break Stuff DON’T DO WHAT I DID
  • 36. @BruntyCSP: Let’s Break Stuff IMPLEMENTATION ADVICE
  • 37. @BruntyCSP: Let’s Break Stuff REPORT-URI
  • 38. @BruntyCSP: Let’s Break Stuff WHEN A POLICY FAILURE OCCURS, THE BROWSER SENDS A JSON PAYLOAD TO THAT URL
  • 39. @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'" } }
  • 40. @BruntyCSP: Let’s Break Stuff REPORT-URI.IO
  • 41. @BruntyCSP: Let’s Break Stuff REPORT-ONLY
  • 42. @BruntyCSP: Let’s Break Stuff Content-Security-Policy-Report-Only: script-src 'self' https://*.google.com; style-src 'self'; report-uri https://mfyu.report-uri.io/r/default/csp/reportOnly;
  • 43. @BruntyCSP: Let’s Break Stuff USE REPORT-ONLY
  • 44. @BruntyCSP: Let’s Break Stuff TRIAL STUFF BEFORE ENFORCING
  • 45. @BruntyCSP: Let’s Break Stuff LOVE REPORT-ONLY
  • 46. @BruntyCSP: Let’s Break Stuff BUT THERE WILL BE NOISE, LOTS OF NOISE
  • 47. @BruntyCSP: Let’s Break Stuff HATE REPORT-ONLY
  • 48. @BruntyCSP: Let’s Break Stuff WAYS TO REMOVE BARRIERS IN DEVELOPMENT 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 to generate tags with a nonce if it’s available
  • 49. @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 - be careful with doing it at a vhost config level (as changes require web server config reload)
  • 50. @BruntyCSP: Let’s Break Stuff BROWSER SUPPORT
  • 53. @BruntyCSP: Let’s Break Stuff @SCOTT_HELME (HE KNOWS HIS STUFF!) (THIS ISN’T ME)
  • 54. @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://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://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy ▸ https://github.com/Brunty/csp-demo
  • 55. @BruntyCSP: Let’s Break Stuff THANK YOU
  • 56. @BruntyCSP: Let’s Break Stuff HTTPS://JOIND.IN/TALK/E45C8
  • 57. @BruntyCSP: Let’s Break Stuff QUESTIONS? @BRUNTY @PHPEM MFYU.CO.UK MATT@MFYU.CO.UK