SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
Ruby Brigade 10/2016
Rails and Content Security Policies
Who am I?
• A developer at Kisko Labs
• In my free 8me I work on too many side projects
• piranhas.co — a book price comparison site and app
• Beer Styles — an iOS app for browsing beer style guidelines
• TLS.caresoon!
— an SSL/TLS cer8ficate monitoring service
• and I also brew beer
Kisko Labs
We build and launch tools on the web
Are you a Ruby or frontend developer? We're hiring
CSPContent Security Policy
Content Security Policy is an added
layer of security that helps to detect
and mi3gate certain types of
a5acks, including Cross Site
Scrip3ng (XSS) and data injec3on
a5acks.
— MDN
Content Security Policy: a header
which tells the browser where
resources (scripts, stylesheets, fonts,
etc) can be loaded from.
— Me
Supported by all major browsers,
even Internet Explorer (kind of)
CSP: Why?
• Reduces the poten.al surface area for a3acks or malicious
injec.on of scripts
• Prevents malicious browser extensions and malware from
inser.ng crap into your pages.
• For example, the CSP on Piranhas.co has stopped some shady
browser extensions from injec.ng ads?
onto the page.
https://static.cmptch.com
I don't know what this is, but I know that I don't want it on my site!
CSP Direc*ves
Content Security Policies allow quite fine grained control over what
can be loaded from where.
For example, you can allow scripts from a domain but not images
(or vice versa).
Or, for example, if you allow users to upload images, but not
scripts, you can segregate user uploads to a specific host (“allow
images from uploads.example.com but nothing else”).
Available direc,ves
• default-src: Define loading policy for all resources type in case of
a resource type dedicated direc5ve is not defined (fallback),
• script-src: Define which scripts the protected resource can
execute,
• object-src: Define from where the protected resource can load
plugins,
• style-src: Define which styles (CSS) the user applies to the
protected resource,
• img-src: Define from where the protected resource can load
images,
• media-src: Define from where the protected resource can load
video and audio,
• frame-src: Define from where the protected resource can embed
frames,
• font-src: Define from where the protected resource can load
fonts,
• connect-src: Define which URIs the protected resource can load
using script interfaces,
• form-ac-on: Define which URIs can be used as the ac;on of
HTML form elements,
• sandbox: Specifies an HTML sandbox policy that the user agent
applies to the protected resource,
• script-nonce: Define script execu;on by requiring the presence
of the specified nonce on script elements,
• plugin-types: Define the set of plugins that can be invoked by
the protected resource by limi:ng the types of resources that
can be embedded,
• reflected-xss: Instructs a user agent to ac:vate or deac:vate any
heuris:cs used to filter or block reflected cross-site scrip:ng
a?acks, equivalent to the effects of the non-standard X-XSS-
Protec:on header,
• report-uri: Specifies a URI to which the user agent sends reports
about policy viola:on
Adding a CSP header to a long
standing site can be … tricky
CSP example (piranhas.co)
Content-Security-Policy:
default-src https:;
style-src 'unsafe-inline'
https://cdn.piranhas.xyz
https://fonts.googleapis.com;
script-src 'unsafe-inline' 'unsafe-eval'
https://cdn.piranhas.xyz
https://www.google-analytics.com
https://suggestqueries.google.com
https://www.googleapis.com;
img-src data: https:;
report-uri https://x.report-uri.io/r/default/csp/enforce;
(line breaks added for clarity…)
Adding it from the very beginning is
a lot easier…
CSP example (simplified)
Content-Security-Policy: default-src *;
Allow all sources, but disallow unsafe inline assets (for example
scripts and styles).
CSP example (simplified alterna3ve)
Content-Security-Policy: default-src 'self';
Allow all sources, but disallow unsafe inline assets (for example
scripts and styles).
'unsafe-inline' vs “safe inline”
• By default inline scripts are blocked
• You can either
• add 'unsafe-inline' to your CSP (in which case you're
back where your started)
• or use inline scripts with a nonce (more on this later)
In cryptography, a nonce is an
arbitrary number that may only be
used once.
— Wikipedia
You specify the nonce in the CSP header:
Content-Security-Policy: ...
script-src 'nonce-/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=' ...;
and in your <script> (or <style>) tag:
<script nonce="/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=">
console.log("Hello World")
</script>
The browser will allow each nonce to be used only once…
Secure Headers
Secure Headers
A Rack middleware gem from Twi2er which adds support for more
security headers than are available by default in Rails.
• h#ps://github.com/twi#er/secureheaders
• h#ps://rubygems.org/gems/secure_headers
Makes it easier to use CSP headers (and it also handles other
security headers)
Secure Headers
It lets you define an app-wide CSP that you can override or append
to at a controller or ac9on level.
Don't just add it though. Look through the configura6on and
understand what it's doing. You might want to disable some of the
op6ons.
Secure Headers
It's a pre*y extensive library, so read the README to learn more.
Secure Headers: nonces
It also includes support for safe inline styles and scripts using
nonces.
For example:
<%= nonced_javascript_tag do %>
console.log("nonced!");
<% end %>
Secure Headers: nonces
Generates this HTML:
<script nonce="/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=">
console.log("nonced!")
</script>
And adds this to the CSP header:
Content-Security-Policy: ...
script-src 'nonce-/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=' ...;
Secure Headers: minimal configura3on
# config/initializers/secure_headers.rb
SecureHeaders::Configuration.default do |config|
config.csp = {
default_src: %w(*),
upgrade_insecure_requests: Rails.env.production?, # see https://www.w3.org/TR/upgrade-insecure-requests/
report_uri: %w(https://x.report-uri.io/r/default/csp/enforce)
}
config.hpkp = SecureHeaders::OPT_OUT
end
Or you might want to use 'self' instead of *
Secure Headers
Rails also sets some of the same security headers, but Secure
Headers has code to override those with its own configura;on.
=> Secure Headers knows how to play nice with Rails
=> Secure Headers knows how to play nice with Rails
isolate_namespace SecureHeaders if defined? isolate_namespace # rails 3.0
conflicting_headers = ['X-Frame-Options', 'X-XSS-Protection',
'X-Permitted-Cross-Domain-Policies', 'X-Download-Options',
'X-Content-Type-Options', 'Strict-Transport-Security',
'Content-Security-Policy', 'Content-Security-Policy-Report-Only',
'Public-Key-Pins', 'Public-Key-Pins-Report-Only', 'Referrer-Policy']
# ...
conflicting_headers.each do |header|
Rails.application.config.action_dispatch.default_headers.delete(header)
end
h"ps://github.com/twi"er/secureheaders/blob/v3.4.1/lib/
secure_headers/rail;e.rb
CSP pro-)ps
CSP pro-)ps
Start by using the Content-Security-Policy-Report-Only
header to test and tweak your CSP header in the wild.
Content-Security-Policy-Report-Only:
default-src *,
report-uri https://x.report-uri.io/r/default/csp/enforce;;
Deploy the Report Only header for a few days before star1ng to
enforce it.
CSP pro-)ps
• New projects
• Enforce the CSP from the beginning
• Report viola<ons from your staging or produc<on environment
• Old projects
• Add a CSP with all the sources you think you need
• Deploy it as Report Only, leave it for a week or two to uncover anything you might have forgoEen
about
• Deploy the enforced policy once you've accounted for all the viola<ons
• Both
• When making changes, you may wish to first test them with the Report Only header (depending on the
change)
CSP resources
• h#ps://sco#helme.co.uk/content-security-policy-an-
introduc8on/
• h#ps://report-uri.io
• h#ps://developer.mozilla.org/en-US/docs/Web/Security/CSP/
Using_Content_Security_Policy
CSP resources
• h#ps://github.com/twi#er/secureheaders
• h#ps://security.googleblog.com/2016/09/reshaping-web-
defenses-with-strict.html
• CSP Evaluator: h#ps://csp-evaluator.withgoogle.com/
• CSP MiGgator: h#ps://chrome.google.com/webstore/detail/
csp-miGgator/gijlobangojajlbodabkpjpheeeokhfa
Summary
Summary
• Rails defaults are pre/y good, but can be (fairly easily) be 9ghtened
• Use a Content Security Policy, if only to prevent ad/malware injec9on by
compromised browsers
• The more strict the CSP is, the fewer chances there are for third par9es to mess
with your site
• Use the Secure Headers gem to manage the CSP policy and other security headers
• It requires more thought than the Rails defaults, but I think it's worth it
• Excep&on to all of the above: If you're working on your first Rails app, you
probably shouldn't add this complexity.
Thanks
Ma#as Korhonen
@ma$askorhonen
ma#askorhonen.fi
piranhas.co
Beer Styles
TLS.caresoon!

