new protecting users by confining javascript with swapi · 2015. 1. 21. · execute javascript...

97
Protecting Users by Confining JavaScript with SWAPI Deian Stefan, Petr Marchenko, Brad Karp, David Mazières, Dave Herman, and John C. Mitchell

Upload: others

Post on 17-Oct-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Protecting Users by Confining JavaScript with SWAPI

Deian Stefan, Petr Marchenko, Brad Karp, David Mazières, Dave Herman, and John C. Mitchell

Page 2: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page 3: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page 4: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page code

Page 5: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page code Ad code

Page 6: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page code Ad code

Third-party APIs

Page 7: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page code

Third-party libraries

Ad code

Third-party APIs

Page 8: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites are complex

Page code

Third-party libraries

Ad code

Third-party APIs

Extensions

Page 9: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Modern websites handle sensitive information

• Financial data

➤ Online banking, tax filing, shopping, budgeting, …

• Health data

➤ Genomics, prescriptions, …

• Personal data

➤ Email, messaging, affiliations, …

Page 10: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Many parties are interested in the sensitive data

• Financial data

➤ Black-hat hackers, …

• Health data

➤ Insurance companies, …

• Personal data

➤ Ad companies, big governments, …

Page 11: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Many parties are interested in the sensitive data

• Financial data

➤ Black-hat hackers, …

• Health data

➤ Insurance companies, …

• Personal data

➤ Ad companies, big governments, …

Page 12: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Many parties are interested in the sensitive data

• Financial data

➤ Black-hat hackers, …

• Health data

➤ Insurance companies, …

• Personal data

➤ Ad companies, big governments, …

Page 13: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Many parties are interested in the sensitive data

• Financial data

➤ Black-hat hackers, …

• Health data

➤ Insurance companies, …

• Personal data

➤ Ad companies, big governments, …

Page 14: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

How do we protect sensitive data?

Non requirements!

… information exchange is still more important than secrecy.Tim Berners-Lee, 1989

Page 15: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

How do we protect sensitive data?

Non requirements!

… information exchange is still more important than secrecy.Tim Berners-Lee, 1989

still somewhat true…

Page 16: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

How do we protect sensitive data?

Non requirements!

… information exchange is still more important than secrecy.Tim Berners-Lee, 1989

still somewhat true…

but this was before the Web became the platform…

Page 17: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What is the state of the art in web security?

• Same Origin Policy

• Content Security Policy

• Sandboxing

Page 18: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

Page 19: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

Page 20: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

Page 21: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

Page 22: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

Page 23: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

✓JSON

Page 24: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

✓JSON

Page 25: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

✓JSON

Page 26: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Idea: isolate content from different origins

➤ E.g., can’t access document of cross-origin page

➤ E.g., can’t inspect responses from cross-origin

c.com b.coma.com

postMessage

✓JSON

Page 27: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Same Origin Policy

Limitations:

➤ Some DOM objects leak data

- E.g., image size can leak if user is logged in

➤ Data exfiltration is trivial

- E.g., any XHR request can contain data form page

➤ Cross-origin scripts run with privilege of page

➠ Injected scripts can corrupt and leak user data!

Page 28: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com a.com

Page 29: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com

Page 30: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

Page 31: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 32: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 33: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 34: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 35: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 36: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy

Goal: prevent and limit damage of XSS attacksIdea: restrict resource loading to a white-list

➤ E.g., default-src ‘self’ http://b.com; img-src *

c.com b.coma.com✓

JSON

Page 37: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com

a.coma.com

Page 38: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com

a.coma.com

Page 39: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com

a.coma.com

unq0

Page 40: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com

a.coma.com

unq0

Page 41: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com✓

a.coma.com

unq0

Page 42: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com✓

a.coma.com

unq0

Page 43: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com✓

a.coma.com

unq0

unq1

Page 44: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Sandboxing

Idea: restrict actions page can perform

➤ E.g., directive sandbox allow-scripts ensures iframe has unique origin

➤ E.g., directive sandbox ensures iframe has unique origin and cannotexecute JavaScript

a.coma.com✓

a.coma.com

unq0

unq1

Page 45: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Content Security Policy & Sandboxing

Limitations:

➤ Data exfiltration is only partly contained

- Can leak to origins we can load resources from, and sibling frames or child Workers (via postMessage)

➤ Scripts still run with privilege of page

- Can we reason about security of jQuery-sized lib?

Page 46: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What is the state of the art in web security?

• Same Origin Policy

• Content Security Policy

• Sandboxing

Page 47: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What is the state of the art in web security?

• Same Origin Policy

• Content Security Policy

• Sandboxing

All-or-nothing discretionary access control: access data ➠ ability to leak it

Page 48: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Page 49: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Page 50: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Mashups

Page 51: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Third-party libraries

Mashups

