Fixes #848 - Use more secure PRNG

Math.random() is not cryptogaphically secure, but the crypto-random-string
package provides what is needed with a cryptographically secure pseudo-random
number generator.
This commit is contained in:
Brian Mearns
2019-10-01 21:29:42 -04:00
parent 4f29f7c3a7
commit 054901cb79
3 changed files with 18834 additions and 10 deletions

18828
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -47,6 +47,7 @@
}, },
"dependencies": { "dependencies": {
"@braintree/sanitize-url": "^3.1.0", "@braintree/sanitize-url": "^3.1.0",
"crypto-random-string": "^3.0.1",
"d3": "^5.7.0", "d3": "^5.7.0",
"dagre-d3-renderer": "^0.5.8", "dagre-d3-renderer": "^0.5.8",
"dagre-layout": "^0.8.8", "dagre-layout": "^0.8.8",

View File

@@ -1,4 +1,5 @@
import _ from 'lodash'; import _ from 'lodash';
import randomString from 'crypto-random-string';
import { logger } from '../../logger'; import { logger } from '../../logger';
@@ -9,17 +10,11 @@ let curBranch = 'master';
let direction = 'LR'; let direction = 'LR';
let seq = 0; let seq = 0;
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function getId() { function getId() {
const pool = '0123456789abcdef'; return randomString({
let id = ''; length: 7,
for (let i = 0; i < 7; i++) { characters: '0123456789abcdef'
id += pool[getRandomInt(0, 16)]; });
}
return id;
} }
function isfastforwardable(currentCommit, otherCommit) { function isfastforwardable(currentCommit, otherCommit) {