Repository navigation
Fix CodeQL password-hash warnings in the SSO samples - #6097
Merged
Merged
Conversation
added 2 commits
December 3, 2026 11:16
CodeQL js/insufficient-password-hash flagged the SSO samples under 07.advanced-web-chat-apps for deriving the PKCE code verifier and the GitHub OAuth "state" from a seed and a salt with a fast hash (SHA-512 / SHA-384). Derive them with crypto.scryptSync (N: 16384) instead. scrypt is deterministic for the same seed and salt, so any server instance still recomputes the same verifier or state, as the samples' distributed design requires. - createPKCECodeVerifier.js (b, c, d, e): 64 bytes, encoded with Node's base64url (86 characters). The previous encoder left a trailing "=", which is outside the RFC 7636 verifier alphabet. - generateOAuthState.js (b, c, d, e): 5 bytes as hex, still 10 characters. c, d and e carry identical copies of this helper, changed the same way. createPKCECodeChallenge.js (SHA-256 of the verifier, required by S256) is unchanged.
Eugene (OEvgeny)
marked this pull request as ready for review
December 4, 2026 22:32
Eugene (OEvgeny)
requested review from
William Wong (compulim),
Chris Whitten (cwhitten) and
Thomas Durnford (tdurnford)
as code owners
December 4, 2026 22:32
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Public OAuth handlers use memory-hard scryptSync on the event loop, blocking unrelated server traffic during login requests.
1 open issue
What changed in this PR
Updates the four SSO samples to address CodeQL password-hash warnings while preserving deterministic derivation.
Changes:
- Replaces SHA-based derivation with scrypt for PKCE verifiers and OAuth state.
- Produces unpadded, 86-character PKCE verifiers and preserves 10-character hexadecimal state.
- Adds a changelog entry.
| File | Description |
|---|---|
samples/07.advanced-web-chat-apps/e.sso-on-behalf-of-authentication/rest-api/src/utils/generateOAuthState.js |
Uses scrypt for OAuth state. |
samples/07.advanced-web-chat-apps/e.sso-on-behalf-of-authentication/rest-api/src/routes/aad/oauth/createPKCECodeVerifier.js |
Uses scrypt and unpadded base64url. |
samples/07.advanced-web-chat-apps/d.sso-for-teams/web/src/utils/generateOAuthState.js |
Uses scrypt for OAuth state. |
samples/07.advanced-web-chat-apps/d.sso-for-teams/web/src/routes/oauth/createPKCECodeVerifier.js |
Uses scrypt and unpadded base64url. |
samples/07.advanced-web-chat-apps/c.sso-for-intranet/web/src/utils/generateOAuthState.js |
Uses scrypt for OAuth state. |
samples/07.advanced-web-chat-apps/c.sso-for-intranet/web/src/routes/oauth/createPKCECodeVerifier.js |
Uses scrypt and unpadded base64url. |
samples/07.advanced-web-chat-apps/b.sso-for-enterprise/rest-api/src/utils/generateOAuthState.js |
Uses scrypt for OAuth state. |
samples/07.advanced-web-chat-apps/b.sso-for-enterprise/rest-api/src/routes/aad/oauth/createPKCECodeVerifier.js |
Uses scrypt and unpadded base64url. |
.changelog/6097-fix-codeql-sso-samples-hash.md |
Documents the sample changes. |
Review effort: Balanced
crypto.scryptSync blocked the event loop for tens of milliseconds on every OAuth authorize and callback request, stalling unrelated server traffic. Derive with crypto.scrypt (promisified; same N: 16384, length and encoding, so the output is unchanged) and await it in every caller: - createPKCECodeVerifier.js, generateOAuthState.js (b, c, d, e): async. - createPKCECodeChallenge.js (b, c, d, e): async, awaits the verifier. - aad/oauth/authorize.js (b), oauth/authorize.js (c, d) and github/oauth/authorize.js (b): async (_, res) handlers, the form restify 11 accepts without next(), as directLine/token.js already uses. - The oauth/callback.js handlers (b, c, d, e) and github/oauth/callback.js (b) were already async and now await the derivation. lint-staged's prettier also reflowed one untouched statement in each of b's and e's aad/oauth/callback.js and b's github/oauth/authorize.js.
William Wong (compulim)
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Changelog Entry
Fixed
Description
The SSO samples derived the PKCE code verifier and the GitHub OAuth
statefrom a seed and a salt with SHA-512/SHA-384, a fast hash that CodeQL flags. They now use Node's built-in asynccrypto.scrypt, a KDF that the rule recommends. Thejs/weak-hasheswarning on__tests__/setup/NUnitTestReporter.jsneeds no change: #5416 removed that file.Design
N: 16384), about 25 ms per call, run async on the thread pool so it does not block other requests.Specific Changes
createPKCECodeVerifier.js(b, c, d, e): 64 scrypt bytes as base64url (86 characters); the old encoder left a trailing=, which RFC 7636 does not allow.generateOAuthState.js(b, c, d, e): 5 scrypt bytes, still 10 hex characters.createPKCECodeChallenge.jsandoauth/authorize.jsroutes: async, as restify 11 allows;callback.jsroutes await the derivation.Verification (b shown; c, d, e the same)
Non-blocking: a
setImmediatequeued before the call fires first (withscryptSyncit does not)..changelog/<PR#>-<slug>.mdReview Checklist
z-index)package.jsonandpackage-lock.jsonreviewed