Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile...

54
Secure Distributed Programming with Object-capabilities in JavaScript Mark S. Miller and the Cajadores

Transcript of Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile...

Page 1: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Secure Distributed Programming with Object-capabilities in JavaScript

Mark S. Miller and the Cajadores

Page 2: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Overview

Why object-capability (ocap) security? Local ocap security in JavaScript Flexible secure mobile code Distributed crypto-caps in JavaScript Secure distributed object programming

Page 3: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Early Choice. Late Despair

ACLs and OCaps start in mid ‘60s. ACLs: “Who is making this request?” OCaps: “Is this request authorized?”

‘70s: Industry took ACL fork in road. ‘90s to present: Rise of Malware

Page 4: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Very Powerful Program

Page 5: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Very Powerful Program

This program can delete any file you can.

Page 6: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Original Web

Server

Server

Frame

Frame

Browser

Link/Form GET/POST

New Page

Link/Form GET/POST

New Page

Page 7: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Ajax = Mobile code + async msgs

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response

XHR GET/POST

XHR Response

Web services

Page 8: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Kludging Towards Distributed Objects

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response, Comet

XHR GET/POST

XHR Response, Comet

Web services JSONP Fragment

tricks

Page 9: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Web of Distributed Objects

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response, SSE

XHR GET/POST

XHR Response, SSE

Web services Cross-Origin XHR

with UMP

postMessage

Page 10: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Web of Distributed Objects

Mobile messages, code, objects, references

Page 11: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Web of Distributed Objects

Page 12: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Web of Distributed Objects

Page 13: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Web of Distributed Objects

Page 14: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Very Powerful Email Message

Page 15: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

A Very Powerful Email Message <html> <head> <title>Basic Mashup</title> <script> function animate(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; var text = textNode.data; var reverse = false; element.onclick = function() { reverse = !reverse; }; setInterval(function() { textNode.data = text = reverse ? text.substring(1) + text[0] : text[text.length-1] + text.substring(0, text.length-1); }, 100); } </script> </head> <body onload="animate('target')"> <pre id="target">Hello Programmable World! </pre> </body> </html>

Page 16: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Active Content: Mobile Code as Media <html> <head> <title>Basic Mashup</title> <script> function animate(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; var text = textNode.data; var reverse = false; element.onclick = function() { reverse = !reverse; }; setInterval(function() { textNode.data = text = reverse ? text.substring(1) + text[0] : text[text.length-1] + text.substring(0, text.length-1); }, 100); } </script> </head> <body onload="animate('target')"> <pre id="target">Hello Programmable World! </pre> </body> </html>

Page 17: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

The Road Not Taken

?

Page 18: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

The Road Not Taken

?

Page 19: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

The Road Not Taken

?

Page 20: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

The Road Not Taken

? ?

Page 21: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Security as Extreme Modularity

Modularity: Avoid needless dependencies Security: Avoid needless vulnerabilities Vulnerability is a form of dependency

Modularity: Principle of info hiding - need to know

Security: Principle of least authority - need to do

Page 22: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Connectivity by…

… Introduction ref to Carol ref to Bob decides to share

… Parenthood … Endowment … Initial Conditions

Alice says: bob.foo(carol)

How might object Bob come to know object Carol?

Page 23: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

OCaps: Small step from pure objects

Memory safety and encapsulation + Effects only by using held references + No powerful references by default

Page 24: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

OCaps: Small step from pure objects

Memory safety and encapsulation + Effects only by using held references + No powerful references by default Reference graph ≡ Access graph Only connectivity begets connectivity Natural Least Authority OO expressiveness for security patterns

Page 25: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } }; }

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

Objects as Closures in JavaScript

Page 26: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Objects as Closures in JavaScript

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } }; }

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A record of closures hiding state is a fine representation of an

object of methods hiding instance vars

Page 27: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } }; }

•  Scoping confusions •  Encapsulation leaks •  Pervasive mutability

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

Objects as Closures in EcmaScript 3

Page 28: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Defensive Objects in SES on ES5

“use strict”; function makeCounter() { var count = 0; return def({ incr: function() { return ++count; }, decr: function() { return --count; } }); }

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A tamper-proof record of lexical closures encapsulating state

is a defensive object

Page 29: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR
Page 30: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR
Page 31: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR
Page 32: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Turning EcmaScript 5 into SES

<script src=“initSES.js”></script>

Monkey patch away bad non-std behaviors Remove non-whitelisted primordials Install leaky WeakMap emulation Make virtual global root Freeze whitelisted global variables •  Replace eval & Function with safe alternatives Freeze accessible primordials

Page 33: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

No powerful references by default

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

bob

carol

Alice Bob

Carol

Page 34: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

No powerful references by default

bob

carol

Alice

Bob and Carol are confined. Only Alice controls how they can interact or get more connected.

Bob

Carol

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

Page 35: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

No powerful references by default

Alice says: Alice bob

carol

Bob

Carol

Page 36: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null; countcountcount

incr

decr

Page 37: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null; countcountcount

incr

decr

Bob can only count up and see result. Carol only down. Alice can only do both.

Page 38: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null; countcountcount

incr

decr

Express policy by the behavior of the objects you provide.

Page 39: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Dr. SES Distributed Resilient Secure EcmaScript

Linguistic abstraction for safe messaging Stretch reference graph between event loops & machines Crypto analog of memory safety

SES + Promise library + infix “!” syntax (“Q” Library usable today without “!” syntax)

Page 40: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Unguessable URLs as Crypto-Caps

https://www.example.com/app/#mhbqcmmva5ja3

How are secrets like object references?

Page 41: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Dr. SES Distributed Resilient Secure EcmaScript

var result = bob.foo(carol); Local-only immediate call

var resultP = bobP ! foo(carol); Eventual send

Page 42: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Dr. SES Distributed Resilient Secure EcmaScript

var result = bob.foo(carol); Local-only immediate call

var resultP = bobP ! foo(carol); Eventual send

var result = bob.foo; Local-only immediate get

var resultP = bobP ! foo; Eventual get

Page 43: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Dr. SES Distributed Resilient Secure EcmaScript

var resultP = bobP ! foo(carol); Eventual send

var resultP = bobP ! foo; Eventual get

Page 44: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Dr. SES Distributed Resilient Secure EcmaScript

var resultP = bobP ! foo(carol); Eventual send

var resultP = bobP ! foo; Eventual get

Page 45: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Q(resultP).when(function(result) { …result… }, function (ex) { …ex… });

Register for notification

Dr. SES Distributed Resilient Secure EcmaScript

var resultP = bobP ! foo(carol); Eventual send

var resultP = bobP ! foo; Eventual get

Page 46: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Q(resultP).when(function(result) { …result… }, function (ex) { …ex… });

xhr.onreadystatechange = …

Async object ops as JSON/REST ops

var resultP = bobP ! foo(carol); POST https://…q=foo {…} var resultP = bobP ! foo; GET https://…q=foo

Page 47: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Distributed Secure Currency

$100

$0

$200

var paymentP = myPurse ! makePurse(); paymentP ! deposit(10, myPurse); var goodP = bobP ! buy(desc, paymentP);

buy

$90

$10

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) { return good; }, …

Page 48: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Money as “factorial” of secure coding

function makeMint() { var amp = WeakMap(); return function mint(balance) { var purse = def({ getBalance: function() { return balance; }, makePurse: function() { return mint(0); }, deposit: function(amount, src) { Nat(balance + amount); amp.get(src)(Nat(amount)); balance += amount; } }); function decr(amount) { balance = Nat(balance – amount); } amp.set(purse, decr); return purse; } }

No explicit crypto

Alice Bob buy

makeMint

mint mint purse decr

purse decr purse decr

balance

amp

Page 49: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Causeway Distributed Debugger

Sourcilloscope

Page 50: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Causeway Distributed Debugger

Causality Grid

Page 51: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Causeway Distributed Debugger

Causality Grid at Scale

Page 52: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Authorization by Designation

CapDesk

Page 53: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Authorization by Designation

Belay

Page 54: Secure Distributed Programmingsoft.vub.ac.be/events/mobicrant_talks/talk1_ocaps_js.pdfAjax = Mobile code + async msgs Server Server Frame Frame Browser XHR GET/POST XHR Response XHR

Questions?

Why object-capability (ocap) security? Local ocap security in JavaScript Flexible secure mobile code Distributed crypto-caps in JavaScript Secure distributed programming