-
Notifications
You must be signed in to change notification settings - Fork 429
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
fix: Sanitize HTML tooltips #2538
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Uffizzi Preview |
frontend/web/components/Toolip.js
Outdated
@@ -16,7 +16,7 @@ const Tooltip = class extends React.Component { | |||
<span className='ion ion-ios-help' data-for={this.id} data-tip /> | |||
)} | |||
<ReactTooltip | |||
html | |||
html={false} |
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.
We only want to disable html for some usages, a lot of the times we use tooltips e.g. permissions uses html for tooltip content.
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.
Implementing DOMPurify to sanitize the tooltip content since it removes XSS scripts but not HTML content.
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.
As per our conversation, proceeded to HTML encode the tag labels to escape HTML and display content as plain text.
Also, converted Tooltip code to Typescript functional component.
frontend/web/components/tags/Tag.tsx
Outdated
@@ -47,6 +47,7 @@ const Tag: FC<TagType> = ({ | |||
|
|||
return ( | |||
<Tooltip | |||
htmlEncode |
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.
we'd probably want to make the property naming of this a bit more clear.
I think plainText might be good since in this case you're wanting to make the tooltip content text rather than html.
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.
Sure, that was my first option but then I thought it was not descriptive enough :). Done
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.
BTW, also fixed the component filename from toolip to tooltip.
frontend/web/components/Tooltip.tsx
Outdated
children: string | JSX.Element | JSX.Element[] | (() => JSX.Element), | ||
): string => { | ||
const html = renderToStaticMarkup( | ||
<StyledTooltip>{plainText ? children : '{{placeholder}}'}</StyledTooltip>, |
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 {{placeholder}} supposed to be here?
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.
Replace with {{html}} for clarity, also, some issues with typescript were corrected
Thanks for submitting a PR! Please check the boxes below:
pre-commit
to check lintingChanges
DIsable HTML tooltips since they could cause XSS injection vulnerability
How did you test this code?
Manually.
" as the label of a tag.
Insert XSS code like "xss
When hover over the tag, it should display simple text and not HTML.