簡體   English   中英

node.js應用程序中的CSP錯誤

[英]CSP error in a node.js application

我在nodejs中有一個帶有主頁的node.js應用程序。 該頁面包含一個“搜索”框,並具有運行並進行服務器端查詢調用的相應search.js腳本。 為了安全起見,我使用以下csp配置在node.js應用程序中添加了“ csp”。

const csp = require('helmet-csp');
app.use(helmet());
app.use(csp({
directives: {
  defaultSrc: ["'self'", 'https://my.domain.com'],
  scriptSrc: ["'self'", "'unsafe-inline'"],
  styleSrc: ["'self'"],
  imgSrc: ["'self'"],
  connectSrc: ["'self'"],
  fontSrc: ["'self'", 'https://fonts.googleapis.com'],
  objectSrc: ["'none'"],
  mediaSrc: ["'self'"],
  frameSrc: ["'none'"],
},
setAllHeaders: false, // set to true if you want to set all headers
safari5: false // set to true if you want to force buggy CSP in Safari 5
}));

但是有了這一更改,我開始在chrome瀏覽器中遇到以下錯誤。

Refused to load the stylesheet 'https://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800|Roboto+Slab:400,100,300,700' because it violates the following Content Security Policy directive: "style-src 'self'".

prefixfree.min.js:17 Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='), or a nonce ('nonce-...') is required to enable inline execution.

我不明白這些錯誤是什么意思。 如何解決這些錯誤。 我需要使用來自Google的字體作為我的style.css文件的一部分,該文件具有以下條目,

@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800|Roboto+Slab:400,100,300,700);

這是設置csp的正確方法嗎? 任何幫助表示贊賞。

由於csp政策,以某種方式標記了googleapis的地址。 我解決了這個問題

  1. 從Google webfonts幫助網站下載了所需的字體

  2. 從CSS刪除了@import

  3. 從fontSrc中刪除了googleapi,並僅保留了“'self'”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM