浏览代码

FIx XSS Sanitize (#4678)

version-14
Faris Ansari 7 年前
committed by Nabin Hait
父节点
当前提交
b5bf7ca6fe
共有 1 个文件被更改,包括 5 次插入6 次删除
  1. +5
    -6
      frappe/public/js/frappe/misc/common.js

+ 5
- 6
frappe/public/js/frappe/misc/common.js 查看文件

@@ -262,7 +262,6 @@ frappe.utils.xss_sanitise = function (string, options) {
strategies: ['html', 'js'] // use all strategies.
}
const HTML_ESCAPE_MAP = {
'&': '&amp',
'<': '&lt',
'>': '&gt',
'"': '&quot',
@@ -271,16 +270,16 @@ frappe.utils.xss_sanitise = function (string, options) {
};
const REGEX_SCRIPT = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi; // used in jQuery 1.7.2 src/ajax.js Line 14
options = Object.assign({ }, DEFAULT_OPTIONS, options); // don't deep copy, immutable beauty.
// Rule 1
if ( options.strategies.includes('html') ) {
// By far, the best thing that has ever happened to JS - Object.keys
Object.keys(HTML_ESCAPE_MAP).map((char, escape) => {
for (let char in HTML_ESCAPE_MAP) {
const escape = HTML_ESCAPE_MAP[char];
const regex = new RegExp(char, "g");
sanitised = sanitised.replace(regex, escape);
});
}
}
// Rule 3 - TODO: Check event handlers?
if ( options.strategies.includes('js') ) {
sanitised = sanitised.replace(REGEX_SCRIPT, "");


正在加载...
取消
保存