【发布时间】:2021-02-06 13:50:04
【问题描述】:
升级到TYPO3 10后发现了一个现象。我使用扩展 fh_debug 生成一个简单的 HTML 文件,该文件在标题中包含一个 CSS 文件。 Firefox 或 Opera 浏览器中的 CSS 样式内容很好地显示了这一点,没有任何问题。但是,如果在 TYPO3 10 网站的 url 下调用它,则会出现浏览器警告。
debug.html:10 拒绝加载样式表“http://localhost/devmulti/typo3conf/ext/fh_debug/Resources/Public/Css/fhdebug.css”,因为它违反了以下内容安全策略指令:“style -src‘无’”。请注意,'style-src-elem' 没有显式设置,因此 'style-src' 用作备用。
因此我改进了带有元标记的 HTML 文件以设置“style-src”。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Debug Devmulti</title>
<meta http-equiv="Content-Security-Policy"
content="default-src *; style-src 'self' http://localhost/devmulti/;"/>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link href="http://localhost/devmulti/typo3conf/ext/fh_debug/Resources/Public/Css/fhdebug.css" rel="stylesheet" media="screen" type="text/css"/>
</head>
<body>
<p>any HTML here.</p>
</body>
浏览器网址是:
http://localhost/devmulti/fileadmin/debug.html
如果我将相同的文件复制到 TYPO3 9 网站,那么它可以工作。
http://localhost/fileadmin/debug.html
如果我将相同的文件复制到文件系统上的目录中,那么它可以工作。
file:///home/franz/Arbeit/Franz/Debug/debug.html
我必须为 TYPO3 10 更改什么?
我暂时重命名了 2 个.htaccess 文件,但没有成功。
devmulti/fileadmin/.htaccess 和 devmulti/.htaccess 。我搜索了这些关于 style-src 的文件。
[franz@localhost devmulti]$ find . -name '*.*' -type f -exec grep -i 'default-src' {} \; -ls
protected const HEADER_PATTERN = '#(?<directive>default-src|script-src|style-src|object-src)\h+(?<rule>[^;]+)(?:\s*;\s*|$)#';
$defaultSrc = isset($this->directives['default-src'])
? $this->directiveMitigatesCrossSiteScripting($this->directives['default-src'])
922745 4 -rw-r--r-- 1 franz franz 2539 Feb 5 09:11 ./typo3_src-10.4.12/typo3/sysext/install/Classes/SystemEnvironment/ServerResponse/ContentSecurityPolicyHeader.php
content="default-src *; style-src \'self\' ' . $host . ';"/>
1326610 60 -rwxrwxrwx 1 franz franz 60236 Feb 6 17:30 ./typo3conf/ext/fh_debug/Classes/Utility/DebugFunctions.php
content="default-src *; style-src 'self' http://localhost/devmulti/;"/>
1177376 4 -rw-rw-r-- 1 franz franz 569 Feb 9 09:16 ./fileadmin/debug-stack1.html
content="default-src *; style-src 'self' http://localhost/devmulti/;"/>
1191268 4 -rwxrwxrwx 1 franz franz 4054 Feb 6 18:22 ./fileadmin/debug.html
Header set Content-Security-Policy "default-src 'self' 'unsafe-inline'; script-src 'none'; object-src 'self'; plugin-types application/pdf;"
Header set Content-Security-Policy "default-src 'self'; script-src 'none'; style-src 'none'; object-src 'none';"
1191266 4 -rw-rw-r-- 1 apache apache 1645 Feb 5 15:45 ./fileadmin/.htaccess
修改devmulti/fileadmin/.htaccessstyle-src 'self':
<IfModule mod_headers.c>
# matching requested *.pdf files only (strict rules block Safari showing PDF documents)
<FilesMatch "\.pdf$">
Header set Content-Security-Policy "default-src 'self' 'unsafe-inline'; script-src 'none'; object-src 'self'; plugin-types application/pdf;"
</FilesMatch>
# matching anything else, using negative lookbehind pattern
<FilesMatch "(?<!\.pdf)$">
Header set Content-Security-Policy "default-src 'self'; script-src 'none'; style-src 'self'; object-src 'none';"
</FilesMatch>
</IfModule>
这是一个独立的 HTML 文件。它不需要在浏览器中显示 TYPO3。它仅在文件系统中包含一个 CSS 文件。 这是使用的 CSS 文件:https://github.com/franzholz/fh_debug/blob/master/Resources/Public/Css/fhdebug.css
第一种解决方案:
删除文件devmulti/fileadmin/.htaccess 并等待一段时间。然后 HTML 文件与 CSS 样式的内容一起工作。只剩下这条消息。
Content Security Policy: The page's settings blocked the loading of a resource at inline ("default-src").
有没有更好的解决方案而不必删除TYPO3的标准.htaccess?
【问题讨论】:
-
通常 TYPO 通过
.htaccess文件发布 CSP,因此您不能在元标记中放松它。检查您是否在 TYPO3 10 中发布了 CSP HTTP 标头,教程是 here。 -
我得到这个响应头:
Cache-Control max-age=0 Connection Keep-Alive Date Mon, 08 Feb 2021 19:46:05 GMT Expires Mon, 08 Feb 2021 19:46:05 GMT Keep-Alive timeout=5, max=100 Server Apache/2.4.46 (Mageia) PHP/7.3.23我想知道为什么 TYPO3 会干扰 HTML 文件。重命名 .htaccess 文件也无济于事。而且我在其中找不到 CSP。 -
如果您在 HTTP 标头中没有看到 CSP,则只有一个选项 - 它在
<meta http-equiv="Content-Security-Policy"中发布。但是您的元标记不包含控制台违规消息中看到的style-src 'none'规则。检查双 CSP 元标记的 HTML 代码。一些浏览器扩展也会干扰。 -
我已将示例的 HTML 代码修改为完整。你可以在这里看到它,它应该可以正常工作。但是它有这些 CSP 错误。
Content Security Policy: The page's settings blocked the loading of a resource at http://localhost/devmulti/typo3conf/ext/fh_debug/Resources/Public/Css/fhdebug.css ("style-src"). -
fingerprint-protection.js:343:25与 TYPO3 无关,可能是您在浏览器中安装的一些广告拦截器(修改标记)
标签: css content-security-policy typo3-10.x