mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-09-10 19:26:00 +00:00
Sanitize rendered web content (#77)
This commit is contained in:
parent
cb192906bd
commit
59013cf0af
6 changed files with 167 additions and 133 deletions
33
apps/logicsrc-web/src/lib/html.ts
Normal file
33
apps/logicsrc-web/src/lib/html.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import sanitizeHtml from "sanitize-html";
|
||||
|
||||
const allowedTags = sanitizeHtml.defaults.allowedTags.concat([
|
||||
"figure",
|
||||
"figcaption",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"img"
|
||||
]);
|
||||
|
||||
const allowedAttributes = {
|
||||
...sanitizeHtml.defaults.allowedAttributes,
|
||||
a: ["href", "name", "target", "rel"],
|
||||
img: ["src", "alt", "title", "width", "height", "loading"],
|
||||
code: ["class"],
|
||||
pre: ["class"]
|
||||
};
|
||||
|
||||
export function sanitizeRenderedHtml(html: string): string {
|
||||
return sanitizeHtml(html, {
|
||||
allowedTags,
|
||||
allowedAttributes,
|
||||
allowedSchemes: ["http", "https", "mailto", "tel"],
|
||||
allowedSchemesByTag: {
|
||||
img: ["http", "https"]
|
||||
},
|
||||
allowProtocolRelative: false
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue