SlideShare a Scribd company logo
2
Most read
4
Most read
7
Most read
Content Security Policy
(CSP)
What is it?
“Content Security Policy (CSP) is a computer security standard introduced to prevent
cross-site scripting (XSS), clickjacking and other code injection attacks resulting from
execution of malicious content in the trusted web page context. [...] CSP provides a
standard method for website owners to declare approved origins of content that browsers
should be allowed to load on that website—covered types are JavaScript, CSS, HTML
frames, web workers, fonts, images, embeddable objects such as Java applets, ActiveX,
audio and video files, and other HTML5 features.”
- https://en.wikipedia.org/wiki/Content_Security_Policy
How does it work?
Applied in the Content-Security-Policy HTTP header (more on HTTP headers).
With it, you can create a whitelist of trusted content sources.
Because CSP occurs on the HTTP headers, it can implement security early on.
What does it look like?
The Content-Security-Policy is defined in the HTTP headers and is provided with
directives and their respective sources.
HTTP Headers:
Response Headers
...
Content-Security-Policy: <directive> <source list>; <directive> <source list>;
...
Directives can list multiple sources.
What are directives?
Directives define the rules the browser must follow for various types of resources.
The main ones we will most often work with are:
default-src, script-src, style-src, img-src, font-src
But there’s plenty more...
base-uri, frame-src, object-src, media-src, connect-src, form-action,
frame-ancestors, child-src, plugin-types, upgrade-insecure-requests, worker-src,
sandbox
What are source lists?
Source lists are sets of strings which identify content that can be fetched and
potentially embedded or executed. For example, you may load styles from your site,
and fonts from Google.
Sources can follow various formats:
● example.com - Allows resources from the specified domain name.
● *.example.com - Allows resources from any subdomain under example.com.
● https://cdn.com - Only resources over HTTPS matching the given domain.
● https: - Allows loading resources only over HTTPS on any domain.
● data: - Allows resources via the data scheme (eg Base64 encoded images).
What is ‘self’ all about?
Special keywords can be used instead of URLs.
● *
● 'self'
● 'unsafe-inline'
● 'unsafe-eval'
● ‘strict-dynamic’
● 'none'
● 'nonce-'
● 'sha256-'
More on these here: https://content-security-policy.com/
How do I implement it?
● With the .htaccess file:
<IfModule mod_headers.c>
Header set Content-Security-Policy "default-src 'self'; ..."
</IfModule>
● With PHP (must happen before any other content):
header("Content-Security-Policy: default-src 'self'; ...");
● With a <meta> tag (not recommended):
<meta http-equiv="Content-Security-Policy" content="default-src ‘self’">
● With a plugin (yay!): HTTP Headers or WP Content Security Policy Plugin
Will it break anything?
Quite possibly, yes.
Luckily there is the Content-Security-Policy-Report-Only header.
Allows you to test your CSP without enforcing it.
Format is the same as the Content-Security-Policy header.
How can I test it?
Examine your HTTP headers in browser dev tools.
Observatory by Mozilla
csp-evaluator.withgoogle.com
Workshop Time…
Work on an “it’s ok if I break something” website please
Install WP Plugin: https://wordpress.org/plugins/wp-content-security-policy/
Disable any caching
Testing tool: https://observatory.mozilla.org/
The final verdict...
CSP is an optional added layer of security.
This comes at the cost of possibly breaking things, and making debugging more
difficult.
Most sites probably won’t see benefits outweigh the costs.
However, it could be a great fit for:
● Banks, government sites, or government-funded institutions.
● Larger organizations with security as a top priority.
● Organizations at higher risk of targeted attacks.
● Recently hacked websites.
Resources
Plugins:
WP Content Security Policy Plugin
HTTP Headers
Testing tools:
Observatory
csp-evaluator.withgoogle.com
Information:
content-security-policy.com
Google’s Web Fundamentals
Thanks!
Austin Gil
https://stegosource.com
austin@stegosource.com
@stegosource

More Related Content

PPT
Application Security
Reggie Niccolo Santos
 
PPTX
Content security policy
Ronan Dunne, CEH, SSCP
 
PDF
XSS Magic tricks
GarethHeyes
 
PDF
Preventing XSS with Content Security Policy
Ksenia Peguero
 
PDF
Http security response headers
mohammadhosseinrouha
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PDF
HTTP Security Headers
Ismael Goncalves
 
PDF
Building Advanced XSS Vectors
Rodolfo Assis (Brute)
 
Application Security
Reggie Niccolo Santos
 
Content security policy
Ronan Dunne, CEH, SSCP
 
XSS Magic tricks
GarethHeyes
 
