【发布时间】:2018-07-05 04:14:45
【问题描述】:
我有一个扩展WebSecurityConfigurerAdapter 的WebSecurityConfiguration。在其中,我为 CSP 随机数生成随机散列。
private static final String CSP = "script-src 'self'{nonce}; style-src 'self' https://fonts.googleapis.com/; img-src 'self'; font-src https://fonts.gstatic.com/; object-src 'none'; connect-src 'self'; report-uri http://127.0.0.1:8080/report";
public String CSP_NONCE;
@Override
protected void configure(HttpSecurity http) throws Exception
{
CSP_NONCE = Util.byteArrayToHex(Util.RandomHash()); // Generate a random hash.
http.headers()
.contentTypeOptions().and()
.xssProtection().and()
.cacheControl().and()
.httpStrictTransportSecurity().and()
.frameOptions().and()
.contentSecurityPolicy(CSP.replace("{nonce}", " 'nonce-" + CSP_NONCE + "'"));
}
我想从其中一个控制器类中访问这个哈希值,但由于 WebSecurityConfiguration 没有被实例化,我只能对其进行静态引用,这不起作用。
如何直接访问此类或在WebSecurityConfiguration 和其中一个控制器之间传输信息?
【问题讨论】:
标签: java spring model-view-controller content-security-policy nonce