从html文件生成nginx内容安全策略头
nginxcsp的Python项目详细描述
nginx内容安全策略头生成器
此工具将从html文件中的导入域为nginx配置文件生成Content-Security-Policy
头。
用法
要从路径中的html文件生成Content-Security-Policy
头,可以使用以下命令:
nginxcsp /path/to/html/files --out /path/to/nginx.conf --override
该命令将为您的nginx.conf
文件的所有server
块生成Content-Security-Policy
、X-Content-Security-Policy
和X-WebKit-CSP
头,并删除以前的头。标题将从HTML文件中的标记生成,例如,如果您有一个带有标记<script src="https://cdnjs.cloudflare.com/some-script.js"></script>
的HTML文件,您将得到标题Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdnjs.cloudfare.com; img-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; object-src 'self'"
。
如果您只想创建Content-Security-Policy
头,则可以使用标志--csp
,这同样适用于--xcsp
的X-Content-Security-Policy
和--xwebkit
的X-WebKit-CSP
。
您可以使用nginxcsp -h
:
usage: nginxcsp html_path
Search content loading sources in HTML files and Content-Security-Policy
headers automatically.
positional arguments:
html_path the path of the HTML files
optional arguments:
-h, --help show this help message and exit
--out OUT NGINX configuration file to output the generated
headers
--server_name SERVER_NAME
the server_name in the NGINX server block to add CSP
headers
--port PORT the port from "listen {port}" line in a NGINX server
block to add CSP headers
--override flag to override the headers in the out file
--csp flag to generate only the Content-Security-Policy
header
--xcsp flag to generate only the X-Content-Security-Policy
header
--xwebkit flag to generate only the X-WebKit-CSP header