Preventing XSS with Content Security Policy
Ksenia Peguero
 
Http security response headers
mohammadhosseinrouha
 
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
HTTP Security Headers
Ismael Goncalves
 
Building Advanced XSS Vectors
Rodolfo Assis (Brute)
 

What's hot (20)

PPTX
Cross site scripting
kinish kumar
 
PDF
Hacking Adobe Experience Manager sites
Mikhail Egorov
 
PPTX
Web development
Kanan Rahimov
 
PDF
W3C Content Security Policy
Markus Wichmann
 
PPTX
WAF ASM / Advance WAF - Brute force lior rotkovitch f5 sirt v5 clean
Lior Rotkovitch
 
PPTX
Vulnerabilities in modern web applications
Niyas Nazar
 
PPTX
Intro to WebSockets
Gaurav Oberoi
 
PPTX
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
PDF
Hunting for security bugs in AEM webapps
Mikhail Egorov
 
PPTX
Bug Bounty #Defconlucknow2016
Shubham Gupta
 
PPTX
Understanding Application Threat Modelling & Architecture
Priyanka Aash
 
PPTX
IdP, SAML, OAuth
Dan Brinkmann
 
PPT
Methods to Bypass a Web Application Firewall Eng
Dmitry Evteev
 
DOCX
Unit 1 XSS-- Document Object Model (DOM)
ChatanBawankar
 
PPTX
Hashicorp Vault Open Source vs Enterprise
Stenio Ferreira
 
PDF
OWASP Top 10 Web Application Vulnerabilities
Software Guru
 
PDF
Web Application Security and Awareness
Abdul Rahman Sherzad
 
PPTX
Attacking thru HTTP Host header
Sergey Belov
 
PPTX
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Svetlin Nakov
 
PDF
HTTP Parameter Pollution Vulnerabilities in Web Applications (Black Hat EU 2011)
Marco Balduzzi
 
Cross site scripting
kinish kumar
 
Hacking Adobe Experience Manager sites
Mikhail Egorov
 
Web development
Kanan Rahimov
 
W3C Content Security Policy
Markus Wichmann
 
WAF ASM / Advance WAF - Brute force lior rotkovitch f5 sirt v5 clean
Lior Rotkovitch
 
Vulnerabilities in modern web applications
Niyas Nazar
 
Intro to WebSockets
Gaurav Oberoi
 
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
Hunting for security bugs in AEM webapps
Mikhail Egorov
 
Bug Bounty #Defconlucknow2016
Shubham Gupta
 
Understanding Application Threat Modelling & Architecture
Priyanka Aash
 
IdP, SAML, OAuth
Dan Brinkmann
 
Methods to Bypass a Web Application Firewall Eng
Dmitry Evteev
 
Unit 1 XSS-- Document Object Model (DOM)
ChatanBawankar
 
Hashicorp Vault Open Source vs Enterprise
Stenio Ferreira
 
OWASP Top 10 Web Application Vulnerabilities
Software Guru
 
Web Application Security and Awareness
Abdul Rahman Sherzad
 
Attacking thru HTTP Host header
Sergey Belov
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Svetlin Nakov
 
HTTP Parameter Pollution Vulnerabilities in Web Applications (Black Hat EU 2011)
Marco Balduzzi
 
Ad

Similar to Content Security Policy (20)

PDF
Content Security Policy (CSP)
Arun Kumar
 
PDF
Content Security Policy - Lessons learned at Yahoo
Binu Ramakrishnan
 
PDF
Csp and http headers
ColdFusionConference
 
PDF
Csp and http headers
devObjective
 
PDF
Web Security - CSP & Web Cryptography
Samsung Open Source Group
 
PDF
[Cluj] CSP (Content Security Policy)
OWASP EEE
 
PPTX
AppSec USA 2016: Demystifying CSP
Eli Nesterov
 
PDF
AppSec California 2017 CSP: The Good, the Bad and the Ugly
Eli Nesterov
 
PDF
Rails and Content Security Policies
Matias Korhonen
 
PDF
Defeating Cross-Site Scripting with Content Security Policy (updated)
Francois Marier
 
PPTX
Content Security Policy ByPass
PawanJaiswal39
 
PDF
Secure coding guidelines for content security policy
vivekanandan r
 
PDF
Content Security Policies: A whole new way of securing your website that no o...
Miriam Schwab
 
PDF
Content Security Policies: A whole new way of securing your website that no o...
Miriam Schwab
 
PDF
Rails security: above and beyond the defaults
Matias Korhonen
 
PPTX
Web content security policies
Dhanu Gupta
 
