File tree Expand file tree Collapse file tree 4 files changed +17
-42
lines changed
Expand file tree Collapse file tree 4 files changed +17
-42
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " api " : patch
3+ ---
4+
5+ Use secure RNG on callback function names.
Original file line number Diff line number Diff line change @@ -7,27 +7,12 @@ declare global {
77 }
88}
99
10- function s4 ( ) : string {
11- return Math . floor ( ( 1 + Math . random ( ) ) * 0x10000 )
12- . toString ( 16 )
13- . substring ( 1 )
14- }
15-
1610function uid ( ) : string {
17- return (
18- s4 ( ) +
19- s4 ( ) +
20- '-' +
21- s4 ( ) +
22- '-' +
23- s4 ( ) +
24- '-' +
25- s4 ( ) +
26- '-' +
27- s4 ( ) +
28- s4 ( ) +
29- s4 ( )
30- )
11+ const length = new Int8Array ( 1 )
12+ window . crypto . getRandomValues ( length )
13+ const array = new Uint8Array ( Math . max ( 16 , Math . abs ( length [ 0 ] ) ) )
14+ window . crypto . getRandomValues ( array )
15+ return array . join ( '' )
3116}
3217
3318function transformCallback (
Original file line number Diff line number Diff line change @@ -7,29 +7,14 @@ if (!String.prototype.startsWith) {
77}
88
99( function ( ) {
10- function s4 ( ) {
11- return Math . floor ( ( 1 + Math . random ( ) ) * 0x10000 )
12- . toString ( 16 )
13- . substring ( 1 ) ;
10+ function uid ( ) {
11+ const length = new Int8Array ( 1 )
12+ window . crypto . getRandomValues ( length )
13+ const array = new Uint8Array ( Math . max ( 16 , Math . abs ( length [ 0 ] ) ) )
14+ window . crypto . getRandomValues ( array )
15+ return array . join ( '' )
1416 }
1517
16- var uid = function ( ) {
17- return (
18- s4 ( ) +
19- s4 ( ) +
20- "-" +
21- s4 ( ) +
22- "-" +
23- s4 ( ) +
24- "-" +
25- s4 ( ) +
26- "-" +
27- s4 ( ) +
28- s4 ( ) +
29- s4 ( )
30- ) ;
31- } ;
32-
3318 function ownKeys ( object , enumerableOnly ) {
3419 var keys = Object . keys ( object ) ;
3520 if ( Object . getOwnPropertySymbols ) {
You can’t perform that action at this time.
0 commit comments