拒绝加载图像 'blob:...' 因为它违反了以下内容安全策略

Refused to load the image 'blob:...' because it violates the following Content Security Policy

我收到这个错误:

Refused to load the image 'blob:file:///cf368042-bf23-42b6-b07c-54189d3b0e01' because it violates the following Content Security Policy directive: "default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.

正在尝试加载 mapboxGL 地图。 这是我的 CSP 标签:

<meta http-equiv="Content-Security-Policy" 
    content="
      worker-src blob:; 
      child-src blob: gap:;
      default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:">

您需要在 CSP 值中添加 img-src blob:。 由于 img-src 不存在,因此它使用 default-src。 您也可以设置 img-src *。 请查看 https://content-security-policy.com/ 了解如何为图像添加 CSP。

这是图像和 base64 的修复。

需添加img-src 'self' blob: data:;如下:

<meta http-equiv="Content-Security-Policy" 
    content="
      worker-src blob:; 
      child-src blob: gap:;
      img-src 'self' blob: data:;
      default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:">

通常情况下,设置 img-src 策略可以解决问题,但如果仍然出现相同的错误。 注意,如果你同时使用“头盔”中间件,你的问题可能就出自它,需要单独配置。