@@ -21,13 +21,15 @@ import VueDOMPurifyHTML from 'vue-dompurify-html';
2121
2222const ALLOWED_TAGS = [
2323 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'p' , 'br' , 'hr' , 'span' , 'div' ,
24- 'em' , 'i' , 'strong' , 'b' , 'del' , 'ins' ,
24+ 'em' , 'i' , 'strong' , 'b' , 'u' , 's' , ' del', 'ins' ,
2525 'ul' , 'ol' , 'li' ,
2626 'code' , 'pre' ,
27+ 'a' , 'img' ,
28+ 'table' , 'thead' , 'tbody' , 'tfoot' , 'tr' , 'th' , 'td' ,
2729 'marked' , 'pasmark' , 'filtermark' ,
28- 'sub' , 'sup' , 'small' ,
30+ 'sub' , 'sup' , 'small' , 'abbr' , 'cite' , 'q' , 'time'
2931] ;
30- const ALLOWED_ATTR = [ 'class' , 'style' , 'id' ] ;
32+ const ALLOWED_ATTR = [ 'class' , 'style' , 'id' , 'src' ] ;
3133const ADDITIONAL_ATTR = [ 'target' , 'href' ] ;
3234
3335// DOMPurify 配置对象
@@ -49,13 +51,17 @@ const dompurifyConfig = {
4951 node . setAttribute ( 'rel' , 'noopener noreferrer' ) ;
5052 node . setAttribute ( 'target' , '_blank' ) ;
5153 }
52- // 确保图片安全
54+ // 严格限制图片只允许 base64
5355 if ( node . tagName === 'IMG' ) {
54- // 强制添加 alt 属性如果不存在
55- if ( ! node . getAttribute ( 'alt' ) ) {
56- node . setAttribute ( 'alt' , 'image' ) ;
56+ const src = node . getAttribute ( 'src' ) || '' ;
57+ if ( ! src . startsWith ( 'data:image/' ) ) {
58+ node . removeAttribute ( 'src' ) ;
59+ } else {
60+ // 强制添加 alt 属性
61+ if ( ! node . getAttribute ( 'alt' ) ) {
62+ node . setAttribute ( 'alt' , 'user image' ) ;
63+ }
5764 }
58- node . setAttribute ( 'loading' , 'lazy' ) ;
5965 }
6066 } ,
6167 } ,
0 commit comments