fix(api): 🔒 Correctly put all URIs in profiles through proxy

This commit is contained in:
Jesse Wierzbinski 2024-11-22 15:06:46 +01:00
parent bd1f09837b
commit 569ba8bf2d
No known key found for this signature in database
3 changed files with 79 additions and 12 deletions

View file

@ -1,5 +1,6 @@
import { stringifyEntitiesLight } from "stringify-entities";
import xss, { type IFilterXSSOptions } from "xss";
import { proxyUrl } from "./response.ts";
export const sanitizedHtmlStrip = (html: string): Promise<string> => {
return sanitizeHtml(html, {
@ -129,6 +130,15 @@ export const sanitizeHtml = async (
}
},
})
// Rewrite all src tags to go through proxy
.on("[src]", {
element(element): void {
element.setAttribute(
"src",
proxyUrl(element.getAttribute("src") ?? "") ?? "",
);
},
})
.transform(new Response(sanitizedHtml))
.text();
};