From E to EcmaScript and back again Mark S. Miller and the - - PowerPoint PPT Presentation

from e to ecmascript and back again
SMART_READER_LITE
LIVE PREVIEW

From E to EcmaScript and back again Mark S. Miller and the - - PowerPoint PPT Presentation

From E to EcmaScript and back again Mark S. Miller and the Cajadores Overview Object-Capabilities Security as extreme modularity Securing JavaScript Why and How? E Caja ES5 SES Dr. SES Patterns of Safe Cooperation In


slide-1
SLIDE 1

From E to EcmaScript and back again

Mark S. Miller and the Cajadores

slide-2
SLIDE 2

Overview

Object-Capabilities

Security as extreme modularity

Securing JavaScript – Why and How?

E  Caja  ES5  SES  Dr. SES

Patterns of Safe Cooperation

In Secure EcmaScript (SES)

Distributed Cryptographic Capabilities

In Distributed Resilient Secure EcmaScript (Dr. SES)

slide-3
SLIDE 3

Security as Extreme Modularity

Modularity: Avoid needless dependencies Security: Avoid needless vulnerabilities Vulnerability is a form of dependency Mod: Principle of info hiding - need to know. Sec: Principle of least authority - need to do.

slide-4
SLIDE 4

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions How might object Bob come to know of object Carol?

slide-5
SLIDE 5

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: bob.foo(carol)

slide-6
SLIDE 6

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: bob.foo(carol)

slide-7
SLIDE 7

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: bob.foo(carol)

slide-8
SLIDE 8

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: bob.foo(carol)

slide-9
SLIDE 9

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: bob.foo(carol)

slide-10
SLIDE 10

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Bob says: var carol = { ... };

slide-11
SLIDE 11

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

Alice says: var bob = { ... carol ... };

slide-12
SLIDE 12

How do I designate thee?

by Introduction

ref to Carol ref to Bob decides to share

by Parenthood by Endowment by Initial Conditions

At t0:

slide-13
SLIDE 13

OCaps: Small step from pure objects

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15

The Mashup problem: 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>

slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19

Improving JavaScript in Stages

EcmaScript 3:

One of the hardest oo languages to secure. Caja: Complex server-side translator. Runtime overhead.

EcmaScript 5:

One of the easiest oo languages to secure. <script src=“initSES.js”></script> Simple client-side init and verifier. No runtime overhead. Approx 3K download compressed.

slide-20
SLIDE 20

Objects as Closures

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

makeCounter count incr incr decr decr count incr incr decr decr count incr incr decr decr

slide-21
SLIDE 21

Objects as Closures

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

makeCounter count incr incr decr decr count incr incr decr decr count incr incr decr decr

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

  • bject of methods hiding instance vars
slide-22
SLIDE 22

Objects as Closures in ES5/strict

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

makeCounter count incr incr decr decr count incr incr decr decr count incr incr decr decr

A tamper-proof record of lexical closures encapsulating state is a defensive object

slide-23
SLIDE 23

Turning ES5 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
slide-24
SLIDE 24

Running ES5 & SES on old browsers

slide-25
SLIDE 25

Future objects on old browsers

slide-26
SLIDE 26

Revocable Function Forwarder

function makeFnCaretaker(target) { return def({ wrapper: function(…args) { return target(…args); }, revoke: function() { target = null; } }); }

makeCaretaker target wrapper wrapper revoke revoke target wrapper wrapper revoke revoke target wrapper wrapper revoke revoke target wrapper wrapper revoke revoke target wrapper wrapper revoke revoke target wrapper wrapper revoke revoke

slide-27
SLIDE 27

Alice

Unconditional Access

Alice says: bob.foo(carol); Bob Carol

foo

Grants Bob full access to Carol forever

slide-28
SLIDE 28

Alice

Revocability ≡ Temporal attenuation

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper);

target wrapper wrapper revoke revoke

Bob Carol

foo

slide-29
SLIDE 29

Alice

Revocability ≡ Temporal attenuation

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //…

target wrapper wrapper revoke revoke

