Skip to content

Commit 7a547fc

Browse files
authored
Merge pull request #96 from AuthorizeNet/security-fix
Fix code scanning alert no. 2: Insecure randomness
2 parents 833a662 + 577ffbb commit 7a547fc

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

test/test-transactionreporting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('Transaction Reporting', function() {
135135

136136
var getRequest = new ApiContracts.GetTransactionListForCustomerRequest();
137137
getRequest.setMerchantAuthentication(testData.merchantAuthenticationType);
138-
getRequest.setCustomerProfileId('922287204');
138+
getRequest.setCustomerProfileId('39931060');
139139

140140
//console.log(JSON.stringify(getRequest.getJSON(), null, 2));
141141

test/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
'use strict';
22

3+
const crypto = require('crypto');
4+
35
function getRandomString(text){
4-
return text + Math.floor((Math.random() * 100000) + 1);
6+
const randomInt = crypto.randomBytes(4).readUInt32BE(0);
7+
return text + randomInt;
58
}
69

710
function getRandomInt(){
8-
return Math.floor((Math.random() * 100000) + 1);
11+
return crypto.randomBytes(4).readUInt32BE(0);
912
}
1013

1114
function getRandomAmount(){
12-
return ((Math.random() * 1000) + 1).toFixed(2);
15+
const randomFloat = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF;
16+
return ((randomFloat * 1000) + 1).toFixed(2);
1317
}
1418

1519
function getDate(){

0 commit comments

Comments
 (0)