Más contenido relacionado

La actualidad más candente

Apache mod security 3.1
Apache mod security   3.1Apache mod security   3.1
Apache mod security 3.1Hai Dinh Tuan
 
Analysis of HTTP Security Headers in Turkey
Analysis of HTTP Security Headers in TurkeyAnalysis of HTTP Security Headers in Turkey
Analysis of HTTP Security Headers in TurkeyDr. Emin İslam Tatlı
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 Philippe Gamache
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesSpin Lai
 
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ -  Automated Malware AnalysisIstSec'14 - İbrahim BALİÇ -  Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ - Automated Malware AnalysisBGA Cyber Security
 
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...OWASP Russia
 
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]RootedCON
 
Security and Privacy on the Web in 2015
Security and Privacy on the Web in 2015Security and Privacy on the Web in 2015
Security and Privacy on the Web in 2015Francois Marier
 
Java ist doch schon sicher?!
Java ist doch schon sicher?!Java ist doch schon sicher?!
Java ist doch schon sicher?!BridgingIT GmbH
 
So you want to be a security expert
So you want to be a security expertSo you want to be a security expert
So you want to be a security expertRoyce Davis
 
QA: Базовое тестирование защищенности веб-приложений в рамках QA
QA: Базовое тестирование защищенности веб-приложений в рамках QAQA: Базовое тестирование защищенности веб-приложений в рамках QA
QA: Базовое тестирование защищенности веб-приложений в рамках QACodeFest
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...Felipe Prado
 
