From b80ab72038763e446a0f3623bbc8135de2ce0e78 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 7 Sep 2026 13:55:04 +0900 Subject: [PATCH] =?UTF-8?q?260907=5F01=5FENH:=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=C2=B7=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=A7=B5=C2=B7HR=20?= =?UTF-8?q?=ED=83=9C=EA=B7=B8=20=ED=99=94=EC=9D=B4=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=ED=99=95=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/TemplateContentSanitizer.java | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java b/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java index 969b66b..07c17dc 100644 --- a/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java +++ b/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java @@ -21,10 +21,41 @@ public final class TemplateContentSanitizer { Pattern.compile("(?i)<\\s*qrcode\\b([\\s\\S]*?)/?\\s*>"); private static final Pattern ESCAPED_QRCODE_CLOSE_TAG_PATTERN = Pattern.compile("(?i)</\\s*qrcode\\s*>"); + private static final Safelist EMAIL_HTML_SAFELIST = createEmailHtmlSafelist(); private TemplateContentSanitizer() { } + private static Safelist createEmailHtmlSafelist() { + return Safelist.relaxed() + .addTags("mark", "hr") + .addAttributes("mark", "style", "data-color") + .addAttributes("hr", "style", "width", "size", "color", "align", "noshade") + .addAttributes("div", "style", "align") + .addAttributes("span", "style") + .addAttributes("p", "style") + .addAttributes("b", "style") + .addAttributes("table", "style", "width", "height", "cellpadding", "cellspacing", + "border", "align", "bgcolor", "role") + .addAttributes("tbody", "style", "align", "valign") + .addAttributes("tr", "style", "align", "valign", "bgcolor", "height") + .addAttributes("td", "style", "align", "valign", "bgcolor", "width", "height", + "colspan", "rowspan") + .addAttributes("th", "style", "align", "valign", "bgcolor", "width", "height", + "colspan", "rowspan", "scope") + .addAttributes("a", "style", "target", "rel") + .addAttributes("img", "style", "loading", "src", "width", "height", "alt", "title", + "align", "usemap") + .addTags("map", "area") + .addAttributes("map", "name", "id") + .addAttributes("area", "shape", "coords", "href", "alt", "title", "target") + .addTags("qrcode") + .addAttributes("qrcode", "src", "width", "height", "alt") + .addProtocols("a", "href", "http", "https", "mailto", "tel") + .addProtocols("area", "href", "http", "https", "mailto", "tel") + .addProtocols("img", "src", "http", "https"); + } + private static int utf8ByteLength(String s) { if (s == null) { return 0; @@ -76,19 +107,8 @@ public final class TemplateContentSanitizer { html = normalizeQrcodeSrc(normalizeEscapedQrcodeTags(html)); - Safelist safelist = Safelist.relaxed() - .addTags("mark") - .addAttributes("mark", "style", "data-color") - .addAttributes("p", "style") - .addAttributes("span", "style") - .addAttributes("div", "style") - .addTags("qrcode") - .addAttributes("qrcode", "src", "width", "height", "alt") - .addProtocols("a", "href", "http", "https", "mailto") - .addProtocols("img", "src", "http", "https"); - Document.OutputSettings out = new Document.OutputSettings().prettyPrint(false); - String cleaned = Jsoup.clean(html, "", safelist, out); + String cleaned = Jsoup.clean(html, "", EMAIL_HTML_SAFELIST, out); cleaned = normalizeControls(cleaned, true); return cleaned.trim();