Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2774 from l5oo00/dev-1.4.3.3
Browse files Browse the repository at this point in the history
修复添加图片和视频的xss
  • Loading branch information
Phinome committed May 12, 2016
2 parents b23a95b + dfa8586 commit 8cfdc15
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 9 deletions.
20 changes: 19 additions & 1 deletion _src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,24 @@ var utils = UE.utils = {

}) : '';
},
/**
* 将url中的html字符转义, 仅转义 ', ", <, > 四个字符
* @param { String } str 需要转义的字符串
* @param { RegExp } reg 自定义的正则
* @return { String } 转义后的字符串
*/
unhtmlForUrl:function (str, reg) {
return str ? str.replace(reg || /[<">']/g, function (a) {
return {
'<':'&lt;',
'&':'&amp;',
'"':'&quot;',
'>':'&gt;',
"'":'&#39;'
}[a]

}) : '';
},

/**
* 将str中的转义字符还原成html字符
Expand Down Expand Up @@ -1189,4 +1207,4 @@ utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Date']
UE.utils['is' + v] = function (obj) {
return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
}
});
});
28 changes: 27 additions & 1 deletion _src/plugins/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ UE.commands['insertimage'] = {
return;
}

function unhtmlData(imgCi) {

utils.each('width,height,border,hspace,vspace'.split(','), function (item) {

if (imgCi[item]) {
imgCi[item] = parseInt(imgCi[item], 10) || 0;
}
});

utils.each('src,_src'.split(','), function (item) {

if (imgCi[item]) {
imgCi[item] = utils.unhtmlForUrl(imgCi[item]);
}
});
utils.each('title,alt'.split(','), function (item) {

if (imgCi[item]) {
imgCi[item] = utils.unhtml(imgCi[item]);
}
});
}

if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
var first = opt.shift();
var floatStyle = first['floatStyle'];
Expand All @@ -213,6 +236,8 @@ UE.commands['insertimage'] = {
var html = [], str = '', ci;
ci = opt[0];
if (opt.length == 1) {
unhtmlData(ci);

str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.width ? 'width="' + ci.width + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
Expand All @@ -229,6 +254,7 @@ UE.commands['insertimage'] = {

} else {
for (var i = 0; ci = opt[i++];) {
unhtmlData(ci);
str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
(ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
(ci.height ? ' height="' + ci.height + '" ' : '') +
Expand All @@ -244,4 +270,4 @@ UE.commands['insertimage'] = {

me.fireEvent('afterinsertimage', opt)
}
};
};
10 changes: 9 additions & 1 deletion _src/plugins/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ UE.plugins['video'] = function (){
* @param addParagraph 是否需要添加P 标签
*/
function creatInsertStr(url,width,height,id,align,classname,type){

url = utils.unhtmlForUrl(url);
align = utils.unhtml(align);
classname = utils.unhtml(classname);

width = parseInt(width, 10) || 0;
height = parseInt(height, 10) || 0;

var str;
switch (type){
case 'image':
Expand Down Expand Up @@ -150,4 +158,4 @@ UE.plugins['video'] = function (){
return flag ? 1 : 0;
}
};
};
};
9 changes: 6 additions & 3 deletions dialogs/image/image.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions dialogs/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@

var conUrl = convert_url(url);

conUrl = utils.unhtmlForUrl(conUrl);

$G("preview").innerHTML = '<div class="previewMsg"><span>'+lang.urlError+'</span></div>'+
'<embed class="previewVideo" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
' src="' + conUrl + '"' +
Expand All @@ -284,8 +286,8 @@
function insertUpload(){
var videoObjs=[],
uploadDir = editor.getOpt('videoUrlPrefix'),
width = $G('upload_width').value || 420,
height = $G('upload_height').value || 280,
width = parseInt($G('upload_width').value, 10) || 420,
height = parseInt($G('upload_height').value, 10) || 280,
align = findFocus("upload_alignment","name") || 'none';
for(var key in uploadVideoList) {
var file = uploadVideoList[key];
Expand Down Expand Up @@ -786,4 +788,4 @@
}
};

})();
})();

0 comments on commit 8cfdc15

Please sign in to comment.