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 = {};
32
32
// This is exported for use by "marks.js".
33
33
global . tabLoadedHandlers = { } ; // tabId -> function()
34
34
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 } ) ;
38
40
39
41
const completionSources = {
40
42
bookmarks : new BookmarkCompleter ,
Original file line number Diff line number Diff line change 1
1
//
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 .
5
5
//
6
6
7
- let XMLHttpRequest ;
7
+ const nodeCrypto = require ( "crypto" ) ;
8
+
8
9
global . window = { } ;
9
10
global . localStorage = { } ;
10
11
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
+
11
28
global . navigator =
12
29
{ appVersion : "5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36" } ;
13
30
You can’t perform that action at this time.
0 commit comments