我使用“create-react-app”创建了一个示例react应用程序。我需要使用X-Frame-options
和Content-Security-Policy
设置请求 header 。我该怎么做呢?我只是尝试用下面的代码更新index.html
,但是我不确定这是否正确。有人能帮忙吗?
<meta http-equiv="Content-Security-Policy" content="frame-ancestors 'none'">
<meta http-equiv="X-Frame-Options" content="SAMEORIGIN">
最佳答案
仅仅修改index.html
还是不够的,至少对于X-Frame-Options
而言。每OWASP:
Common Defense Mistakes
Meta-tags that attempt to apply the X-Frame-Options directive DO NOT WORK. For example, ) will not work. You must apply the X-FRAME-OPTIONS directive as HTTP Response Header...
MDC具有a similar warning。
我花了一些时间寻找,但是没有找到在React本身中设置
X-Frame-Options
的方法。有一些方法可以在服务器级别或以其他语言(例如for Tomact或in Java或with webpack或configure it with Spring Security)来执行,这可能对您没有帮助。React似乎也不支持
Content-Security-Policy
……至少是not as of 2013,我进行了搜索,但没有发现位置的最新变化。
关于reactjs - 如何为使用 'create-react-app'创建的React应用设置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49896667/