Skip to content

Commit b007d20

Browse files
authored
fix(ses-demo): adapt to disabled Date.now() throwing (#2357)
Closes: #XXXX Refs: #910 (comment) #1718 #2354 #910 ## Description While investigating #2354 , I just tried it locally by visiting file:///.../endojs/endo/packages/ses/demos/console/index.html and file:///.../endojs/endo/packages/ses/demos/challenge/index.html in my browser. The first is the SES demo console, which worked just fine. The second is the SES Escape Room, which still relied on the disabled `Date.now()` not throwing. Indeed, before #1718 a disabled (secure mode) `Date.now()` returned `NaN`. But #1718 changed it to throw. What's strange is that in #1718 I revise endojs/endo/packages/ses/demos/challenge/index.html to adjust the text to say that `Date.now()` is "disabled" rather than "NaN". But I didn't fix the escape room code. Although I found this while investigating #2354 , this is a completely distinct bug that is unrelated to #2354 . This PR itself does nothing to fix #2354 . ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations All our docs that link to an explain the Escape Room challenge need to be revisited, especially once #2354 is fixed. For example, https://agoric.com/blog/technology/a-taxonomy-of-security-issues , which I just verified links to the broken page reported at #2354 ### Testing Considerations It is frustrating that the Escape Room is broken at least since #1718 , and also broken by #2354 for an undetermined period of time, without anyone noticing until now. It would be good to bring that site under some kind of automated testing. ### Compatibility Considerations none ### Upgrade Considerations none
1 parent 00f5eab commit b007d20

File tree

1 file changed

+14
-2
lines changed
  • packages/ses/demos/challenge

1 file changed

+14
-2
lines changed

packages/ses/demos/challenge/main.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ lockdown();
250250
return into.slice(0, offset) + char + into.slice(offset + 1, into.length);
251251
}
252252

253+
function dateNow() {
254+
try {
255+
return Date.now();
256+
} catch (err) {
257+
if (err instanceof TypeError) {
258+
// assume we cannot measure time because of err
259+
return NaN;
260+
}
261+
throw err;
262+
}
263+
}
264+
253265
/**
254266
* @param {string} base
255267
* @param {number} offset
@@ -273,9 +285,9 @@ lockdown();
273285
const delays = new Map();
274286
for (let c = 0; c < 36; c++) {
275287
const guessedCode = buildCode(base, offset, c);
276-
const start = Date.now();
288+
const start = dateNow();
277289
guess(guessedCode);
278-
const elapsed = Date.now() - start;
290+
const elapsed = dateNow() - start;
279291
delays.set(toChar(c), elapsed);
280292
yield; // allow UI to refresh
281293
// if our guess was right, then on the last character

0 commit comments

Comments
 (0)