PDF
Introduction: Content Security Policy (CSP) - ゼロから始めるセキュリティ勉強会 #14
Takashi Yoneuchi
 
PDF
Defeating Cross-Site Scripting with Content Security Policy
Francois Marier
 
PDF
Breaking Bad CSP
Lukas Weichselbaum
 
Content Security Policy (CSP)
Arun Kumar
 
Content Security Policy - Lessons learned at Yahoo
Binu Ramakrishnan
 
Csp and http headers
ColdFusionConference
 
Csp and http headers
devObjective
 
Web Security - CSP & Web Cryptography
Samsung Open Source Group
 
[Cluj] CSP (Content Security Policy)
OWASP EEE
 
AppSec USA 2016: Demystifying CSP
Eli Nesterov
 
AppSec California 2017 CSP: The Good, the Bad and the Ugly
Eli Nesterov
 
Rails and Content Security Policies
Matias Korhonen
 
Defeating Cross-Site Scripting with Content Security Policy (updated)
Francois Marier
 
Content Security Policy ByPass
PawanJaiswal39
 
Secure coding guidelines for content security policy
vivekanandan r
 
Content Security Policies: A whole new way of securing your website that no o...
Miriam Schwab
 
Content Security Policies: A whole new way of securing your website that no o...
Miriam Schwab
 
Rails security: above and beyond the defaults
Matias Korhonen
 
Web content security policies
Dhanu Gupta
 
Introduction: Content Security Policy (CSP) - ゼロから始めるセキュリティ勉強会 #14
Takashi Yoneuchi
 
Defeating Cross-Site Scripting with Content Security Policy
Francois Marier
 
Breaking Bad CSP
Lukas Weichselbaum
 
Ad

More from Austin Gil (8)

PDF
What I like about vue
Austin Gil
 
PDF
Functional Components in Vue.js
Austin Gil
 
PPTX
Enterprise level application in 5 min
Austin Gil
 
PPTX
Developing word press professionally
Austin Gil
 
PPTX
A holistic approach to web performance
Austin Gil
 
PPTX
Web Performance: 3 Stages to Success
Austin Gil
 
PDF
Improve WordPress load times with a CDN
Austin Gil
 
PPTX
Isotope, WP REST API, and AJAX...Oh my!
Austin Gil
 
What I like about vue
Austin Gil
 
Functional Components in Vue.js
Austin Gil
 
Enterprise level application in 5 min
Austin Gil
 
Developing word press professionally
Austin Gil
 
A holistic approach to web performance
Austin Gil
 
Web Performance: 3 Stages to Success
Austin Gil
 
Improve WordPress load times with a CDN
Austin Gil
 
Isotope, WP REST API, and AJAX...Oh my!
Austin Gil
 

Recently uploaded (20)

PPTX
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
PPTX
Parallel & Concurrent ...
yashpavasiya892
 
PPTX
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
PPTX
SEO Trends in 2025 | B3AITS - Bow & 3 Arrows IT Solutions
B3AITS - Bow & 3 Arrows IT Solutions
 
PDF
Project English Paja Jara Alejandro.jpdf
AlejandroAlonsoPajaJ
 
PDF
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
PDF
Cybersecurity Awareness Presentation ppt.
banodhaharshita
 
PPTX
EthicalHack{aksdladlsfsamnookfmnakoasjd}.pptx
dagarabull
 
PPTX
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
PDF
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PPTX
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
PPTX
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
PPTX
Generics jehfkhkshfhskjghkshhhhlshluhueheuhuhhlhkhk.pptx
yashpavasiya892
 
PPTX
Perkembangan Perangkat jaringan komputer dan telekomunikasi 3.pptx
Prayudha3
 
PPTX
Slides Powerpoint: Eco Economic Epochs.pptx
Steven McGee
 
PDF
LB# 820-1889_051-7370_C000.schematic.pdf
matheusalbuquerqueco3
 
PPTX
dns domain name system history work.pptx
MUHAMMADKAVISHSHABAN
 
PPTX
谢尔丹学院毕业证购买|Sheridan文凭不见了怎么办谢尔丹学院成绩单
mookxk3
 
PPTX
原版北不列颠哥伦比亚大学毕业证文凭UNBC成绩单2025年新版在线制作学位证书
e7nw4o4
 
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
Parallel & Concurrent ...
yashpavasiya892
 
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
SEO Trends in 2025 | B3AITS - Bow & 3 Arrows IT Solutions
B3AITS - Bow & 3 Arrows IT Solutions
 
Project English Paja Jara Alejandro.jpdf
AlejandroAlonsoPajaJ
 
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
Cybersecurity Awareness Presentation ppt.
banodhaharshita
 
