Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6097-fix-codeql-sso-samples-hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- 🏫 Fixed SSO samples deriving the PKCE verifier and OAuth state with a fast hash, in PR [#6097](https://github.com/microsoft/BotFramework-WebChat/pull/6097), by [@OEvgeny](https://github.com/OEvgeny)
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { createHash } = require('crypto');
const encodeBase64URL = require('../../../encodeBase64URL');
const { scryptSync } = require('crypto');

const { AAD_OAUTH_PKCE_SALT } = process.env;

// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
module.exports = seed => {
const hash = createHash('sha512');
// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

hash.update(seed);
hash.update(AAD_OAUTH_PKCE_SALT);
// 64 bytes are 86 base64url characters, within the 43–128 characters required by RFC 7636.
const VERIFIER_BYTES = 64;

return encodeBase64URL(hash.digest());
};
// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
// scrypt is deterministic: every server with the same salt derives the same verifier.
module.exports = seed => scryptSync(seed, AAD_OAUTH_PKCE_SALT, VERIFIER_BYTES, SCRYPT_OPTIONS).toString('base64url');
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const crypto = require('crypto');

// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

// 5 bytes are 10 hex characters.
const STATE_BYTES = 5;

// For additional security, GitHub recommends using a "state" parameter that is only known to the servers and never passed to the client.
// We are using a well-known salt to create the "state" parameter for distributed knowledge.
// scrypt is deterministic: every server with the same salt derives the same state.
module.exports = function generateOAuthState(seed, salt) {
const hash = crypto.createHash('sha384');

hash.update(seed);
hash.update(salt);

return hash.digest('hex').substr(0, 10);
return crypto.scryptSync(seed, salt, STATE_BYTES, SCRYPT_OPTIONS).toString('hex');
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { createHash } = require('crypto');
const encodeBase64URL = require('../../encodeBase64URL');
const { scryptSync } = require('crypto');

const { OAUTH_PKCE_SALT } = process.env;

// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
module.exports = seed => {
const hash = createHash('sha512');
// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

hash.update(seed);
hash.update(OAUTH_PKCE_SALT);
// 64 bytes are 86 base64url characters, within the 43–128 characters required by RFC 7636.
const VERIFIER_BYTES = 64;

return encodeBase64URL(hash.digest());
};
// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
// scrypt is deterministic: every server with the same salt derives the same verifier.
module.exports = seed => scryptSync(seed, OAUTH_PKCE_SALT, VERIFIER_BYTES, SCRYPT_OPTIONS).toString('base64url');
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const crypto = require('crypto');

// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

// 5 bytes are 10 hex characters.
const STATE_BYTES = 5;

// For additional security, GitHub recommends using a "state" parameter that is only known to the servers and never passed to the client.
// We are using a well-known salt to create the "state" parameter for distributed knowledge.
// scrypt is deterministic: every server with the same salt derives the same state.
module.exports = function generateOAuthState(seed, salt) {
const hash = crypto.createHash('sha384');

hash.update(seed);
hash.update(salt);

return hash.digest('hex').substr(0, 10);
return crypto.scryptSync(seed, salt, STATE_BYTES, SCRYPT_OPTIONS).toString('hex');
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { createHash } = require('crypto');
const encodeBase64URL = require('../../encodeBase64URL');
const { scryptSync } = require('crypto');

const { OAUTH_PKCE_SALT } = process.env;

// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
module.exports = seed => {
const hash = createHash('sha512');
// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

hash.update(seed);
hash.update(OAUTH_PKCE_SALT);
// 64 bytes are 86 base64url characters, within the 43–128 characters required by RFC 7636.
const VERIFIER_BYTES = 64;

return encodeBase64URL(hash.digest());
};
// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
// scrypt is deterministic: every server with the same salt derives the same verifier.
module.exports = seed => scryptSync(seed, OAUTH_PKCE_SALT, VERIFIER_BYTES, SCRYPT_OPTIONS).toString('base64url');
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const crypto = require('crypto');

// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

// 5 bytes are 10 hex characters.
const STATE_BYTES = 5;

// For additional security, GitHub recommends using a "state" parameter that is only known to the servers and never passed to the client.
// We are using a well-known salt to create the "state" parameter for distributed knowledge.
// scrypt is deterministic: every server with the same salt derives the same state.
module.exports = function generateOAuthState(seed, salt) {
const hash = crypto.createHash('sha384');

hash.update(seed);
hash.update(salt);

return hash.digest('hex').substr(0, 10);
return crypto.scryptSync(seed, salt, STATE_BYTES, SCRYPT_OPTIONS).toString('hex');
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { createHash } = require('crypto');
const encodeBase64URL = require('../../../encodeBase64URL');
const { scryptSync } = require('crypto');

const { AAD_OAUTH_PKCE_SALT } = process.env;

// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
module.exports = seed => {
const hash = createHash('sha512');
// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

hash.update(seed);
hash.update(AAD_OAUTH_PKCE_SALT);
// 64 bytes are 86 base64url characters, within the 43–128 characters required by RFC 7636.
const VERIFIER_BYTES = 64;

return encodeBase64URL(hash.digest());
};
// Creating a PKCE code verifier based on salt and seed.
// We are using seed and salt to simplify the creation of PKCE code in a distributed manner.
// scrypt is deterministic: every server with the same salt derives the same verifier.
module.exports = seed => scryptSync(seed, AAD_OAUTH_PKCE_SALT, VERIFIER_BYTES, SCRYPT_OPTIONS).toString('base64url');
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const crypto = require('crypto');

// scrypt cost, set explicitly so every server derives with the same cost.
const SCRYPT_OPTIONS = Object.freeze({ N: 16384 });

// 5 bytes are 10 hex characters.
const STATE_BYTES = 5;

// For additional security, GitHub recommends using a "state" parameter that is only known to the servers and never passed to the client.
// We are using a well-known salt to create the "state" parameter for distributed knowledge.
// scrypt is deterministic: every server with the same salt derives the same state.
module.exports = function generateOAuthState(seed, salt) {
const hash = crypto.createHash('sha384');

hash.update(seed);
hash.update(salt);

return hash.digest('hex').substr(0, 10);
return crypto.scryptSync(seed, salt, STATE_BYTES, SCRYPT_OPTIONS).toString('hex');
};
Loading