csp july2015

19
Content Security Policy OR HOW TO MAKE DEVELOPERS EVEN MORE LAZIER RIYAZ WALIKAR

Upload: nu-the-open-security-community

Post on 13-Aug-2015

203 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Csp july2015

Content Security PolicyOR HOW TO MAKE DEVELOPERS EVEN MORE LAZIER

RIYAZ WALIKAR

Page 2: Csp july2015

whoami

Security evangelist

Do not work at a Big 4

One of the 3 OWASP Bangalore chapter leaders

Extremely talkative

Page 3: Csp july2015

Same Origin Policy

So you own http://banana.com

Code from http://potato.com should not be able to access data from http://banana.com

Browser’s sandbox and Origin protection

XSS to bypass SOP

Page 4: Csp july2015

For the love of XSS

Reflected, Stored, DOM based

Page 5: Csp july2015
Page 6: Csp july2015

Content Security Policy

Page 7: Csp july2015

The core issue exploited by XSS attacks is the browser’s inability to distinguish between script that’s intended to be part of your application, and script that’s been maliciously injected by a third-party.

http://www.html5rocks.com/en/tutorials/security/content-security-policy/

Page 8: Csp july2015

I had you at Header

Content Security Policy (CSP) defines the Content-Security-Policy HTTP header

Whitelist script sources of trusted content

Even if vulnerable to XSS, injected script will not trigger due to header definition

Page 9: Csp july2015

Building the policy

So you trust scripts only from http://banana.com and your own domain (non inline)

Content-Security-Policy: script-src 'self' http://banana.com

So you want to load images only from http://potato.com and flash content from your own domain. Also, absolutely no scripts.

Content-Security-Policy: script-src 'none'; img-src http://potato.com; object-src 'self'

Page 10: Csp july2015

CSP Directives

default-src

script-src

style-src

img-src

connect-src

font-src

object-src

media-src

child-src

sandbox

report-uri

The default-src is the default policy for loading content such as JavaScript, Images, CSS, fonts, AJAX requests, Frames and HTML5 Media

Defines valid sources of JavaScriptDefines valid sources of css (stylesheets)Defines valid sources of imagesDefines sources to which XMLHTTPRequest (AJAX), WebSocket or EventSource can fetch data from

Defines valid sources of fontsDefines valid sources of plugins (for example: flash, embed tag, applet etc.)

Defines valid source of audio and videoDefines valid source for workers and embedded frame contents.

frame-src is deprecated. child-src should be used.

More about this laterInstructs the browser to POST a reports of policy failures to a specified URI.

Page 11: Csp july2015

CSP Source Declarations

Source Value Meaning

* Wildcard, allows all origins.

'self' Allow same origin (current origin).

'none'Don't allow any resources of this directive to load.

domain.example.com Allow a domain (explicit declaration)

*.example.com Allow all subdomains on a domain. Exclude TLD.

https://example.com Exact match including protocol

https: Load from any domain but https

data: Allow data uri (eg: Base64 encoded image)

Page 12: Csp july2015

unsafe-inline

When script-src or style-src are declared, inline script tags and css are disabled

You can specify 'unsafe-inline' to execute inline script but that is precisely what CSP was designed to prevent!

Page 13: Csp july2015

unsafe-eval

CSP disables the JavaScript function eval() by design

To enable this explicitly, add 'unsafe-eval' to a script-src directive

Not advised!

Page 14: Csp july2015

sandbox

If present, browser treats the page as if it loaded inside an iframe with a sandbox attribute

The browser severely restricts the page’s functionality, disabling JS, form submissions, plugins and objects

You can keep the sandbox value empty to keep all restrictions in place, or add values: allow-forms allow-same-origin allow-scripts, and allow-top-navigation

Page 15: Csp july2015

DEMOTIME

Page 17: Csp july2015

CSP 2.0!

Several new enhancements including support for inline scripts in combination with a cryptographic nonce or hash sharing of the script itself

Content-Security-Policy: script-src 'nonce-AY778asa229b2DEADBEEF'

http://www.w3.org/TR/CSP2/

Page 19: Csp july2015

Riyaz Walikar

http://www.riyazwalikar.com

@riyazwalikar

@wincmdfu