-
Notifications
You must be signed in to change notification settings - Fork 2
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: Unescape HTML entities for alternate DOMPurify check #2630
Conversation
Removed vultr server and associated DNS entries |
07715d5
to
18d0f05
Compare
const logUncleanHTMLError = (input: string, cleanHTML: string) => { | ||
const userId = userContext.getStore()?.user.sub; | ||
|
||
console.error({ |
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.
I think this should be fine, I'll check on staging. We might need to use the logger.notify()
method Ben wrote if this doesn't get caught by Airbrake.
}); | ||
}; | ||
|
||
const unescapeHTML = (input: string): string => |
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.
I tested a number of other HTML entities and these were the only one which were getting caught.
Tiptap is converting the quotation marks, and DOMPurify appears to be converting all HTML entities apart from
.
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.
Thanks for getting to the bottom of this one!
What's the problem?
Originally picked up here - https://opensystemslab.slack.com/archives/C01E3AC0C03/p1703175603781519 (OSL Slack)
A permission error is thrown when attempting to copy some flows from the "Templates" team, despite the users in question having the requisite permission level.
What's the cause?
The logged error is misleading, it's actually an input validation error that's being thrown - the try/catch block just didn't account for this.
What's happening here is that the simple
length === length
check for DOMPurify is not accounting for HTML entities (see screenshot below).There isn't a simple alternative way of checking that DOMPurify has modified content unfortunately. We can't check string equality directly as the order of HTML attributes in sanitised content can differ from the original (and there's not a method of preserving this). Please see comment from DOMPurify readme below on checking for removed attributes directly -
Source: https://github.com/cure53/DOMPurify?tab=readme-ov-file#okay-makes-sense-lets-move-on
What's the solution?
Check length, and then unescape known HTML entities which are converted, and re-check. I'll be honest this doesn't feel ideal but it's the best / simplest solution I've reached.
I'm throwing noisy errors here so that we can more easily spot any more issues going forward.