Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fb30f9

Browse files
committed
临时处理 xss
1 parent 39ff273 commit 0fb30f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

static/js/topics.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
var markdownString = $(this).text();
2424

2525
var contentHtml = marked(markdownString);
26+
27+
// JS 处理,避免 XSS。最终还是改为服务端渲染更好
28+
if (contentHtml.indexOf('<script') != -1) {
29+
contentHtml = contentHtml.replace(/<script/g, '&lt;script');
30+
}
31+
if (contentHtml.indexOf('<form') != -1) {
32+
contentHtml = contentHtml.replace(/<form/g, '&lt;form');
33+
}
34+
if (contentHtml.indexOf('<input') != -1) {
35+
contentHtml = contentHtml.replace(/<input/g, '&lt;input');
36+
}
37+
if (contentHtml.indexOf('<select') != -1) {
38+
contentHtml = contentHtml.replace(/<select/g, '&lt;select');
39+
}
40+
if (contentHtml.indexOf('<textarea') != -1) {
41+
contentHtml = contentHtml.replace(/<textarea/g, '&lt;textarea');
42+
}
43+
2644
contentHtml = SG.replaceCodeChar(contentHtml);
2745

2846
$(this).html(contentHtml);

0 commit comments

Comments
 (0)