Skip to content

Commit

Permalink
Fixes to endowment safety example (#102)
Browse files Browse the repository at this point in the history
* Fixes to endowment safety example
Tried evaluating the example in the docs and found it was missing a few calls, and replacing the `toString` of `Function.prototype` rather than `Object.prototype`.
  • Loading branch information
mappum authored and katelynsills committed Apr 2, 2019
1 parent d3bd27a commit 18b937d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function makeConsole() {
}
}

const newConsole = s.evaluate(`(${makeConsole})`, {consoleEndowment: console});
const newConsole = s.evaluate(`(${makeConsole}())`, {consoleEndowment: console});
s.evaluate('console.log(4)', { console: newConsole });
```

Expand All @@ -87,8 +87,8 @@ function evil() {
outerObject.__proto__.toString = obj => 'haha';
}
s.evaluate(`(${evil})`, { consoleEndowment: console });
{}.toString(); // prints 'haha'
s.evaluate(`(${evil}())`, { consoleEndowment: console });
(()=>{}).toString(); // prints 'haha'
```

The key is that we evaluate trusted code to generate the safe endowment, and only pass the safe endowment to the untrusted code. Every object in the system should be examined to identify which realm it is coming from (outer or inner), and never ever reveal outer-realm objects to untrusted code. Even passing a collection of safe inner-realm objects to untrusted code enables a confinement breach:
Expand Down

0 comments on commit 18b937d

Please sign in to comment.