Replies: 2 comments 4 replies
-
An example would be the following, #3131. I need to clean it up to reintroduce inline styles for people who don't want the progressive enhancement, but this would be a CSP safe implementation of the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just to clarify, the issue here is that your CSP prevents you from using a library that uses inline styles in any capacity. Is that correct? Granted this is not my specialty, but AFAIK nothing we are doing is actually opening you up to XSS attacks. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
I believe Radix could benefit from becoming more security-conscious about its styling and avoiding the use of inline styles entirely. While there have been efforts to support nonces in style tags, if your application is rendered on the client side, or a certain component needs to be, you're out of luck unless you're willing to weaken your CSP. For those who don't know, inline styles can be a potential vector for cross-site scripting (XSS) attacks. Currently, the majority of components within Radix's primitives use inline styles. I'm not saying Radix is creating vulnerabilities, but it shouldn't be the reason people feel they need to lower their security standards, potentially introducing vulnerabilities elsewhere.
I’m proposing a switch to using CSS classes and exporting these classes as part of each package. Consumers who want to remain CSP-conscious would need to import the CSS file for each component that requires one. Most modern build systems, like Webpack and Vite, do a great job of combining CSS files, so I'm not concerned about ending up with 50 different stylesheets.
The majority of these inline styles don’t even depend on the component’s state and could be directly converted into traditional CSS classes. For more complex styles, two or more classes may need to be created, and the component’s state can be used to determine which class to apply. One example of this would be the pointer-event in NavigationMenu. The guideline would be to create two classes, or use a CSS variable to control these values.
In cases where a component’s state directly controls the value of a CSS property, the guideline would be to use CSS variables. I’ve been experimenting with setProperty, but I think manipulating an element’s CSS Object Model (CSSOM) could work as well.
Some open questions I have relate to creating a single source of truth between the existing inline styles and the proposed CSS classes. I’m trying to avoid a major version bump to implement a change like this, opting instead for a progressive enhancement. This has led me to consider how to consolidate the CSS classes with the inline styles so they can coexist until the next major version, where users would need to migrate anyway. If anyone has thoughts on this area, feel free to chime in!
The goal of this post is to gauge interest and see if this is something worth pursuing. I know one of Radix's pillars is ease of use, and this would increase the complexity of using a component, but I think complexity with reason is better than just doing what's easy. Thanks for taking a read, open to suggestions and ideas!
Beta Was this translation helpful? Give feedback.
All reactions