Skip to content

feat: add nonce support to genStyleUtils for CSP compliance#38

Merged
zombieJ merged 1 commit intomasterfrom
fix/gen-cssvar-register-nonce
Mar 4, 2026
Merged

feat: add nonce support to genStyleUtils for CSP compliance#38
zombieJ merged 1 commit intomasterfrom
fix/gen-cssvar-register-nonce

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 4, 2026

Pass CSP nonce to useCSSVarRegister when registering CSS variables. This ensures dynamically generated style tags include the nonce attribute when Content Security Policy is enabled.

Also updated @ant-design/cssinjs dependency to ^2.1.2 and fixed React import.

Pass CSP nonce to useCSSVarRegister when registering CSS variables.
This ensures dynamically generated style tags include the nonce attribute
when Content Security Policy is enabled.

Also updated @ant-design/cssinjs dependency to ^2.1.2 and fixed React import.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Warning

Rate limit exceeded

@zombieJ has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 72ca5585-8fb5-4c0a-b2e1-84252089730c

📥 Commits

Reviewing files that changed from the base of the PR and between 62ae62d and 124884e.

📒 Files selected for processing (3)
  • package.json
  • src/util/genStyleUtils.ts
  • tests/genStyleUtils.test.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gen-cssvar-register-nonce

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (62ae62d) to head (124884e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage   90.39%   90.46%   +0.06%     
==========================================
  Files          11       11              
  Lines         302      304       +2     
  Branches       74       74              
==========================================
+ Hits          273      275       +2     
  Misses         29       29              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit 461648c into master Mar 4, 2026
7 of 8 checks passed
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 enhances the styling utility by integrating Content Security Policy (CSP) nonce support, which is crucial for applications with strict security requirements. It ensures that all dynamically injected styles are compliant with CSP rules, thereby preventing potential cross-site scripting vulnerabilities. Additionally, it includes an update to a core styling dependency and a minor refactor of a React import.

Highlights

  • CSP Nonce Support: Implemented Content Security Policy (CSP) nonce support within genStyleUtils to ensure dynamically generated style tags include the necessary nonce attribute for enhanced security.
  • Dependency Update: Updated the @ant-design/cssinjs dependency to version ^2.1.2.
  • React Import Refinement: Adjusted the React import statement in genStyleUtils.ts for better type handling.
  • Unit Testing: Added a dedicated test case to validate the correct propagation and application of the CSP nonce to style tags.

🧠 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
  • package.json
    • Updated @ant-design/cssinjs dependency from ^2.1.0 to ^2.1.2.
  • src/util/genStyleUtils.ts
    • Changed React import from import React, { useMemo } from 'react'; to import type React from 'react'; import { useMemo } from 'react';.
    • Introduced useCSP() hook to retrieve CSP nonce.
    • Passed the retrieved nonce to the useCSSVarRegister function for dynamic style tags.
  • tests/genStyleUtils.test.tsx
    • Added a test case to ensure nonce is correctly passed to useCSSVarRegister and applied to generated style tags.
Activity
  • The pull request was created by zombieJ to add nonce support for CSP compliance and update a dependency.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully adds nonce support to genStyleUtils for CSP compliance, which is a valuable security enhancement. The dependency update for @ant-design/cssinjs is minor and the change to type-only React import is a good practice. A comprehensive test case has been added to validate the nonce functionality.

ignore,
token: realToken,
scope: rootCls,
nonce: () => csp.nonce!,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The non-null assertion operator ! on csp.nonce! can be misleading here. The useCSP hook, especially its default implementation useDefaultCSP, can return an object where nonce is undefined. While () => undefined might be handled gracefully by useCSSVarRegister, it's generally better to avoid ! when nullability is possible to improve type safety clarity. Consider passing csp.nonce directly or providing a default if useCSSVarRegister strictly expects a string when the nonce property is present.

Suggested change
nonce: () => csp.nonce!,
nonce: () => csp.nonce,

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.

1 participant