feat: Add nonce support for css-variables - #255
Conversation
- Extract injectCSPNonce helper function to unify nonce injection logic - Add nonce parameter support to useCacheToken hook with type definition - Add nonce parameter support to useCSSVarRegister hook - Refactor useStyleRegister to use new injectCSPNonce helper - Add comprehensive tests for nonce functionality (string and function types) This provides better CSP security by allowing nonce configuration for style elements.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthrough该拉取请求在CSS变量注册流程中添加了CSP随机数(nonce)支持。通过引入新的Nonce类型和injectCSPNonce辅助函数,在useCSSVarRegister、useCacheToken和useStyleRegister等hooks中注入CSP nonce,并为相关场景添加了测试用例。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 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. ✨ 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 |
|
🎊 PR Preview ede79c0 has been successfully built and deployed to https://ant-design-cssinjs-preview-pr-255.surge.sh 🕐 Build time: 99.856s 🤖 By surge-preview |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #255 +/- ##
==========================================
+ Coverage 94.65% 94.74% +0.09%
==========================================
Files 32 32
Lines 2823 2873 +50
Branches 448 450 +2
==========================================
+ Hits 2672 2722 +50
Misses 151 151 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the security posture of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces CSP nonce support for CSS variables, which is a great security enhancement. The changes are well-structured: a new injectCSPNonce utility is created to centralize the logic, and this helper is used consistently across useCacheToken, useCSSVarRegister, and useStyleRegister. The addition of comprehensive tests for the nonce functionality is also a valuable contribution. I have one minor suggestion to make the new injectCSPNonce helper more robust for future use.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Change injectCSPNonce from mutating to returning new object - Follow functional programming principles - Preserve existing csp config with spread operator - Update all call sites to use returned value

Summary
This PR adds CSP nonce support for better security when using CSS variables in cssinjs.
Changes
injectCSPNoncehelper: New utility function to unify nonce injection logic across all hooksuseCacheToken: Addnonceparameter support with TypeScript type definition (stringor(() => string))useCSSVarRegister: Addnonceparameter supportuseStyleRegister: Refactor to use the newinjectCSPNoncehelper instead of inline nonce handlinguseCacheTokenanduseCSSVarRegisterhooksBenefits
Example Usage
Summary by CodeRabbit
发布说明
新功能
测试