Skip to content

Commit

Permalink
generate cryptographically secure state token
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jan 13, 2021
1 parent 1721b78 commit f230ea7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions changelog/unreleased/generate-secure-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: generate cryptographically secure state token

Replaced Math.random with a cryptographically secure way to generate the oidc state token using the javascript crypto api.

https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
https://github.com/owncloud/ocis/pull/1203
6 changes: 5 additions & 1 deletion konnectd/ui/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function withClientRequestState(obj) {
obj.state = Math.random().toString(36).substring(7);
// Generate a 16 byte random token
const values = new Uint8Array(16);
crypto.getRandomValues(values);
// Convert the 16 byte to a hex string and assign to the state attribute
obj.state = Array.prototype.map.call(values, x => x.toString(16)).join('');

return obj;
}
Expand Down

0 comments on commit f230ea7

Please sign in to comment.