This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2776 from robbenmu/dev-1.4.3.3
添加xssfileter过滤器插件
- Loading branch information
Showing
3 changed files
with
181 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @file xssFilter.js | ||
* @desc xss过滤器 | ||
* @author robbenmu | ||
*/ | ||
|
||
UE.plugins.xssFilter = function() { | ||
|
||
var config = UEDITOR_CONFIG; | ||
var whitList = config.whitList; | ||
|
||
function filter(node) { | ||
|
||
var tagName = node.tagName; | ||
var attrs = node.attrs; | ||
|
||
if (!whitList.hasOwnProperty(tagName)) { | ||
node.parentNode.removeChild(node); | ||
return false; | ||
} | ||
|
||
UE.utils.each(attrs, function (val, key) { | ||
|
||
if (whitList[tagName].indexOf(key) === -1) { | ||
node.setAttr(key); | ||
} | ||
}); | ||
} | ||
|
||
// 添加inserthtml\paste等操作用的过滤规则 | ||
if (whitList && config.xssFilterRules) { | ||
this.options.filterRules = function () { | ||
|
||
var result = {}; | ||
|
||
UE.utils.each(whitList, function(val, key) { | ||
result[key] = function (node) { | ||
return filter(node); | ||
}; | ||
}); | ||
|
||
return result; | ||
}(); | ||
} | ||
|
||
var tagList = []; | ||
|
||
UE.utils.each(whitList, function (val, key) { | ||
tagList.push(key); | ||
}); | ||
|
||
// 添加input过滤规则 | ||
// | ||
if (whitList && config.inputXssFilter) { | ||
this.addInputRule(function (root) { | ||
|
||
root.traversal(function(node) { | ||
if (node.type !== 'element') { | ||
return false; | ||
} | ||
filter(node); | ||
}); | ||
}); | ||
} | ||
// 添加output过滤规则 | ||
// | ||
if (whitList && config.outputXssFilter) { | ||
this.addOutputRule(function (root) { | ||
|
||
root.traversal(function(node) { | ||
if (node.type !== 'element') { | ||
return false; | ||
} | ||
filter(node); | ||
}); | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters