-
Notifications
You must be signed in to change notification settings - Fork 3
Test whatthediff #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces a new React functional component, Changes
TipsChat with CodeRabbit Bot (
|
PR Summary
|
import React, {FC} from 'react'; | ||
import {CSSAssetSchemaRenderDescription} from '../../utils/renderDescriptionSchema'; | ||
import {useDynamicStyle} from '../../hooks/useDynamicStyle'; | ||
|
||
type HTMLContainerProps = CSSAssetSchemaRenderDescription & { | ||
htmlContent: string; | ||
dynamicStyle?: any; | ||
}; | ||
|
||
export const HTMLContainer: FC<HTMLContainerProps> = ({ | ||
htmlContent, | ||
dynamicStyle, | ||
...props | ||
}) => { | ||
const currentFrameStyle = useDynamicStyle(dynamicStyle); | ||
return ( | ||
<div | ||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={{__html: htmlContent}} | ||
style={{...props.style, ...currentFrameStyle}} | ||
/> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/wtd give me a feedback on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import React, {FC} from 'react'; | |
import {CSSAssetSchemaRenderDescription} from '../../utils/renderDescriptionSchema'; | |
import {useDynamicStyle} from '../../hooks/useDynamicStyle'; | |
type HTMLContainerProps = CSSAssetSchemaRenderDescription & { | |
htmlContent: string; | |
dynamicStyle?: any; | |
}; | |
export const HTMLContainer: FC<HTMLContainerProps> = ({ | |
htmlContent, | |
dynamicStyle, | |
...props | |
}) => { | |
const currentFrameStyle = useDynamicStyle(dynamicStyle); | |
return ( | |
<div | |
// eslint-disable-next-line react/no-danger | |
dangerouslySetInnerHTML={{__html: htmlContent}} | |
style={{...props.style, ...currentFrameStyle}} | |
/> | |
); | |
}; | |
import React, { FC } from 'react'; | |
import { CSSAssetSchemaRenderDescription } from '../../utils/renderDescriptionSchema'; | |
import { useDynamicStyle } from '../../hooks/useDynamicStyle'; | |
type HTMLContainerProps = CSSAssetSchemaRenderDescription & { | |
htmlContent: string; | |
dynamicStyle?: any; | |
}; | |
export const HTMLContainer: FC<HTMLContainerProps> = ({ | |
htmlContent, | |
dynamicStyle, | |
...props | |
}) => { | |
const currentFrameStyle = useDynamicStyle(dynamicStyle); | |
return ( | |
<div | |
// eslint-disable-next-line react/no-danger | |
dangerouslySetInnerHTML={{ __html: htmlContent }} | |
style={{ ...props.style, ...currentFrameStyle }} | |
/> | |
); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (1)
- src/components/assetLoader/HTMLContainer.tsx (1 hunks)
Additional comments (Suppressed): 2
src/components/assetLoader/HTMLContainer.tsx (2)
19-20: Using
dangerouslySetInnerHTML
can expose your application to cross-site scripting (XSS) attacks if the HTML content isn't properly sanitized. Ensure thathtmlContent
is always sanitized before it's passed toHTMLContainer
.15-15: The
useDynamicStyle
hook is used here but there's no context provided about its implementation. Make sure it doesn't have side effects that could affect the rendering ofHTMLContainer
.
type HTMLContainerProps = CSSAssetSchemaRenderDescription & { | ||
htmlContent: string; | ||
dynamicStyle?: any; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamicStyle
prop is typed as any
. This could lead to potential type errors or bugs in the future. It would be better to define a more specific type for this prop, if possible.
- dynamicStyle?: any;
+ dynamicStyle?: Record<string, unknown>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using dangerouslySetInnerHTML
safe for this component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alfonsograziano The use of dangerouslySetInnerHTML
can potentially expose your application to cross-site scripting (XSS) attacks if the HTML content is not properly sanitized. This is because it directly inserts HTML content into your component, which could include malicious scripts.
In this case, the safety of using dangerouslySetInnerHTML
depends on the source and handling of the htmlContent
prop. If htmlContent
is always static, controlled by developers, and never includes user input or data from untrusted sources, then it should be safe. However, if htmlContent
can come from an untrusted source or includes user input, it should be sanitized before being passed to dangerouslySetInnerHTML
.
If you need to render user-supplied or otherwise untrusted HTML, consider using a library like DOMPurify to sanitize the HTML content before rendering it.
Here's how you might do that:
import DOMPurify from 'dompurify';
// ...
export const HTMLContainer: FC<HTMLContainerProps> = ({
htmlContent,
dynamicStyle,
...props
}) => {
const currentFrameStyle = useDynamicStyle(dynamicStyle);
const sanitizedHTML = DOMPurify.sanitize(htmlContent);
return (
<div
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: sanitizedHTML}}
style={{...props.style, ...currentFrameStyle}}
/>
);
};
Please note that sanitizing HTML is a complex task and using a well-tested library like DOMPurify is generally safer than trying to do it yourself.
return ( | ||
<div | ||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={{__html: htmlContent}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/wtd is this safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dangerouslySetInnerHTML={{__html: htmlContent}} | |
dangerouslySetInnerHTML={{__html: htmlContent}} |
@coderabbitai show me how to improve this |
Summary by CodeRabbit
HTMLContainer
component in the asset loader. This component allows for rendering HTML content directly within the application, with support for dynamic styling. This enhances the flexibility of content presentation and allows for more complex layouts and designs to be incorporated into the app. Please note that this feature should be used judiciously due to potential security implications associated with rendering raw HTML content.