EthicalHack{aksdladlsfsamnookfmnakoasjd}.pptx
dagarabull
 
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
Generics jehfkhkshfhskjghkshhhhlshluhueheuhuhhlhkhk.pptx
yashpavasiya892
 
Perkembangan Perangkat jaringan komputer dan telekomunikasi 3.pptx
Prayudha3
 
Slides Powerpoint: Eco Economic Epochs.pptx
Steven McGee
 
LB# 820-1889_051-7370_C000.schematic.pdf
matheusalbuquerqueco3
 
dns domain name system history work.pptx
MUHAMMADKAVISHSHABAN
 
谢尔丹学院毕业证购买|Sheridan文凭不见了怎么办谢尔丹学院成绩单
mookxk3
 
原版北不列颠哥伦比亚大学毕业证文凭UNBC成绩单2025年新版在线制作学位证书
e7nw4o4
 

Content Security Policy

  • 2. What is it? “Content Security Policy (CSP) is a computer security standard introduced to prevent cross-site scripting (XSS), clickjacking and other code injection attacks resulting from execution of malicious content in the trusted web page context. [...] CSP provides a standard method for website owners to declare approved origins of content that browsers should be allowed to load on that website—covered types are JavaScript, CSS, HTML frames, web workers, fonts, images, embeddable objects such as Java applets, ActiveX, audio and video files, and other HTML5 features.” - https://en.wikipedia.org/wiki/Content_Security_Policy
  • 3. How does it work? Applied in the Content-Security-Policy HTTP header (more on HTTP headers). With it, you can create a whitelist of trusted content sources. Because CSP occurs on the HTTP headers, it can implement security early on.
  • 4. What does it look like? The Content-Security-Policy is defined in the HTTP headers and is provided with directives and their respective sources. HTTP Headers: Response Headers ... Content-Security-Policy: <directive> <source list>; <directive> <source list>; ... Directives can list multiple sources.
  • 5. What are directives? Directives define the rules the browser must follow for various types of resources. The main ones we will most often work with are: default-src, script-src, style-src, img-src, font-src But there’s plenty more... base-uri, frame-src, object-src, media-src, connect-src, form-action, frame-ancestors, child-src, plugin-types, upgrade-insecure-requests, worker-src, sandbox
  • 6. What are source lists? Source lists are sets of strings which identify content that can be fetched and potentially embedded or executed. For example, you may load styles from your site, and fonts from Google. Sources can follow various formats: ● example.com - Allows resources from the specified domain name. ● *.example.com - Allows resources from any subdomain under example.com. ● https://cdn.com - Only resources over HTTPS matching the given domain. ● https: - Allows loading resources only over HTTPS on any domain. ● data: - Allows resources via the data scheme (eg Base64 encoded images).
  • 7. What is ‘self’ all about? Special keywords can be used instead of URLs. ● * ● 'self' ● 'unsafe-inline' ● 'unsafe-eval' ● ‘strict-dynamic’ ● 'none' ● 'nonce-' ● 'sha256-' More on these here: https://content-security-policy.com/
  • 8. How do I implement it? ● With the .htaccess file: <IfModule mod_headers.c> Header set Content-Security-Policy "default-src 'self'; ..." </IfModule> ● With PHP (must happen before any other content): header("Content-Security-Policy: default-src 'self'; ..."); ● With a <meta> tag (not recommended): <meta http-equiv="Content-Security-Policy" content="default-src ‘self’"> ● With a plugin (yay!): HTTP Headers or WP Content Security Policy Plugin
  • 9. Will it break anything? Quite possibly, yes. Luckily there is the Content-Security-Policy-Report-Only header. Allows you to test your CSP without enforcing it. Format is the same as the Content-Security-Policy header.
  • 10. How can I test it? Examine your HTTP headers in browser dev tools. Observatory by Mozilla csp-evaluator.withgoogle.com
  • 11. Workshop Time… Work on an “it’s ok if I break something” website please Install WP Plugin: https://wordpress.org/plugins/wp-content-security-policy/ Disable any caching Testing tool: https://observatory.mozilla.org/
  • 12. The final verdict... CSP is an optional added layer of security. This comes at the cost of possibly breaking things, and making debugging more difficult. Most sites probably won’t see benefits outweigh the costs. However, it could be a great fit for: ● Banks, government sites, or government-funded institutions. ● Larger organizations with security as a top priority. ● Organizations at higher risk of targeted attacks. ● Recently hacked websites.
  • 13. Resources Plugins: WP Content Security Policy Plugin HTTP Headers Testing tools: Observatory csp-evaluator.withgoogle.com Information: content-security-policy.com Google’s Web Fundamentals