阅读Angular 安全指南后,我想:
到目前为止,这是我更改index.html的方式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline';" />
<meta http-equiv="Content-Security-Policy" content="trusted-types angular angular#unsafe-bypass; require-trusted-types-for 'script';" />
现在,我的控制台中有很多错误:
This document requires 'TrustedScript' assignment.
FooService EvalError: Refused to evaluate a string as JavaScript because this document requires 'Trusted Type' assignment.
我的问题:
- 是否可以定义
Content-Security-Policy
两次/两者:
一个用于“经典”CSP 配置,一个用于受信任类型?
是否有意义? - 它们如何相互关联?
- 我如何使它在本地和生产中工作?
- 我知道这个配置可能应该只在生产环境中激活(因为 JIT),
使用特定的index.production.html文件(参见参考资料)。我不是只为两个元属性复制index.html
的忠实粉丝...... - 我还看到我可以在 my 中使用该
headers
属性architect.serve.configurations.production
,
但我不确定它是否更好和/或等效
- 我知道这个配置可能应该只在生产环境中激活(因为 JIT),
- 我什至应该使用
trusted-types
?
Angular 安全指南推荐使用它,但仍处于试验阶段
我阅读了一些有趣的资源,但它们没有展示如何具体使用 CSP 属性。
我正在使用 Angular 13。