Page 52: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Page 53: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Extensions

Page 54: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Where this falls short…

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Extensions

Page 55: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Guarantee: checker cannot leak password

➤ At worst: checker lies about strength of password

Password-strength checker

b.ru/chk.htmla.com

Page 56: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 57: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

p45s

Page 58: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 59: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 60: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 61: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 62: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 63: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Page 64: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker using existing mechanisms

• Host the checker code on a.com

• CSP & Sandboxing

➤ Need JavaScript: sandbox allow-scripts

➤ Restrict all communication: default-src ‘none’ ‘unsafe-inline’

a.com/chk.htmla.com b.ru

Actually can leak to iframes, so need to use also Workers…

Page 65: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Why is this unsatisfactory?

• Functionality of library is limited

➤ E.g., library cannot fetch resources from network

• Requires server-side support to set policy

• Security policy is not first-class

➤ Library cannot use code it itself doesn’t trust

• Security policy is not symmetric

➤ Library cannot consider parent untrusted

Page 66: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

A new approach: Secure Web API

Idea (a): Provide means for associating security label with data

➤ E.g., password is sensitive to a.com

Idea (b): Ensure code is confined to obey labels by associating labels with browsing contexts

➤ E.g., password can only be sent to entities that are as sensitive as a.com (via XHR, postMessage, storage, …)

Page 67: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.rua.com

Page 68: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru

public b.ru

a.com

a.com

Page 69: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru

public b.ru?

a.com

a.com

Page 70: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru

public b.ru

a.com

a.com

Page 71: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com

Page 72: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com

Page 73: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com

Page 74: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com

Page 75: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com ?

Page 76: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

a.com

a.com

Page 77: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

postMessage({level: “a.com”}, “b.ru” , Label())

?

a.com

a.com

Page 78: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

postMessage({level: “a.com”}, “b.ru” , Label())

a.com

a.com

Page 79: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

{level: “a.com”}

a.com

a.com

Page 80: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

publicpublic b.ru

{level: “a.com”}

a.com

a.com

SWAPI.label = event.data.level;

Page 81: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.ru

{level: “a.com”}

a.com

a.com

a.com

SWAPI.label = event.data.level;

Page 82: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.ru

{level: “a.com”}

a.com

a.com

a.com

SWAPI.label = event.data.level;

Page 83: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

Page 84: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

postMessage({pass: ...}, “b.ru” , Label(“a.com”))

?

Page 85: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

postMessage({pass: ...}, “b.ru” , Label(“a.com”))

?{pass: ...}

Page 86: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

{pass: ...}

Page 87: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

Page 88: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

Page 89: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.comCan leak password to a.com Fix: create fresh labels to ensure checker is fully confined

Page 90: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Confining the checker with SWAPI

• Express sensitivity of data

➤ Checker can only receive password if its context label is as sensitive as the password

• Use new postMessage API to send password

➤ Source specifies sensitivity of data at time of send

a.com b.ru/chk.html b.ru

public b.rua.com

a.com

a.com

Page 91: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What can we do with this?

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Extensions

Page 92: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Rest of SWAPI• Privileges

➤ Origin can use privilege to exfiltrate its own data

• Labeled DOM (light-weight) workers ➤ Extensions: Untrusted code executed in unprivileged worker

Like Chrome-extension model, but uses confinement

➤ Third-party libs: Worker contains page TCB and page privilege Confined page contains untrusted jQuery

• Labeled XHR constructor ➤ Allow reading cross-origin responses, but restrict context

from writing it arbitrarily

Page 93: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What can we do with this?

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Extensions

Page 94: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

What can we do with this?

Third-party APIs

Third-party libraries

Mashups

Third-party mashups

Extensions

And more…

Page 95: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Implementation

• A minimally intrusive implementation

➤ Set CSP & iframe sandbox dynamically, according to context label

➤ Restrict postMessage and object access according to context label (even for same origin contexts!)

➤ Opt-in: enabled when using any SWAPI feature

• Implemented in Firefox and Chromium

➤ Negligible performance impact

Page 96: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Summary• Client-side security mechanism

• Security policy is first-class

➤ Any code can impose restrictions oh what the receiver can do with the data before sending it

• Security policy is symmetric

➤ Iframes and workers can impose restrictions on parent code when sending messages

★ Consequence: don’t need to trade off functionality and security

Page 97: New Protecting Users by Confining JavaScript with SWAPI · 2015. 1. 21. · execute JavaScript a.com a.com a ... Third-party APIs Third-party libraries Mashups. Where this falls short

Thanks. Stay tuned…

Many thanks to Edward Z. Yang, Stefan Heule, Bobby Holley, Blake Kaplan, Garrett Robinson, and Brian Smith.

that can only talk to your friendsthat can only talk to your friends

————-———-—————-———-—————-———-—————-———-—