fix(pkce): use rejection sampling to remove modulo bias#171
Conversation
🦋 Changeset detectedLatest commit: 1eada24 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a changeset file and modifies PKCE verifier generation to remove modulo-based bias: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Stack: security-codeql-fixes Part of a stacked PR chain. Do not merge manually. |
The naive `byte % CHARSET.length` loop over-represents the first 58 characters of the 66-entry PKCE charset by ~33% because 256 is not a multiple of 66. Switch to rejection sampling so every character is equally likely. Flagged by CodeQL (js/biased-cryptographic-random).
67a57a1 to
1eada24
Compare
Summary
byte % CHARSET.lengthingenerateCodeVerifierwith rejection sampling. The 66-character PKCE charset does not divide evenly into 256, so the naive modulo biased the first 58 characters to appear ~33% more often than the last 8.js/biased-cryptographic-random.Test plan
bun test packages/cli-core/src/lib/pkce.test.tsbun run typecheck