fix: detect crypto with typeof, not optional chaining - #1968
Conversation
`typeof crypto` is safe when the name does not exist. `typeof crypto?.timingSafeEqual` is not: optional chaining still reads the identifier and throws ReferenceError. `randomId` in this file already uses `typeof crypto === 'undefined'`. Use the same check for `constantTimeEqual` so importing Elysia works in environments that have no `crypto` global.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe constant-time cookie comparison fallback now checks whether the global ChangesConstant-time cookie comparison
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This localized change prevents module import failures when crypto is unavailable while preserving the existing fallback behavior; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Disclaimer: AI wrote this, but I vetted it
Summary
constantTimeEqualis initialized at module load with:typeofdoes not protect that. Optional chaining still evaluates the identifier, so a missingcryptoglobal throwsReferenceErrorinstead of taking the string-compare fallback.randomIdin the same file already does this correctly:This change uses that same
typeof cryptocheck:What is not a problem
crypto.subtleinsignCookieonly runs when signing a cookie.crypto.randomUUID()only runs in therandomIdbranch aftertypeof crypto === 'undefined'has already passed.Importing Elysia (and thus
utils.ts) no longer requires acryptoglobal.Summary by CodeRabbit