AMT*_*AMT 5 node.js express content-security-policy
我正在开发一个 NodeJS 项目,并且正在使用CSP(内容安全策略)。
我正在使用一个外部插件FullCalendar,该插件被 csp 阻止,并出现以下错误:
Error: call to Function() blocked by CSP
我曾经script-src 'self' 'unsafe-eval';重写它,但在 Firefox 中不起作用。在其他浏览器中它工作正常。
我在这个问题上被困了 4 小时。
得到解决方案将会很有帮助。
我在 CSP 限制中使用以下格式。
X-Content-Security-Policy:默认-src *;script-src 'self' '不安全评估'; 对象-src'无';style-src 'self' '不安全内联 img-src *;选项 eval-script;
X-WebKit-CSP:默认-src *;script-src 'self' '不安全评估'; 对象-src'无';style-src 'self' '不安全内联 img-src *;
内容安全策略:default-src *;script-src 'self' '不安全评估'; 对象-src'无';style-src 'self' '不安全内联 img-src *;
假设this.disp包含要计算的表达式。还disp: document.getElementById("id_of_text_input_field")。例如。this.disp.value = 123/45*67+8-9%10. 它还会关心negativeno。例如。-123+3= -120。耶!
compute: function compute() {
var sign = 1;
if (this.disp.value[0] == '-') sign = -1;
this.disp.value = this.calculate(this.disp.value,sign);
this.update(this.disp.value.length);
return this.disp.value;
},
calculate: function calculate(input,sign){
var opr_list = { add : '+'
, sub : '-'
, div : '/'
, mlt : '*'
, mod : '%'
};
opr_list.opr = [[ [opr_list.mlt] , [opr_list.div] , [opr_list.mod]],
[ [opr_list.add] , [opr_list.sub] ]];
input = input.replace(/[^0-9%^*\/()\-+.]/g,'');
var output,n;
for(var i=0, n=opr_list.opr.length; i<n; i++ ){
var re = new RegExp('(\\d+\\.?\\d*)([\\'+opr_list.opr[i].join('\\')+'])(\\d+\\.?\\d*)');
re.lastIndex = 0;
while( re.test(input) ){
output = this.compute_result(opr_list,sign*RegExp.$1,RegExp.$2,RegExp.$3);
if (isNaN(output) || !isFinite(output)) return output;
input = input.replace(re,output);
}
}
return output;
},
compute_result: function compute_result(opr_list,a,op,b){
a=a*1; b=b*1;
switch(op){
case opr_list.add: return a+b; break;
case opr_list.sub: return a-b; break;
case opr_list.div: return a/b; break;
case opr_list.mlt: return a*b; break;
case opr_list.mod: return a%b; break;
default: null;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以根据您的要求添加更多运算符和案例。例如。方形x^y等