Hardening cassandra q2_2016
Hardening cassandra q2_2016Hardening cassandra q2_2016
Hardening cassandra q2_2016zznate
 
Secret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s VaultSecret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s VaultAWS Germany
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultJeff Horwitz
 
Securing Cassandra The Right Way
Securing Cassandra The Right WaySecuring Cassandra The Right Way
Securing Cassandra The Right WayDataStax Academy
 
Web Uygulama Güvenliği (Akademik Bilişim 2016)
Web Uygulama Güvenliği (Akademik Bilişim 2016)Web Uygulama Güvenliği (Akademik Bilişim 2016)
Web Uygulama Güvenliği (Akademik Bilişim 2016)Ömer Çıtak
 
Cassandra and security
Cassandra and securityCassandra and security
Cassandra and securityBen Bromhead
 
Red Team vs Blue Team on AWS - RSA 2018
Red Team vs Blue Team on AWS - RSA 2018Red Team vs Blue Team on AWS - RSA 2018
Red Team vs Blue Team on AWS - RSA 2018Teri Radichel
 

La actualidad más candente (20)

Apache mod security 3.1
Apache mod security   3.1Apache mod security   3.1
Apache mod security 3.1
 
Analysis of HTTP Security Headers in Turkey
Analysis of HTTP Security Headers in TurkeyAnalysis of HTTP Security Headers in Turkey
Analysis of HTTP Security Headers in Turkey
 
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017 OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
OWASP Top 10 Proactive Controls 2016 - NorthEast PHP 2017
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best Practices
 
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ -  Automated Malware AnalysisIstSec'14 - İbrahim BALİÇ -  Automated Malware Analysis
IstSec'14 - İbrahim BALİÇ - Automated Malware Analysis
 
Building Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 Features
 
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
 
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]Yihan Lian &  Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
Yihan Lian & Zhibin Hu - Smarter Peach: Add Eyes to Peach Fuzzer [rooted2017]
 
Security and Privacy on the Web in 2015
Security and Privacy on the Web in 2015Security and Privacy on the Web in 2015
Security and Privacy on the Web in 2015
 
Java ist doch schon sicher?!
Java ist doch schon sicher?!Java ist doch schon sicher?!
Java ist doch schon sicher?!
 
So you want to be a security expert
So you want to be a security expertSo you want to be a security expert
So you want to be a security expert
 
QA: Базовое тестирование защищенности веб-приложений в рамках QA
QA: Базовое тестирование защищенности веб-приложений в рамках QAQA: Базовое тестирование защищенности веб-приложений в рамках QA
QA: Базовое тестирование защищенности веб-приложений в рамках QA
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
 
Hardening cassandra q2_2016
Hardening cassandra q2_2016Hardening cassandra q2_2016
Hardening cassandra q2_2016
 
Secret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s VaultSecret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s Vault
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
 
Securing Cassandra The Right Way
Securing Cassandra The Right WaySecuring Cassandra The Right Way
Securing Cassandra The Right Way
 
Web Uygulama Güvenliği (Akademik Bilişim 2016)
Web Uygulama Güvenliği (Akademik Bilişim 2016)Web Uygulama Güvenliği (Akademik Bilişim 2016)
Web Uygulama Güvenliği (Akademik Bilişim 2016)
 
Cassandra and security
Cassandra and securityCassandra and security
Cassandra and security
 
Red Team vs Blue Team on AWS - RSA 2018
Red Team vs Blue Team on AWS - RSA 2018Red Team vs Blue Team on AWS - RSA 2018
Red Team vs Blue Team on AWS - RSA 2018
 

Destacado

More Clicks, More Customers: Drive ROI with Video and Marketing Automation
More Clicks, More Customers: Drive ROI with Video and Marketing AutomationMore Clicks, More Customers: Drive ROI with Video and Marketing Automation
More Clicks, More Customers: Drive ROI with Video and Marketing AutomationMarketo
 
Evergreen: Nurturing Your Customers From First Contact to Happily Every After
Evergreen: Nurturing Your Customers From First Contact to Happily Every AfterEvergreen: Nurturing Your Customers From First Contact to Happily Every After
Evergreen: Nurturing Your Customers From First Contact to Happily Every AfterNoah Fleming
 
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT Goals
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT GoalsCloud Computing Technology: A Mechanism for Achieving Sustainable IT Goals
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT GoalsBooz Allen Hamilton
 
Cloud Computing: Big Data Technology
Cloud Computing: Big Data TechnologyCloud Computing: Big Data Technology
Cloud Computing: Big Data TechnologyBooz Allen Hamilton
 
Booz Allen's 10 Cyber Priorities for Boards of Directors
Booz Allen's 10 Cyber Priorities for Boards of DirectorsBooz Allen's 10 Cyber Priorities for Boards of Directors
Booz Allen's 10 Cyber Priorities for Boards of DirectorsBooz Allen Hamilton
 
Pin for the Win: How to Market Your Brand on Pinterest
Pin for the Win: How to Market Your Brand on PinterestPin for the Win: How to Market Your Brand on Pinterest
Pin for the Win: How to Market Your Brand on PinterestMarketo
 
Convergence and Disruption in Manufacturing
Convergence and Disruption in ManufacturingConvergence and Disruption in Manufacturing
Convergence and Disruption in ManufacturingBooz Allen Hamilton
 
5 Marketing Strategies for Customer Engagement
5 Marketing Strategies for Customer Engagement5 Marketing Strategies for Customer Engagement
5 Marketing Strategies for Customer EngagementMarketo
 
Booz Allen Industrial Cybersecurity Threat Briefing
Booz Allen Industrial Cybersecurity Threat BriefingBooz Allen Industrial Cybersecurity Threat Briefing
Booz Allen Industrial Cybersecurity Threat BriefingBooz Allen Hamilton
 
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...Marketo
 
Quarterly Feature Round Up Webinar
Quarterly Feature Round Up WebinarQuarterly Feature Round Up Webinar
Quarterly Feature Round Up WebinarMarketo
 
A New Era of Email Deliverability: Tools of 250ok
A New Era of Email Deliverability: Tools of 250okA New Era of Email Deliverability: Tools of 250ok
A New Era of Email Deliverability: Tools of 250okMarketo
 
Make Sure Your App Marketing Isn't Crap Marketing
Make Sure Your App Marketing Isn't Crap MarketingMake Sure Your App Marketing Isn't Crap Marketing
Make Sure Your App Marketing Isn't Crap MarketingMarketo
 
Behold, Magical Conversions with Predictive Content
Behold, Magical Conversions with Predictive ContentBehold, Magical Conversions with Predictive Content
Behold, Magical Conversions with Predictive ContentMarketo
 
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...Marketo
 
