Skip to content
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

Notifications: use sanitize-html for cleaning header/body content #322

Open
agjohnson opened this issue Mar 29, 2024 · 4 comments
Open

Notifications: use sanitize-html for cleaning header/body content #322

agjohnson opened this issue Mar 29, 2024 · 4 comments
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code

Comments

@agjohnson
Copy link
Contributor

agjohnson commented Mar 29, 2024

This was a library that was brought in for displaying ANSI color codes in the build detail command output. It is currently unused, but was loaded async previously. It seems we could use this for notifications as well, making it a standard part of our bundled JS. Or, alternatively, load it async when there are notifications.

We only need to support some minor elements in notification body/header, mostly formatting and links.

return Promise.all([
import(
/* webpackChunkName: 'ansi_up' */
"ansi_up"
).then(({ default: AnsiUp }) => {
return AnsiUp;
}),
import(
/* webpackChunkName: 'sanitize-html' */
"sanitize-html"
).then(({ default: sanitize_html }) => {
return sanitize_html;
}),
]).then((imports) => {
let AnsiUp, sanitize_html;
[AnsiUp, sanitize_html] = imports;
// Build output lines
let ansi_up = new AnsiUp();
ansi_up.use_classes = true;
output = ansi_up.ansi_to_html(output);
output = sanitize_html(output, {
allowedTags: ["span"],
allowedAttributes: { span: ["class"] },
});
return output;
});

@agjohnson agjohnson added Improvement Minor improvement to code Accepted Accepted issue on our roadmap labels Mar 29, 2024
@stsewd
Copy link
Member

stsewd commented Apr 1, 2024

Another popular option is DOMPurify https://github.com/cure53/DOMPurify

@agjohnson
Copy link
Contributor Author

@stsewd What sort of scenario would this help cover? I know we talked about cleaning the notificaiton HTML before DOM insertion, but if the notification HTML is safe inside our API, is there any case where this wouldn't be safe as we are injecting it into the DOM?

@stsewd
Copy link
Member

stsewd commented Jun 4, 2024

As long as our notifications don't include user content withotu escaping, we shuold be good.

@agjohnson
Copy link
Contributor Author

@humitos are we consistently escaping user input in notifications through the API? I couldn't actually find where we were sanitizing message body/header content. I thought this happened at the model or API level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Improvement Minor improvement to code
Projects
Status: Planned
Development

No branches or pull requests

2 participants