spaze / nonce-generator
内容安全策略nonce生成器
v4.0.1
2023-09-20 01:39 UTC
Requires
- php: ^8.2
- latte/latte: ^3.0
- nette/application: ^3.1
- nette/di: ^3.0
Requires (Dev)
Suggests
- spaze/csp-config: Build and send Content Security Policy header, possibly including nonce, if enabled
- spaze/sri-macros: For script tags with automatically added Content Security Policy nonces, and Subresource Integrity hashes, too
README
此工具生成随机nonce,用于内容安全策略的nonce属性。这些nonce与CSP3的strict-dynamic
一起使用,旨在使内容安全策略对现有应用程序的部署更加简单。此包旨在与Nette框架、spaze/csp-config
和spaze/sri-macros
一起使用。
用法
这是一个即插即用的生成器。
如果安装了,来自spaze/csp-config
的\Spaze\ContentSecurityPolicy\Config::addDirective()
将自动将nonce-...
属性添加到配置的指令中,来自spaze/sri-macros
的Latte宏{script ...}
和{stylesheet ...}
将分别添加到script
和style
属性中。此外,n:nonce
快捷方式也将使用相同的生成值。
安装
使用 Composer
composer require spaze/nonce-generator
将扩展添加到您的配置中
extensions: nonceGenerator: Spaze\NonceGenerator\Bridges\Nette\GeneratorExtension
要求
- PHP 8.2 或更高版本
- Latte 3.0 或更高版本
- Nette应用程序 3.1 或更高版本
- Nette DI 3.0 或更高版本
API
createNonce(): Nonce
生成并返回一个Nonce
对象。使用Nonce::getValue()
获取生成的nonce。