|
5 | 5 | <script setup lang="ts">
|
6 | 6 | import { onMounted, ref, watch } from 'vue'
|
7 | 7 | import type { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common'
|
| 8 | + import sanitizeHtml from 'sanitize-html'; |
8 | 9 |
|
9 | 10 | const props = defineProps<{
|
10 | 11 | column: AdminForthResourceColumnCommon
|
|
28 | 29 | iframe.style.height = "400px"
|
29 | 30 |
|
30 | 31 | doc.open()
|
31 |
| - doc.write(props.record[props.column.name] || '') |
| 32 | + doc.write(protectAgainstXSS(props.record[props.column.name]) || '') |
32 | 33 | doc.close()
|
33 | 34 | }
|
34 |
| - |
| 35 | +
|
| 36 | + function protectAgainstXSS(value: string) { |
| 37 | + return sanitizeHtml(value, { |
| 38 | + allowedTags: [ |
| 39 | + "address", "article", "aside", "footer", "header", "h1", "h2", "h3", "h4", |
| 40 | + "h5", "h6", "hgroup", "main", "nav", "section", "blockquote", "dd", "div", |
| 41 | + "dl", "dt", "figcaption", "figure", "hr", "li", "main", "ol", "p", "pre", |
| 42 | + "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", |
| 43 | + "em", "i", "kbd", "mark", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", |
| 44 | + "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "caption", |
| 45 | + "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", 'img' |
| 46 | + ], |
| 47 | + allowedAttributes: { |
| 48 | + 'li': [ 'data-list' ], |
| 49 | + 'img': [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ] |
| 50 | + } |
| 51 | + }); |
| 52 | + } |
| 53 | +
|
35 | 54 | onMounted(renderHtml)
|
36 | 55 | watch(() => props.record[props.column.name], renderHtml)
|
37 | 56 | </script>
|
|
0 commit comments