Skip to content
Snippets Groups Projects
Verified Commit bafdfb47 authored by creations's avatar creations :earth_africa:
Browse files

Add more to buns purify

parent c867c57a
Branches
No related tags found
No related merge requests found
import { redisTtl } from "@config/environment";
import { fetch } from "bun";
import { redis } from "bun";
import { fetch, redis } from "bun";
import { marked } from "marked";
const routeDef: RouteDef = {
......@@ -22,10 +21,35 @@ async function addLazyLoading(html: string): Promise<string> {
async function sanitizeHtml(html: string): Promise<string> {
return new HTMLRewriter()
.on("script, iframe, object, embed, link[rel=import]", {
.on(
"script, iframe, object, embed, link[rel=import], svg, math, base, meta[http-equiv='refresh']",
{
element(el) {
el.remove();
},
},
)
.on("*", {
element(el) {
for (const [name, value] of el.attributes) {
const lowerName = name.toLowerCase();
const lowerValue = value.toLowerCase();
if (lowerName.startsWith("on")) {
el.removeAttribute(name);
}
if (
(lowerName === "href" ||
lowerName === "src" ||
lowerName === "action") &&
(lowerValue.startsWith("javascript:") ||
lowerValue.startsWith("data:"))
) {
el.removeAttribute(name);
}
}
},
})
.on("img", {
element(el) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment