Protecting Users by Confining JavaScript with SWAPI
Deian Stefan, Petr Marchenko, Brad Karp, David Mazières, Dave Herman, and John C. Mitchell
Protecting Users by Confining JavaScript with SWAPI Deian Stefan, - - PowerPoint PPT Presentation
Protecting Users by Confining JavaScript with SWAPI Deian Stefan, Petr Marchenko, Brad Karp, David Mazires, Dave Herman, and John C. Mitchell Modern websites are complex Modern websites are complex Modern websites are complex Page code
Deian Stefan, Petr Marchenko, Brad Karp, David Mazières, Dave Herman, and John C. Mitchell
Page code
Page code Ad code
Page code Ad code Third-party APIs
Page code Third-party libraries Ad code Third-party APIs
Page code Third-party libraries Ad code Third-party APIs Extensions
➤ Online banking, tax filing, shopping, budgeting, …
➤ Genomics, prescriptions, …
➤ Email, messaging, affiliations, …
➤ Black-hat hackers, …
➤ Insurance companies, …
➤ Ad companies, big governments, …
➤ Black-hat hackers, …
➤ Insurance companies, …
➤ Ad companies, big governments, …
➤ Black-hat hackers, …
➤ Insurance companies, …
➤ Ad companies, big governments, …
➤ Black-hat hackers, …
➤ Insurance companies, …
➤ Ad companies, big governments, …
Non requirements
… information exchange is still more important than secrecy.
Tim Berners-Lee, 1989
Non requirements
… information exchange is still more important than secrecy.
Tim Berners-Lee, 1989
still somewhat true…
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…
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.com a.com
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.com a.com
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.com a.com
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.com a.com
postMessage
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.com a.com
postMessage
✓
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.com a.com
postMessage
✓
JSON
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.com a.com
postMessage
✓
JSON
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.com a.com
postMessage
✓
JSON
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.com a.com
postMessage
✓
JSON
Limitations:
➤ Some DOM objects leak data
➤ Data exfiltration is trivial
➤ Cross-origin scripts run with privilege of page
➠ Injected scripts can corrupt and leak user data!
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com a.com
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
Goal: prevent and limit damage of XSS attacks Idea: restrict resource loading to a white-list
➤ E.g., default-src ‘self’ http://b.com; img-src *
c.com b.com a.com
✓
JSON
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 cannot execute JavaScript
a.com a.com a.com a.com
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 cannot execute JavaScript
a.com a.com a.com a.com
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 cannot execute JavaScript
a.com a.com a.com a.com unq0
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 cannot execute JavaScript
a.com a.com a.com a.com unq0
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 cannot execute JavaScript
a.com a.com
✓
a.com a.com unq0
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 cannot execute JavaScript
a.com a.com
✓
a.com a.com unq0
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 cannot execute JavaScript
a.com a.com
✓
a.com a.com unq0 unq1
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 cannot execute JavaScript
a.com a.com
✓
a.com a.com unq0 unq1
Limitations:
➤ Data exfiltration is only partly contained
and sibling frames or child Workers (via postMessage)
➤ Scripts still run with privilege of page
All-or-nothing discretionary access control: access data ➠ ability to leak it
Third-party APIs
Third-party APIs Mashups
Third-party APIs Third-party libraries Mashups
Third-party APIs Third-party libraries Mashups Third-party mashups
Third-party APIs Third-party libraries Mashups Third-party mashups Extensions
Third-party APIs Third-party libraries Mashups Third-party mashups Extensions
Guarantee: checker cannot leak password
➤ At worst: checker lies about strength of password
b.ru/chk.html a.com
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
p45s
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
➤ Need JavaScript: sandbox allow-scripts ➤ Restrict all communication:
default-src ‘none’ ‘unsafe-inline’
a.com/chk.html a.com b.ru
Actually can leak to iframes, so need to use also Workers…
➤ E.g., library cannot fetch resources from network
➤ Library cannot use code it itself doesn’t trust
➤ Library cannot consider parent untrusted
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, …)
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru
public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru
public b.ru
?
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru
public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
?
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru postMessage({level: “a.com”}, “b.ru” , Label())
?
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru postMessage({level: “a.com”}, “b.ru” , Label())
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
{level: “a.com”}
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public public b.ru
{level: “a.com”}
a.com
a.com SWAPI.label = event.data.level;
➤ Checker can only receive password if its context
label is as sensitive as the 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;
➤ Checker can only receive password if its context
label is as sensitive as the 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;
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com postMessage({pass: ...}, “b.ru” , Label(“a.com”))
?
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com postMessage({pass: ...}, “b.ru” , Label(“a.com”))
?
{pass: ...}
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com
{pass: ...}
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com Can leak password to a.com Fix: create fresh labels to ensure checker is fully confined
➤ Checker can only receive password if its context
label is as sensitive as the password
➤ Source specifies sensitivity of data at time of send
a.com b.ru/chk.html b.ru
public b.ru a.com
a.com
a.com
Third-party APIs Third-party libraries Mashups Third-party mashups Extensions
➤ Origin can use privilege to exfiltrate its own data
➤ 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
➤ Allow reading cross-origin responses, but restrict context
from writing it arbitrarily
Third-party APIs Third-party libraries Mashups Third-party mashups Extensions
Third-party APIs Third-party libraries Mashups Third-party mashups Extensions
➤ 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
➤ Negligible performance impact
➤ Any code can impose restrictions oh what the
receiver can do with the data before sending it
➤ Iframes and workers can impose restrictions on
parent code when sending messages
★ Consequence: don’t need to trade off functionality and security
Many thanks to Edward Z. Yang, Stefan Heule, Bobby Holley, Blake Kaplan, Garrett Robinson, and Brian Smith.
that can only talk to your friends that can only talk to your friends
————-——
————-——
————-——
————-——