Skip to content

Fix CodeQL password-hash warnings in the SSO samples - #6097

Merged
Eugene (OEvgeny) merged 3 commits into
mainfrom
OEvgeny/fix-codeql-sso-samples-hash
Dec 4, 2026
Merged

Eugene (OEvgeny) merged 3 commits into
mainfrom
OEvgeny/fix-codeql-sso-samples-hash

Conversation

@OEvgeny

@OEvgeny Eugene (OEvgeny) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes CodeQL js/insufficient-password-hash warnings in the SSO samples under samples/07.advanced-web-chat-apps.

Changelog Entry

Fixed

  • 🏫 Fixed SSO samples deriving the PKCE verifier and OAuth state with a fast hash, in PR #6097, by @OEvgeny

Description

The SSO samples derived the PKCE code verifier and the GitHub OAuth state from a seed and a salt with SHA-512/SHA-384, a fast hash that CodeQL flags. They now use Node's built-in async crypto.scrypt, a KDF that the rule recommends. The js/weak-hashes warning on __tests__/setup/NUnitTestReporter.js needs no change: #5416 removed that file.

Design

  • scrypt is deterministic, so every server still derives the same value from the same seed and salt. Cost is explicit (N: 16384), about 25 ms per call, run async on the thread pool so it does not block other requests.
  • PBKDF2 also satisfies the rule; scrypt needs no iteration count.

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.js and oauth/authorize.js routes: async, as restify 11 allows; callback.js routes await the derivation.
Verification (b shown; c, d, e the same)
PKCE  verifier 86 chars ✓ deterministic ✓ seeds differ ✓ RFC 7636 ✓ S256 challenge 43 chars ✓ non-blocking ✓
STATE "30d39c1575" ✓ deterministic ✓ seeds differ ✓ salts differ ✓ 10 hex ✓ non-blocking ✓

Non-blocking: a setImmediate queued before the call fires first (with scryptSync it does not).

  • I have added tests and executed them locally
  • I have added .changelog/<PR#>-<slug>.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

Eugene Olonov 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.
@OEvgeny
Eugene (OEvgeny) enabled auto-merge (squash) December 4, 2026 23:05
@OEvgeny
Eugene (OEvgeny) merged commit 77aa030 into main Dec 4, 2026
46 checks passed
@OEvgeny
Eugene (OEvgeny) deleted the OEvgeny/fix-codeql-sso-samples-hash branch December 4, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants