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();