Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Use random bytes when generating nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasEllul committed Feb 9, 2021
1 parent 977c79f commit e0e080c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Added
- Webhooks types are now exported outside the library [#91](https://github.com/shopify/shopify-node-api/pull/91)
### Fixed
- Use cryptographically random bytes to generate nonce [#98](https://github.com/Shopify/shopify-node-api/pull/98)

## [0.3.1] - 2021-02-03
### Fixed
Expand Down
15 changes: 9 additions & 6 deletions src/utils/nonce.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import crypto from 'crypto';

export default function nonce(): string {
const length = 15;
let nonce = '';
const bytes = crypto.randomBytes(length);

for (let i = 0; i <= 3; i++) {
nonce += Math.round(Number(new Date()) * Math.random());
}
const nonce = bytes
.map((byte) => {
return byte % 10;
})
.join('');

const str = nonce.substr(nonce.length - length);
return str;
return nonce;
}

0 comments on commit e0e080c

Please sign in to comment.