feat(document-preview): enhance security by sanitizing HTML and Markdown content
- Integrated sanitizeHTML and safeMarkdownToHTML functions to ensure that rendered HTML and Markdown content is safe from XSS vulnerabilities. - Updated the rendering logic for Excel and Markdown to sanitize the output, improving overall security in document previews.
This commit is contained in:
@@ -6,6 +6,7 @@ import { MessagePlugin } from 'tdesign-vue-next';
|
|||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
import 'highlight.js/styles/github.css';
|
import 'highlight.js/styles/github.css';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { sanitizeHTML, safeMarkdownToHTML } from '@/utils/security';
|
||||||
|
|
||||||
|
|
||||||
const VueOfficePptx = defineAsyncComponent(() => import('@vue-office/pptx'));
|
const VueOfficePptx = defineAsyncComponent(() => import('@vue-office/pptx'));
|
||||||
@@ -174,7 +175,7 @@ async function renderExcel(blob: Blob, fileType?: string) {
|
|||||||
html += sheetHtml;
|
html += sheetHtml;
|
||||||
html += `</div>`;
|
html += `</div>`;
|
||||||
});
|
});
|
||||||
excelHtml.value = html;
|
excelHtml.value = sanitizeHTML(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderText(blob: Blob, fileType: string) {
|
async function renderText(blob: Blob, fileType: string) {
|
||||||
@@ -223,7 +224,9 @@ async function renderMarkdown(blob: Blob) {
|
|||||||
return `<pre><code class="hljs">${highlighted}</code></pre>`;
|
return `<pre><code class="hljs">${highlighted}</code></pre>`;
|
||||||
};
|
};
|
||||||
marked.use({ renderer });
|
marked.use({ renderer });
|
||||||
markdownHtml.value = marked.parse(text);
|
const safeText = safeMarkdownToHTML(text);
|
||||||
|
const rawHtml = marked.parse(safeText);
|
||||||
|
markdownHtml.value = sanitizeHTML(rawHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onImageLoad(e: Event) {
|
function onImageLoad(e: Event) {
|
||||||
|
|||||||
@@ -189,10 +189,6 @@ const renderToken = (token) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const myMarkdown = (res) => {
|
|
||||||
return marked.parse(res, { renderer })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取实际内容
|
// 获取实际内容
|
||||||
const getActualContent = () => {
|
const getActualContent = () => {
|
||||||
return (props.content || props.session?.content || '').trim();
|
return (props.content || props.session?.content || '').trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user