Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair demo console and challenge pages #590

Merged
merged 8 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ User-visible changes in SES:
passed through to the underlying `JSON.stringfiy`. Passing in a space or
two spaces makes the output much more readable using indentation and other
whitespace, but takes multiple lines.
* The "SES Demo Console" and "SES Challenge" have been fixed to work with
modern SES. Both now run in browsers, though these are not yet hosted
for visiting as an external web page.
* We no longer enable overriding `Object.prototype.constructor` by assigning
to the `constructor` property of a derived object. We were enabling it
due to a bug in acorn 7, since fixed in acorn 8. To enable it, we were
making `Object.prototype.constructor` into an accessor property, which
confused the Node debugger, causing annoying extra noise in the console
output. Now that we've worked around our acorn problem (currently with
a patch) we have stopped enabling this assignment, and so stopped
confusing the Node debugger.

## Release 0.12.2 (5-Feb-2021)

Expand Down
5 changes: 3 additions & 2 deletions packages/ses/demos/challenge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ <h2>Sample Attacks:</h2>
<li><button id="sample-counter" type="button">Counter</button></li>
<li><button id="sample-timing" type="button">Timing Side-Channel</button></li>
</ul>
<p>(<a href="https://github.com/Agoric/ses-shim/tree/master/apps/challenge">challenge source code</a>)</p>
<p>(<a href="https://github.com/Agoric/SES-shim/tree/master/packages/ses/demos/challenge">challenge source code</a>)</p>
<script src="../../dist/lockdown.umd.js"></script>
<script src="main.js"></script>
</body>
</html>
</html>
35 changes: 12 additions & 23 deletions packages/ses/demos/challenge/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@
// limit attacker to some finite number of calls per go()
// framework updates UI (with setTimeout(0)), then calls go() again

import('../../dist/ses.esm.js').then(({ lockdown }) => {
lockdown();
{
console.log('starting');

// Helpers

function $(selector) {
return document.querySelector(selector);
}
// function $$(selector) {
// return document.querySelectorAll(selector);
// }
const $ = selector => document.querySelector(selector);

// ********************
// 1. We build the SES Realm.
// 1. Should we endow the real `Date`?
// ********************

const dateTaming = window.location.search.includes('dateNow=enabled')
? 'unsafe'
: 'safe';
$('#dateNowStatus').textContent =
dateTaming === 'unsafe' ? 'Date.now() enabled' : 'Date.now() returns NaN';
erights marked this conversation as resolved.
Show resolved Hide resolved
lockdown({ dateTaming });
const urlsp = new URLSearchParams(window.location.search);
const nowEnabled = urlsp.get('dateNow') === 'enabled';
const dateEndowment = nowEnabled ? { Date } : {};
$('#dateNowStatus').textContent = nowEnabled
? 'Date.now() enabled'
: 'Date.now() disabled';

// ********************
// 2. We prepare APIs for the defender code.
Expand Down Expand Up @@ -149,15 +145,8 @@ import('../../dist/ses.esm.js').then(({ lockdown }) => {
return true;
}

const tamedConsole = {
log() {
return console.log();
},
};

harden(tamedConsole);
harden(guess);
const compartent = new Compartment({ console: tamedConsole, guess });
const compartent = new Compartment({ console, guess, ...dateEndowment });

function submitProgram(program) {
// the attacker's code will be submitted here. We expect it to be a
Expand Down Expand Up @@ -297,6 +286,6 @@ import('../../dist/ses.esm.js').then(({ lockdown }) => {
});

console.log('loaded');
});
}

/* eslint-enable no-plusplus */
15 changes: 8 additions & 7 deletions packages/ses/demos/console/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>SES Console</title>
<title>SES Demo Console</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<h1>SES Console</h1>
<h1>SES Demo Console</h1>
<label>Input:</label>
<br/>
<textarea id="input" rows="25" cols="80">
Expand All @@ -18,9 +18,9 @@ <h1>SES Console</h1>
const x = 0;
const c1 = new Compartment({ x: 1 });
const c2 = new Compartment({ x: 2 });
const x1 = c1.evaluate('(x)');
const x2 = c2.evaluate('(x)');

const x1 = c1.evaluate('x');
const x2 = c2.evaluate('x');
/**
* This line below will output 3 values to demonstrate that
* x has a different value in every context:
Expand All @@ -29,7 +29,7 @@ <h1>SES Console</h1>
* - 2 in compartment #2
*/
({ x, x1, x2 })

</textarea>
<br />
<button id="execute">Execute</button>
Expand All @@ -43,6 +43,7 @@ <h1>SES Console</h1>
Note: you can look in the console to inspect the original output of the evaluation.
</small>
</p>
<script src="../../dist/lockdown.umd.js"></script>
<script src="main.js"></script>
</body>
</html>
</html>
29 changes: 12 additions & 17 deletions packages/ses/demos/console/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* globals document */
import('../../dist/ses.esm.js').then(({ lockdown }) => {
lockdown();

lockdown();
{
const { quote: q } = assert;

const $ = selector => document.querySelector(selector);

Expand All @@ -9,34 +11,27 @@ import('../../dist/ses.esm.js').then(({ lockdown }) => {
const input = $('#input');
const output = $('#output');

const compartment = new Compartment();
// Under the default `lockdown` settings, it is safe enough
// to endow with the safe `console`.
const compartment = new Compartment({ console });

execute.addEventListener('click', () => {
const sourceText = input.value;
let result;
let outputText;
try {
result = compartment.evaluate(sourceText);
switch (typeof result) {
case 'function':
outputText = result.toString();
break;
case 'object':
outputText = JSON.stringify(result);
break;
default:
outputText = `${result}`;
}
console.log(result);
outputText = `${q(result, ' ')}`;
} catch (e) {
outputText = `${e}`;
console.log('threw', e);
outputText = `threw ${q(e)}`;
}

console.log(result);
output.value = outputText;
});

clear.addEventListener('click', () => {
input.value = '';
output.value = '';
});
});
}
4 changes: 2 additions & 2 deletions packages/ses/demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<h1>SES Demos</h1>
<ul>
<li>
<a href="./console">SES Console</a>: a REPL to help you debug code running in SES.
<a href="./console">SES Demo Console</a>: a REPL to help you debug code running in SES.
</li>
<li>
<a href="./challenge">SES Challenge</a>: try to break out of SES and read a secret!
</li>
</ul>
</body>
</html>
</html>