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

Skip to content

Commit ba6532a

Browse files
committed
xss 注入问题
1 parent c1e6217 commit ba6532a

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

config/env.sample.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ port = 3306
2323
user = root
2424
password =
2525
dbname = studygolang
26-
charset = utf8
26+
charset = utf8mb4
2727

2828
; 最大空闲连接数
2929
max_idle = 2

static/js/common.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,22 @@ SG.replaceSpecialChar = function(str) {
7878
}
7979

8080
SG.markSetting = function() {
81-
// 配置 marked 语法高亮
81+
var renderer = new marked.Renderer();
82+
83+
// 对 html 进行处理
84+
renderer.html = function(html) {
85+
if (html.indexOf('<video') == 0) {
86+
return html;
87+
} else if (html.indexOf('<table') == 0) {
88+
return html;
89+
} else {
90+
return html.replace(/</g, '&lt;');
91+
}
92+
};
93+
8294
marked.setOptions({
95+
renderer: renderer,
96+
// 配置 marked 语法高亮
8397
highlight: function (code) {
8498
code = SG.replaceSpecialChar(code);
8599
return hljs.highlightAuto(code).value;

static/js/topics.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
SG.Topics = function(){}
1717
SG.Topics.prototype = new SG.Publisher();
1818
SG.Topics.prototype.parseContent = function(selector) {
19-
var markdownString = SG.preProcess(selector.text());
19+
var markdownString = selector.text();
2020
// 配置 marked 语法高亮
2121
marked = SG.markSetting();
2222

2323
var contentHtml = marked(markdownString);
2424
contentHtml = SG.replaceCodeChar(contentHtml);
25+
2526
selector.html(contentHtml);
2627

2728
// emoji 表情解析

template/common/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
}
254254
var GLaunchTime = {{timestamp .app.LaunchTime}}*1000;
255255
</script>
256-
<script src="/static/js/common.js?v=1.4"></script>
256+
<script src="/static/js/common.js?v=1.0"></script>
257257
{{template "js" .}}
258258
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jsrender/0.9.84/jsrender.min.js"></script>
259259
<script type="text/javascript">

template/topics/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>
3434
<div class="outdated">这是一个创建于 <span title="{{.topic.ctime}}" class="timeago"></span> 的主题,其中的信息可能已经有所发展或是发生改变。</div>
3535
{{end}}
3636
<div class="cell">
37-
<div class="content">{{.topic.content | html}}</div>
37+
<div class="content">{{.topic.content}}</div>
3838
</div>
3939

4040
<div class="content-buttons">
@@ -125,7 +125,7 @@ <h1>
125125
<script type="text/javascript" src="/static/js/libs/emojify.min.js"></script>
126126
<script type="text/javascript" src="/static/js/libs/emojis.js"></script>
127127
<script type="text/javascript" src="/static/js/libs/plupload.full.min.js"></script>
128-
<script type="text/javascript" src="/static/js/topics.js?v=1.2"></script>
128+
<script type="text/javascript" src="/static/js/topics.js?v=1.1"></script>
129129
<script type="text/javascript" src="/static/js/comment.js?v=1.23"></script>
130130
<script type="text/javascript" src="/static/js/puploader.js?v=1.2"></script>
131131
<script type="text/javascript">

0 commit comments

Comments
 (0)