Social Media: The Rising Star for Your Digital Marketing Strategy
Social Media: The Rising Star for Your Digital Marketing StrategySocial Media: The Rising Star for Your Digital Marketing Strategy
Social Media: The Rising Star for Your Digital Marketing StrategyMarketo
 
Work Together Even When You're Not Together: Marketing Collaboration in the C...
Work Together Even When You're Not Together: Marketing Collaboration in the C...Work Together Even When You're Not Together: Marketing Collaboration in the C...
Work Together Even When You're Not Together: Marketing Collaboration in the C...Marketo
 
Twitter Tips for Beginners
Twitter Tips for BeginnersTwitter Tips for Beginners
Twitter Tips for BeginnersBuffer
 
I Can't Teach That!
I Can't Teach That!I Can't Teach That!
I Can't Teach That!mrrobbo
 

Destacado (20)

More Clicks, More Customers: Drive ROI with Video and Marketing Automation
More Clicks, More Customers: Drive ROI with Video and Marketing AutomationMore Clicks, More Customers: Drive ROI with Video and Marketing Automation
More Clicks, More Customers: Drive ROI with Video and Marketing Automation
 
Evergreen: Nurturing Your Customers From First Contact to Happily Every After
Evergreen: Nurturing Your Customers From First Contact to Happily Every AfterEvergreen: Nurturing Your Customers From First Contact to Happily Every After
Evergreen: Nurturing Your Customers From First Contact to Happily Every After
 
The Connected Vehicle Ecosystem
The Connected Vehicle EcosystemThe Connected Vehicle Ecosystem
The Connected Vehicle Ecosystem
 
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT Goals
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT GoalsCloud Computing Technology: A Mechanism for Achieving Sustainable IT Goals
Cloud Computing Technology: A Mechanism for Achieving Sustainable IT Goals
 
Cloud Computing: Big Data Technology
Cloud Computing: Big Data TechnologyCloud Computing: Big Data Technology
Cloud Computing: Big Data Technology
 
Booz Allen's 10 Cyber Priorities for Boards of Directors
Booz Allen's 10 Cyber Priorities for Boards of DirectorsBooz Allen's 10 Cyber Priorities for Boards of Directors
Booz Allen's 10 Cyber Priorities for Boards of Directors
 
Pin for the Win: How to Market Your Brand on Pinterest
Pin for the Win: How to Market Your Brand on PinterestPin for the Win: How to Market Your Brand on Pinterest
Pin for the Win: How to Market Your Brand on Pinterest
 
Convergence and Disruption in Manufacturing
Convergence and Disruption in ManufacturingConvergence and Disruption in Manufacturing
Convergence and Disruption in Manufacturing
 
5 Marketing Strategies for Customer Engagement
5 Marketing Strategies for Customer Engagement5 Marketing Strategies for Customer Engagement
5 Marketing Strategies for Customer Engagement
 
Booz Allen Industrial Cybersecurity Threat Briefing
Booz Allen Industrial Cybersecurity Threat BriefingBooz Allen Industrial Cybersecurity Threat Briefing
Booz Allen Industrial Cybersecurity Threat Briefing
 
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...
Create a Content Powerhouse: How to Structure and Optimize Your Content Marke...
 
Quarterly Feature Round Up Webinar
Quarterly Feature Round Up WebinarQuarterly Feature Round Up Webinar
Quarterly Feature Round Up Webinar
 
A New Era of Email Deliverability: Tools of 250ok
A New Era of Email Deliverability: Tools of 250okA New Era of Email Deliverability: Tools of 250ok
A New Era of Email Deliverability: Tools of 250ok
 
Make Sure Your App Marketing Isn't Crap Marketing
Make Sure Your App Marketing Isn't Crap MarketingMake Sure Your App Marketing Isn't Crap Marketing
Make Sure Your App Marketing Isn't Crap Marketing
 
