Отказался загружать скрипт, поскольку он нарушает следующую директиву Content Security Policy: «script-src 'self'

Я пытаюсь разработать приложение Chrome, в котором я хочу отображать пользовательские Rss-каналы, но каналы не загружаются и отображают ошибку, как указано выше.

Информация об ошибке, в которой отображается

Refused to load the script
 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

     Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js". 
 jquery.min.js:35

     Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

     Refused to load the script 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=2&output=json&q=http%3A%2F%2Fblog.tax2290.com%2Ffeed%2F&hl=en&callback=jsonp1373953012503'
 because it violates the following Content Security Policy directive:
 "script-src 'self'
 https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js".

manifest.json

{
      "name": "Tax New 2290",
      "manifest_version": 2,
      "version": "1.1",
      "description": "Tax 2290",
    "web_accessible_resources": ["images/logo.png"],
      "icons": {
        "16": "icon16.png",
        "19":"icon19.png",
        "48": "icon48.png",
        "128": "icon128.png",
        "256": "icon256.png"
    },
     "browser_action":
    {
    "default_icon":"images/logo.png",
    "default_popup":"index.html"
    },

         "permissions": ["tabs", "<all_urls>","http://www.tax2290.com","http://*/*", "https://*/*","http://*.google.com/"],
        "content_security_policy": "script-src 'self' https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js; https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js; object-src 'self'"

    }

index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="images/feed.js"></script>
<link rel="stylesheet" href="images/style.css" type="text/css"  />
<title>Chrome Popup</title>
</head>

фид.js

        $(function() {
                var $items = $('#vtab>ul>li');
                $items.mouseover(function() {
                    $items.removeClass('selected');
                    $(this).addClass('selected');

                    var index = $items.index($(this));
                    $('#vtab>div').hide().eq(index).show();
                }).eq(0).mouseover();
            });


    $(document).ready(function () {  
       $('#divRss2').FeedEk({
            FeedUrl: 'http://blog.tax2290.com/feed/',
            MaxCount: 2,ShowDesc: true,
            ShowPubDate: true,
            DescCharacterLimit: 250
        });
    });


   > Please tel me how could avoid these errors and load the custom RSS feeds.

person user2564356    schedule 16.07.2013    source источник
comment
Есть 4 элемента Chrome, которые могут иметь файл manifest.json: приложение Chrome, расширение Chrome, размещенное приложение и устаревшее упакованное приложение. Было бы полезно, если бы вы могли точно определить, какой из этих четырех вы пытаетесь написать. В вашем вопросе упоминается приложение Chrome, но показанный вами манифест не относится к приложению Chrome, поэтому неясно, что вы пытаетесь сделать.   -  person Marc Rochkind    schedule 07.09.2014


Ответы (2)


Ваша «content_security_policy» имеет несколько проблем.

1) Во-первых, вы должны удалить точку с запятой между объявлениями jquery 1.4.1 и 1.9.1. Несколько URL-адресов должны быть разделены только одним пробелом и никакими другими символами.

2) Во-вторых, вы пытаетесь загрузить этот скрипт "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=2&output=json&q=http%3A%2F%2Fblog.tax2290.com%2Ffeed%2F&hl=en&callback=jsonp1373953012503", но вы никогда не разрешаете это в своем CSP.

3) И в-третьих, похоже, вам нужно разрешить встроенные скрипты.

Я бы изменил вашу «content_security_policy», чтобы она выглядела так:

"content_security_policy": "script-src 'self' https://ajax.googleapis.com/ 'unsafe-inline'; object-src 'self'"

'unsafe-inline' должен исправить ошибку «Отказано в выполнении встроенного скрипта».

https://ajax.googleapis.com/ должен разрешить загрузку обеих версий jquery, а также вашего /ajarx /services/feed/загрузить URL.

person Jason Wheeler    schedule 18.01.2016
comment
Понижение: unsafe-inline игнорируется в расширениях Chrome - person Xan; 19.01.2016

Если вы создаете упакованное приложение, вы не можете загружать внешний скрипт. Ваше приложение должно включать в себя все сценарии, стили или изображения.

Перейдите по этой ссылке, чтобы убедиться, что вы соблюдаете правила CSP для приложений Chrome: https://developer.chrome.com/extensions/contentSecurityPolicy

person Damien    schedule 18.07.2013
comment
Вы говорите о упакованных приложениях (хотя вопрос явно не о приложениях). Расширения могут загружать внешние скрипты. - person Xan; 19.01.2016