Summary
The generatePKCEPair function in lib/utils/generateAuthUrl.ts has two related issues identified during the code review of PR #192:
1. Insufficient crypto.subtle guard
The current production guard only checks if (!crypto), but the else branch directly calls crypto.subtle.digest() without verifying that crypto.subtle itself exists. If crypto is defined but crypto.subtle is undefined (e.g. in certain non-browser environments or older runtimes), this will throw a runtime error.
Fix: Update the guard to fully validate Web Crypto availability before use:
typeof crypto !== 'undefined' && crypto && crypto.subtle && typeof crypto.subtle.digest === 'function'
2. PKCE protocol violation on fallback path
When the no-crypto fallback executes, codeChallenge is produced via base64UrlEncode(codeVerifier) (a plain encoding), but the auth flow continues to send code_challenge_method=S256. This is a violation of the PKCE specification (RFC 7636) — S256 should only be sent when the challenge is the SHA-256 hash of the verifier.
Fix: Return the appropriate code_challenge_method value from generatePKCEPair ("S256" for the hash path, "plain" for the fallback), and ensure the auth URL construction uses the returned value.
References
Requested by
@pesickaa
Summary
The
generatePKCEPairfunction inlib/utils/generateAuthUrl.tshas two related issues identified during the code review of PR #192:1. Insufficient
crypto.subtleguardThe current production guard only checks
if (!crypto), but theelsebranch directly callscrypto.subtle.digest()without verifying thatcrypto.subtleitself exists. Ifcryptois defined butcrypto.subtleis undefined (e.g. in certain non-browser environments or older runtimes), this will throw a runtime error.Fix: Update the guard to fully validate Web Crypto availability before use:
2. PKCE protocol violation on fallback path
When the no-crypto fallback executes,
codeChallengeis produced viabase64UrlEncode(codeVerifier)(a plain encoding), but the auth flow continues to sendcode_challenge_method=S256. This is a violation of the PKCE specification (RFC 7636) —S256should only be sent when the challenge is the SHA-256 hash of the verifier.Fix: Return the appropriate
code_challenge_methodvalue fromgeneratePKCEPair("S256"for the hash path,"plain"for the fallback), and ensure the auth URL construction uses the returned value.References
Requested by
@pesickaa