Behold, Magical Conversions with Predictive Content
Behold, Magical Conversions with Predictive ContentBehold, Magical Conversions with Predictive Content
Behold, Magical Conversions with Predictive Content
 
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...
Increase AUM with Marketing Automation: Client Retention in Volatile Times (P...
 
Social Media: The Rising Star for Your Digital Marketing Strategy
Social Media: The Rising Star for Your Digital Marketing StrategySocial Media: The Rising Star for Your Digital Marketing Strategy
Social Media: The Rising Star for Your Digital Marketing Strategy
 
Work Together Even When You're Not Together: Marketing Collaboration in the C...
Work Together Even When You're Not Together: Marketing Collaboration in the C...Work Together Even When You're Not Together: Marketing Collaboration in the C...
Work Together Even When You're Not Together: Marketing Collaboration in the C...
 
Twitter Tips for Beginners
Twitter Tips for BeginnersTwitter Tips for Beginners
Twitter Tips for Beginners
 
I Can't Teach That!
I Can't Teach That!I Can't Teach That!
I Can't Teach That!
 

Similar a Rails and Content Security Policies

Rails security: above and beyond the defaults
Rails security: above and beyond the defaultsRails security: above and beyond the defaults
Rails security: above and beyond the defaultsMatias Korhonen
 
Csp and http headers
Csp and http headersCsp and http headers
Csp and http headersdevObjective
 
DefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersPhú Phùng
 
Securing your web application through HTTP headers
Securing your web application through HTTP headersSecuring your web application through HTTP headers
Securing your web application through HTTP headersAndre N. Klingsheim
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security PolicyAustin Gil
 
[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security HeadersOWASP
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Philippe Gamache
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Philippe Gamache
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Philippe Gamache
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header SecurityMikal Villa
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Philippe Gamache
 
HTTP_Header_Security.pdf
HTTP_Header_Security.pdfHTTP_Header_Security.pdf
HTTP_Header_Security.pdfksudhakarreddy5
 
Devopsdays london: Let’s talk about security
Devopsdays london:  Let’s talk about securityDevopsdays london:  Let’s talk about security
Devopsdays london: Let’s talk about securityJustin Cormack
 
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...PROIDEA
 
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 PolicyGeorge Boobyer
 
How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?Ksenia Peguero
 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsLewis Ardern
 
So you thought you were safe using AngularJS.. Think again!
So you thought you were safe using AngularJS.. Think again!So you thought you were safe using AngularJS.. Think again!
So you thought you were safe using AngularJS.. Think again!Lewis Ardern
 

Similar a Rails and Content Security Policies (20)

Rails security: above and beyond the defaults
Rails security: above and beyond the defaultsRails security: above and beyond the defaults
Rails security: above and beyond the defaults
 
Csp and http headers
Csp and http headersCsp and http headers
Csp and http headers
 
DefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysisDefCamp 2013 - Http header analysis
DefCamp 2013 - Http header analysis
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in Browsers
 
Securing your web application through HTTP headers
Securing your web application through HTTP headersSecuring your web application through HTTP headers
Securing your web application through HTTP headers
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security Policy
 
[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers
 
Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017Browser Serving Your Web Application Security - NorthEast PHP 2017
Browser Serving Your Web Application Security - NorthEast PHP 2017
 
Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017Browser Serving Your Web Application Security - Madison PHP 2017
Browser Serving Your Web Application Security - Madison PHP 2017
 
Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017Browser Serving Your We Application Security - ZendCon 2017
Browser Serving Your We Application Security - ZendCon 2017
 
Tsc summit #2 - HTTP Header Security
Tsc summit #2  - HTTP Header SecurityTsc summit #2  - HTTP Header Security
Tsc summit #2 - HTTP Header Security
 
Content-Security-Policy 2018.0
Content-Security-Policy 2018.0Content-Security-Policy 2018.0
Content-Security-Policy 2018.0
 
HTTP_Header_Security.pdf
HTTP_Header_Security.pdfHTTP_Header_Security.pdf
HTTP_Header_Security.pdf
 
Devopsdays london: Let’s talk about security
Devopsdays london:  Let’s talk about securityDevopsdays london:  Let’s talk about security
Devopsdays london: Let’s talk about security
 
Web Security - CSP & Web Cryptography
Web Security - CSP & Web CryptographyWeb Security - CSP & Web Cryptography
Web Security - CSP & Web Cryptography
 
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
 
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 do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?
 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript Applications
 
So you thought you were safe using AngularJS.. Think again!
So you thought you were safe using AngularJS.. Think again!So you thought you were safe using AngularJS.. Think again!
So you thought you were safe using AngularJS.. Think again!
 

Último

SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 

Último (20)

SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 

Rails and Content Security Policies

  • 1. Ruby Brigade 10/2016 Rails and Content Security Policies
  • 2. Who am I? • A developer at Kisko Labs • In my free 8me I work on too many side projects • piranhas.co — a book price comparison site and app • Beer Styles — an iOS app for browsing beer style guidelines • TLS.caresoon! — an SSL/TLS cer8ficate monitoring service • and I also brew beer
  • 3. Kisko Labs We build and launch tools on the web Are you a Ruby or frontend developer? We're hiring
  • 5. Content Security Policy is an added layer of security that helps to detect and mi3gate certain types of a5acks, including Cross Site Scrip3ng (XSS) and data injec3on a5acks. — MDN
  • 6. Content Security Policy: a header which tells the browser where resources (scripts, stylesheets, fonts, etc) can be loaded from. — Me
  • 7. Supported by all major browsers, even Internet Explorer (kind of)
  • 8.
  • 9. CSP: Why? • Reduces the poten.al surface area for a3acks or malicious injec.on of scripts • Prevents malicious browser extensions and malware from inser.ng crap into your pages. • For example, the CSP on Piranhas.co has stopped some shady browser extensions from injec.ng ads? onto the page.
  • 10.
  • 12.
  • 13. I don't know what this is, but I know that I don't want it on my site!
  • 14. CSP Direc*ves Content Security Policies allow quite fine grained control over what can be loaded from where. For example, you can allow scripts from a domain but not images (or vice versa). Or, for example, if you allow users to upload images, but not scripts, you can segregate user uploads to a specific host (“allow images from uploads.example.com but nothing else”).
  • 15. Available direc,ves • default-src: Define loading policy for all resources type in case of a resource type dedicated direc5ve is not defined (fallback), • script-src: Define which scripts the protected resource can execute, • object-src: Define from where the protected resource can load plugins, • style-src: Define which styles (CSS) the user applies to the protected resource,
  • 16. • img-src: Define from where the protected resource can load images, • media-src: Define from where the protected resource can load video and audio, • frame-src: Define from where the protected resource can embed frames, • font-src: Define from where the protected resource can load fonts,
  • 17. • connect-src: Define which URIs the protected resource can load using script interfaces, • form-ac-on: Define which URIs can be used as the ac;on of HTML form elements, • sandbox: Specifies an HTML sandbox policy that the user agent applies to the protected resource, • script-nonce: Define script execu;on by requiring the presence of the specified nonce on script elements,
  • 18. • plugin-types: Define the set of plugins that can be invoked by the protected resource by limi:ng the types of resources that can be embedded, • reflected-xss: Instructs a user agent to ac:vate or deac:vate any heuris:cs used to filter or block reflected cross-site scrip:ng a?acks, equivalent to the effects of the non-standard X-XSS- Protec:on header, • report-uri: Specifies a URI to which the user agent sends reports about policy viola:on
  • 19. Adding a CSP header to a long standing site can be … tricky
  • 20. CSP example (piranhas.co) Content-Security-Policy: default-src https:; style-src 'unsafe-inline' https://cdn.piranhas.xyz https://fonts.googleapis.com; script-src 'unsafe-inline' 'unsafe-eval' https://cdn.piranhas.xyz https://www.google-analytics.com https://suggestqueries.google.com https://www.googleapis.com; img-src data: https:; report-uri https://x.report-uri.io/r/default/csp/enforce; (line breaks added for clarity…)
  • 21. Adding it from the very beginning is a lot easier…
  • 22. CSP example (simplified) Content-Security-Policy: default-src *; Allow all sources, but disallow unsafe inline assets (for example scripts and styles).
  • 23. CSP example (simplified alterna3ve) Content-Security-Policy: default-src 'self'; Allow all sources, but disallow unsafe inline assets (for example scripts and styles).
  • 24. 'unsafe-inline' vs “safe inline” • By default inline scripts are blocked • You can either • add 'unsafe-inline' to your CSP (in which case you're back where your started) • or use inline scripts with a nonce (more on this later)
  • 25. In cryptography, a nonce is an arbitrary number that may only be used once. — Wikipedia
  • 26. You specify the nonce in the CSP header: Content-Security-Policy: ... script-src 'nonce-/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=' ...; and in your <script> (or <style>) tag: <script nonce="/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI="> console.log("Hello World") </script> The browser will allow each nonce to be used only once…
  • 28. Secure Headers A Rack middleware gem from Twi2er which adds support for more security headers than are available by default in Rails. • h#ps://github.com/twi#er/secureheaders • h#ps://rubygems.org/gems/secure_headers Makes it easier to use CSP headers (and it also handles other security headers)
  • 29. Secure Headers It lets you define an app-wide CSP that you can override or append to at a controller or ac9on level. Don't just add it though. Look through the configura6on and understand what it's doing. You might want to disable some of the op6ons.
  • 30. Secure Headers It's a pre*y extensive library, so read the README to learn more.
  • 31. Secure Headers: nonces It also includes support for safe inline styles and scripts using nonces. For example: <%= nonced_javascript_tag do %> console.log("nonced!"); <% end %>
  • 32. Secure Headers: nonces Generates this HTML: <script nonce="/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI="> console.log("nonced!") </script> And adds this to the CSP header: Content-Security-Policy: ... script-src 'nonce-/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=' ...;
  • 33. Secure Headers: minimal configura3on # config/initializers/secure_headers.rb SecureHeaders::Configuration.default do |config| config.csp = { default_src: %w(*), upgrade_insecure_requests: Rails.env.production?, # see https://www.w3.org/TR/upgrade-insecure-requests/ report_uri: %w(https://x.report-uri.io/r/default/csp/enforce) } config.hpkp = SecureHeaders::OPT_OUT end Or you might want to use 'self' instead of *
  • 34. Secure Headers Rails also sets some of the same security headers, but Secure Headers has code to override those with its own configura;on. => Secure Headers knows how to play nice with Rails
  • 35. => Secure Headers knows how to play nice with Rails isolate_namespace SecureHeaders if defined? isolate_namespace # rails 3.0 conflicting_headers = ['X-Frame-Options', 'X-XSS-Protection', 'X-Permitted-Cross-Domain-Policies', 'X-Download-Options', 'X-Content-Type-Options', 'Strict-Transport-Security', 'Content-Security-Policy', 'Content-Security-Policy-Report-Only', 'Public-Key-Pins', 'Public-Key-Pins-Report-Only', 'Referrer-Policy'] # ... conflicting_headers.each do |header| Rails.application.config.action_dispatch.default_headers.delete(header) end h"ps://github.com/twi"er/secureheaders/blob/v3.4.1/lib/ secure_headers/rail;e.rb
  • 37. CSP pro-)ps Start by using the Content-Security-Policy-Report-Only header to test and tweak your CSP header in the wild. Content-Security-Policy-Report-Only: default-src *, report-uri https://x.report-uri.io/r/default/csp/enforce;; Deploy the Report Only header for a few days before star1ng to enforce it.
  • 38. CSP pro-)ps • New projects • Enforce the CSP from the beginning • Report viola<ons from your staging or produc<on environment • Old projects • Add a CSP with all the sources you think you need • Deploy it as Report Only, leave it for a week or two to uncover anything you might have forgoEen about • Deploy the enforced policy once you've accounted for all the viola<ons • Both • When making changes, you may wish to first test them with the Report Only header (depending on the change)
  • 39. CSP resources • h#ps://sco#helme.co.uk/content-security-policy-an- introduc8on/ • h#ps://report-uri.io • h#ps://developer.mozilla.org/en-US/docs/Web/Security/CSP/ Using_Content_Security_Policy
  • 40. CSP resources • h#ps://github.com/twi#er/secureheaders • h#ps://security.googleblog.com/2016/09/reshaping-web- defenses-with-strict.html • CSP Evaluator: h#ps://csp-evaluator.withgoogle.com/ • CSP MiGgator: h#ps://chrome.google.com/webstore/detail/ csp-miGgator/gijlobangojajlbodabkpjpheeeokhfa
  • 42. Summary • Rails defaults are pre/y good, but can be (fairly easily) be 9ghtened • Use a Content Security Policy, if only to prevent ad/malware injec9on by compromised browsers • The more strict the CSP is, the fewer chances there are for third par9es to mess with your site • Use the Secure Headers gem to manage the CSP policy and other security headers • It requires more thought than the Rails defaults, but I think it's worth it • Excep&on to all of the above: If you're working on your first Rails app, you probably shouldn't add this complexity.