Skip to content

Commit da829fc

Browse files
autopulatedmarkstos
authored andcommitted
Use crypto.randomBytes for ID generation (#235)
* Use crypto.randomBytes for ID generation Math.random is not cryptographically secure, and IDs generated with it could potentially be predicted. Use crypto.randomBytes instead.
1 parent 305afbd commit da829fc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/passport-saml/saml.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ SAML.prototype.getCallbackUrl = function (req) {
9494
};
9595

9696
SAML.prototype.generateUniqueID = function () {
97-
var chars = "abcdef0123456789";
98-
var uniqueID = "";
99-
for (var i = 0; i < 20; i++) {
100-
uniqueID += chars.substr(Math.floor((Math.random()*15)), 1);
101-
}
102-
return uniqueID;
97+
return crypto.randomBytes(10).toString('hex');
10398
};
10499

105100
SAML.prototype.generateInstant = function () {

test/tests.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)