260907_01_ENH: 이메일 템플릿 테이블·이미지맵·HR 태그 화이트리스트 확장
This commit is contained in:
@@ -21,10 +21,41 @@ public final class TemplateContentSanitizer {
|
|||||||
Pattern.compile("(?i)<\\s*qrcode\\b([\\s\\S]*?)/?\\s*>");
|
Pattern.compile("(?i)<\\s*qrcode\\b([\\s\\S]*?)/?\\s*>");
|
||||||
private static final Pattern ESCAPED_QRCODE_CLOSE_TAG_PATTERN =
|
private static final Pattern ESCAPED_QRCODE_CLOSE_TAG_PATTERN =
|
||||||
Pattern.compile("(?i)</\\s*qrcode\\s*>");
|
Pattern.compile("(?i)</\\s*qrcode\\s*>");
|
||||||
|
private static final Safelist EMAIL_HTML_SAFELIST = createEmailHtmlSafelist();
|
||||||
|
|
||||||
private TemplateContentSanitizer() {
|
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) {
|
private static int utf8ByteLength(String s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -76,19 +107,8 @@ public final class TemplateContentSanitizer {
|
|||||||
|
|
||||||
html = normalizeQrcodeSrc(normalizeEscapedQrcodeTags(html));
|
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);
|
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);
|
cleaned = normalizeControls(cleaned, true);
|
||||||
return cleaned.trim();
|
return cleaned.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user