fix(security): harden URL and HTML sanitization

This commit is contained in:
RhenCloud committed 2026-10-24 16:41:29 +08:00
1 parent 978c53eeb3
commit c07741bf54
6 files changed
+9 -6

No files matched your search

+3
View File
@@ -218,6 +218,9 @@ function stripHtml(input: string): string {
.replace(/>/gi, ">")
.replace(/"/gi, '"')
.replace(/'/gi, "'")
// Entity decoding can reveal a tag prefix after the first pass. Remove
// angle brackets again so encoded `<script` cannot survive sanitization.
.replace(/</g, "")
.replace(/&#x([0-9a-f]+);/gi, (m, hex: string) => codePoint(parseInt(hex, 16), m))
.replace(/&#(\d+);/g, (m, dec: string) => codePoint(Number(dec), m))
.replace(/&amp;/gi, "&");