Bob Carol

slide-30
SLIDE 30

Alice Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //… ct.revoke();

target wrapper wrapper revoke revoke

Bob Carol

Revocability ≡ Temporal attenuation

slide-31
SLIDE 31

Alice Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //… ct.revoke();

target wrapper wrapper revoke revoke

Bob Carol

Revocability ≡ Temporal attenuation

slide-32
SLIDE 32

Alice

Attenuators ≡ Access Abstractions

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); Bob Carol Express security policy by the behavior of the objects you provide

foo

slide-33
SLIDE 33

Abstractions extend vocabulary

Primitives Abstraction Forms Extended Vocabulary

+, ., []

procedural abstraction

foo(bar, baz), … int, struct, array

data abstraction

Point, Window, … if, while, switch

control abstraction

addListener, …

points-to access abstraction

caretaker, membrane, …

slide-34
SLIDE 34

Alice

Membranes: Transitive Interposition

function makeFnMembrane(target) { var enabled = true; function wrap(wrapped) { if (wrapped !== Object(wrapped)) { return wrapped; } return function(…args) { if (!enabled) { throw new Error(“revoked”); } return wrap(wrapped(…args.map(wrap)); } } return def({ wrapper: wrap(target), revoke: function() { enabled = false; } }); }

Bob Carol Dave

slide-35
SLIDE 35

Attenuators Compose

function makeROFile(file) { return def({ read: file.read, getLength: file.getLength }); } var rorFile = makeROFile(revocableFile);

slide-36
SLIDE 36

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

slide-37
SLIDE 37

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);

slide-38
SLIDE 38

No powerful references by default

Alice says: Alice bob carol Bob Carol

slide-39
SLIDE 39

Bob Carol bob carol counter

Only connectivity begets connectivity

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

count count count incr incr decr decr

slide-40
SLIDE 40

Bob Carol bob carol counter

Only connectivity begets connectivity

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

count count count incr incr decr decr

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

slide-41
SLIDE 41

Membrane eval → compartment

var compartment = makeMembrane(eval); var vbob = compartment.wrapper(bobSrc);

Alice Bob

slide-42
SLIDE 42

Membrane eval → compartment

var compartment = makeMembrane(eval); var vbob = compartment.wrapper(bobSrc); //…

Alice Bob

slide-43
SLIDE 43

Membrane eval → compartment

var compartment = makeMembrane(eval); var vbob = compartment.wrapper(bobSrc); //… compartment.revoke();

Alice Bob GC

slide-44
SLIDE 44

Composing Authority

+? Usually intersection

slide-45
SLIDE 45

Rights Amplification

≥+ + Authority conditional on other possessions. Enables more expressive power.

slide-46
SLIDE 46

Rights Amplification

function makeBrand() { var amp = WeakMap(); return def({ seal: function(payload) { var box = def({}); amp.set(box, payload); return box; }, unseal: function(box) { return amp.get(box); } }); }

Alice Bob

foo makeBrand amp seal unseal seal unseal payload box payload box payload box amp

slide-47
SLIDE 47

Rights Amplification

function makeBrand() { var amp = WeakMap(); return def({ seal: function(payload) { var box = def({}); amp.set(box, payload); return box; }, unseal: function(box) { return amp.get(box); } }); }

Crypto patterns without crypto makeBrand() generate key pair seal method encryption key unseal method decryption key payload plaintext box cyphertext

slide-48
SLIDE 48
  • Dr. SES

Distributed Resilient Secure EcmaScript

Most suspicion is not within an address space Stretch reference graph between machines Preserve distributed “memory safety”

slide-49
SLIDE 49

Async object ops as JSON/REST ops

Object operations https: JSON/RESTful operations

var result = bob.foo(carol);

local only call

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

slide-50
SLIDE 50

Async object ops as JSON/REST ops

Object operations https: JSON/RESTful operations

var result = bob.foo(carol);

local only call

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

local only get

var resultP = bobP ! foo;

GET https://…q=foo

