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 · 1 comment
Open
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

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