File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,11 @@ global.urlForTab = {};
3232// This is exported for use by "marks.js".
3333global . tabLoadedHandlers = { } ; // tabId -> function()
3434
35- // A secret, available only within the current instantiation of Vimium. The secret is big, likely unguessable
36- // in practice, but less than 2^31.
37- chrome . storage . local . set ( { vimiumSecret : Math . floor ( Math . random ( ) * 2000000000 ) } ) ;
35+ // A secret, available only within the current instantiation of Vimium, for the duration of the browser
36+ // session. The secret is a generated strong random string.
37+ const randomArray = window . crypto . getRandomValues ( new Uint8Array ( 32 ) ) ; // 32-byte random token.
38+ const secretToken = randomArray . reduce ( ( a , b ) => a . toString ( 16 ) + b . toString ( 16 ) ) ;
39+ chrome . storage . local . set ( { vimiumSecret : secretToken } ) ;
3840
3941const completionSources = {
4042 bookmarks : new BookmarkCompleter ,
Original file line number Diff line number Diff line change 11//
2- // This is a stub for chrome.strorage.sync for testing.
3- // It does what chrome.storage.sync should do (roughly), but does so synchronously .
4- // It also provides stubs for a number of other chrome APIs .
2+ // This file contains stubs for a number of browser and chrome APIs which are missing in
3+ // Node.js .
4+ // The chrome.storage.sync stub does roughly what chrome.storage.sync should do, but does so synchronously .
55//
66
7- let XMLHttpRequest ;
7+ const nodeCrypto = require ( "crypto" ) ;
8+
89global . window = { } ;
910global . localStorage = { } ;
1011
12+ window . crypto = {
13+ // This polyfill was taken from
14+ // https://github.com/KenanY/get-random-values
15+ getRandomValues : ( buffer ) => {
16+ if ( ! ( buffer instanceof Uint8Array ) )
17+ throw new TypeError ( 'expected Uint8Array' ) ;
18+ if ( buffer . length > 65536 )
19+ throw new Error ( "Buffer length cannot be larger than 65536; this API doesn't support that much entropy." ) ;
20+ var bytes = nodeCrypto . randomBytes ( buffer . length ) ;
21+ buffer . set ( bytes ) ;
22+ return buffer ;
23+ }
24+ }
25+
26+ let XMLHttpRequest ;
27+
1128global . navigator =
1229 { appVersion : "5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36" } ;
1330
You can’t perform that action at this time.
0 commit comments