javascript - 在 Firefox OS 验证器中检测到 CSP 违规

标签 javascript firefox firefox-os

我在 firefox os 验证器中有这条消息:

Erreur:您的代码似乎正在执行违反特权应用程序 CSP(内容安全策略)的操作。 您可以在 Mozilla 开发者网站上找到有关 CSP 允许和不允许的内容的更多信息。 https://developer.mozilla.org/en-US/docs/Security/CSP

www/index.html
16
17
<script type="text/javascript" src="js/select2.js"></script>
<script>

代码index.html:

<!DOCTYPE html> 
<html>
<head>
    <title>Chri App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="js/jquery.css.min.css" rel="stylesheet"/>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
            <meta charset='utf-8'> 
        <meta name="format-detection" content="telephone=no" />
                <link rel="stylesheet" type="text/css" href="css/index.css" />
        <meta name="viewport" content="width=device-width, initial-scale=1">  
        <link href="js/select2/select2.css" rel="stylesheet" > 
        <link href="css/web_app.css" rel="stylesheet" > 
        <script src="main.js"></script>
        <script type="text/javascript" src="js/select2/select2.js"></script> 
        <script>

        $(document).bind('pageinit',function(e ){


        $.support.cors = true;
        $.mobile.allowCrossDomainPages= true;
        $.mobile.selectmenu.prototype.options.nativeMenu = false;





            // When the testform is submitted
        $("#search-form-location").select2();
        $("#search-form-category").select2();
            $("#testform").submit(function() {

            $.mobile.loading('show');
.......

你有想法吗?

最佳答案

如果您正在编写特权(或认证)应用程序,它需要符合多项要求,以使其更健壮 - 不易受到各种攻击。限制之一禁止内联 javascript,即嵌入在 <script> 中的 javascript标签 - 您应该将这些内联脚本放入外部 .js文件,并通过 src 链接它们属性。

查看您的代码,这应该是验证器提示的原因(请参阅此处的 jQuery $(document).bind(... block )。将此 block 放入外部文件应该可以解决此问题。

您可以在 MDN: Apps CSP 上阅读更多关于其他 CSP 要求和限制的信息.

关于javascript - 在 Firefox OS 验证器中检测到 CSP 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19209134/

相关文章:

javascript - JavaScript 中更简单的 "Class"定义

javascript - typescript + angular2 从字符串值传递类

php - 无法选择动态生成的表单元素(ajax)

html - Firefox 图片底部的文字 less 30

web-applications - Firefox Webapp(Open Web App)无法使用自签名证书

javascript - 在 Firefox 中使用 howler.js 播放 mp3

firefox - Phonegap 无法添加平台 FireFox OS

javascript - 如何在 ChromeWorker 中使用事件?

Firefox: "Document Expired Error"用于 POST 页面

javascript - 只接受输入 javascript 中的数字和制表符