内容安全策略指令:“框架祖先”缺失但存在?

Tla*_*uis 2 content-security-policy

我正在开发一个nodejs电子应用程序,在我的index.html中我有一个“内容安全策略”,如下所示

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy"
      content="
      default-src     'self' https://*.mydomain.tld;
      script-src      'self' https://*.mydomain.tld;
      style-src       'self' https://*.mydomain.tld;
      img-src         'self' https://*.mydomain.tld;
      font-src        'self' https://*.mydomain.tld;
      connect-src     'self' https://*.mydomain.tld;
      media-src       'self' https://*.mydomain.tld;
      object-src      'self' https://*.mydomain.tld;
      child-src       'self' https://*.mydomain.tld;
      frame-ancestors 'self' https://*.mydomain.tld;
      frame-src       'self' https://*.mydomain.tld;
      worker-src      'self' https://*.mydomain.tld;
      form-action     'self' https://*.mydomain.tld;
      block-all-mixed-content;
      ">
Run Code Online (Sandbox Code Playgroud)

当我运行该应用程序时,它工作得很好,所有资源都加载得很好,但在控制台中我收到以下错误

通过元素传递的内容安全策略可能不包含frame-ancestors指令。索引.html: 4

我一直在尝试消除该错误并寻找可能导致该错误的原因,但找不到任何东西,对我来说一切似乎都是正确的,但我仍然收到错误,我还认为该错误可能是由服务器 @https 引起的://*.mydomain.tld 所以我尝试了这个

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy"
      content="
      default-src     'self';
      script-src      'self';
      style-src       'self';
      img-src         'self';
      font-src        'self';
      connect-src     'self';
      media-src       'self';
      object-src      'self';
      child-src       'self';
      frame-ancestors 'self';
      frame-src       'self';
      worker-src      'self';
      form-action     'self';
      block-all-mixed-content;
      ">
Run Code Online (Sandbox Code Playgroud)

这导致了完全相同的错误,我可以完全忽略该错误,因为应用程序确实可以正常工作,并且该错误似乎不会引起任何问题,但是如果有人知道可能出了什么问题,我将非常感激。

编辑:当我删除框架祖先时,标签看起来像这样

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy"
      content="
      default-src     'self' https://*.mydomain.tld;
      script-src      'self' https://*.mydomain.tld;
      style-src       'self' https://*.mydomain.tld;
      img-src         'self' https://*.mydomain.tld;
      font-src        'self' https://*.mydomain.tld;
      connect-src     'self' https://*.mydomain.tld;
      media-src       'self' https://*.mydomain.tld;
      object-src      'self' https://*.mydomain.tld;
      child-src       'self' https://*.mydomain.tld;
      frame-src       'self' https://*.mydomain.tld;
      worker-src      'self' https://*.mydomain.tld;
      form-action     'self' https://*.mydomain.tld;
      block-all-mixed-content;
      ">
Run Code Online (Sandbox Code Playgroud)

错误消失了,我不应该添加它吗?

小智 5

因为meta元素不支持该指令。查看https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors

仅取决于服务器的“响应”。