bobP ! foo = newFoo; PUT https://…q=foo {…} delete bobP ! foo; DELETE http://…q=foo

slide-51
SLIDE 51

Object operations https: JSON/RESTful operations

var result = bob.foo(carol);

local only call

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

local only get

var resultP = bobP ! foo;

GET https://…q=foo

bobP ! foo = newFoo; PUT https://…q=foo {…} delete bobP ! foo; DELETE http://…q=foo

Async object ops as JSON/REST ops

slide-52
SLIDE 52

Object operations https: JSON/RESTful operations

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

GET https://…q=foo

Async object ops as JSON/REST ops

slide-53
SLIDE 53

Async object ops as JSON/REST ops

Object operations https: JSON/RESTful operations

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

GET https://…q=foo

slide-54
SLIDE 54

Async object ops as JSON/REST ops

Object operations https: JSON/RESTful operations

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

GET https://…q=foo

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

Register for notification using

xhr.onreadystatechange = …

slide-55
SLIDE 55

Distributed Secure Currency

$100 $200

slide-56
SLIDE 56

Distributed Secure Currency

$100 $200

var paymentP = myPurse ! makePurse();

slide-57
SLIDE 57

Distributed Secure Currency

$100 $200

var paymentP = myPurse ! makePurse();

slide-58
SLIDE 58

Distributed Secure Currency

$100 $0 $200

var paymentP = myPurse ! makePurse();

slide-59
SLIDE 59

Distributed Secure Currency

$100 $0 $200

var paymentP = myPurse ! makePurse(); paymentP ! deposit(10, myPurse);

slide-60
SLIDE 60

Distributed Secure Currency

$100 $0 $200

var paymentP = myPurse ! makePurse(); paymentP ! deposit(10, myPurse);

slide-61
SLIDE 61

Distributed Secure Currency

$100 $0 $200

var paymentP = myPurse ! makePurse(); paymentP ! deposit(10, myPurse);

$90 $10

slide-62
SLIDE 62

Distributed Secure Currency

$100 $0 $200

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

$90 $10

slide-63
SLIDE 63

Distributed Secure Currency

$100 $0 $200

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

buy

$90 $10

slide-64
SLIDE 64

Distributed Secure Currency

$100 $0 $200

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

$90 $10

return Q.when(paymentP, function(p) {

slide-65
SLIDE 65

Distributed Secure Currency

$100 $0 $200

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

$90 $10

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

slide-66
SLIDE 66

Distributed Secure Currency

$100 $0 $200

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

$90 $10

deposit

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

slide-67
SLIDE 67

Distributed Secure Currency

$100 $0 $200

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

$90 $210

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

slide-68
SLIDE 68

Distributed Secure Currency

$100 $0 $200

var paymentP = myPurse ! makePurse(); paymentP ! deposit(10, myPurse); var goodP = bobP ! buy(desc, paymentP); return Q.when(paymentP, function(p) { return Q.when(myPurse ! deposit(10, p), function(_) { return good; }, …

$90 $210

slide-69
SLIDE 69

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) { var newBal = Nat(balance + amount); amp.get(src)(Nat(amount)); balance = newBal; } }); 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

slide-70
SLIDE 70

The other half of the object revolution

Protect object from world Protect world from object Responsibility driven design Authority driven design Avoid needless coupling Avoid needless vulnerability Information hiding Principle of Least Authority Avoid global variables Forbid mutable static state Procedural, data, control, … …, and access abstractions Patterns and frameworks Patterns of safe cooperation Say what you mean Mean only what you say

slide-71
SLIDE 71

Questions?

slide-72
SLIDE 72

Caja Roadmap

Cajita SES5/3 SES/ES5-strict + Valija ES5/3 Sandboxed ES5-strict + ref_send / server-proxy ref_send / UMP + server-server captp captp / web-sockets + “!” sending sugar Subtotal:

  • Dr. SES5/3
  • Dr. SES

+ Sanitize HTML & CSS + Domita / uncajoled JS Domado / SES = Caja Yesterday Caja Tomorrow Caja on ES5,HTML5