【问题标题】:ExpressiveAnnotations error message on validation验证时的 ExpressiveAnnotations 错误消息
【发布时间】:2019-06-17 07:01:01
【问题描述】:

将 ExpressiveAnnotations (expressive.annotations.validate.js) 插入我的应用程序并触发要验证的输入后,浏览器会显示错误消息(见下文)。我不认为问题来自我的代码,而是配置问题。

我已经发现这一行(在 ExpressiveAnnotations 内)会导致问题:

ctxEval: function(exp, ctx) { // evaluates expression in the scope of context object
    return (new Function('expression', 'context', 'with(context){return eval(expression)}'))(exp, ctx); // function constructor used on purpose (a hack), for 'with' statement not to collide with strict mode, which
                                                                                                        // is applied to entire module scope (BTW 'use strict'; pragma intentionally not put to function constructor)
}

显示的错误信息:

[fail] (16:14:32): EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not a allowed source of script in the following Content Security Policy directive: "script-src 'self ''不安全的内联'"。

【问题讨论】:

    标签: javascript typescript asp.net-core expressiveannotations


    【解决方案1】:

    为了解决这个问题,我将 CSP 设置为以下值:

    "content_security_policy": "script-src 'self' 'unsafe-eval';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-22
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2012-06-04
      相关资源
      最近更新 更多