如何使用Undafe-Inline' vaadin中的内容 - 安全性?
我正在使用vaadin开发一个应用程序,并且在引导流式列赛纳中使用内容 - 安全性。当我使用OWASP ZAP测试应用程序时,我对scripts-src'不安全inline'
(中等风险)有问题。当我删除“不安全的内线”时,我的应用程序不起作用。
我的代码:
String csp = "";
String defaultSrc = "default-src 'none'";
String styleSrc = "style-src 'unsafe-inline' 'self'";
String fontSrc = "font-src 'self'";
String scriptSrc = "script-src 'unsafe-inline' 'unsafe-eval' 'self'";
String imgSrc = "img-src 'self'";
String connectSrc = "connect-src 'self'";
String frameAncestors = "frame-ancestors 'self'";
String formAction = "form-action 'self'";
csp = Arrays.asList(defaultSenter code hererc,styleSrc,fontSrc,scriptSrc,imgSrc,connectSrc,frameAncestors,formAction).stream().collect(Collectors.joining(";"));
I am developing an application with Vaadin and I use Content-Security-Policy in my BootstrapListener. When I test my application with OWASP ZAP, I have problem with script-src 'unsafe-inline'
(medium risk). When I delete the 'unsafe-inline', my application doesn't work.
My code:
String csp = "";
String defaultSrc = "default-src 'none'";
String styleSrc = "style-src 'unsafe-inline' 'self'";
String fontSrc = "font-src 'self'";
String scriptSrc = "script-src 'unsafe-inline' 'unsafe-eval' 'self'";
String imgSrc = "img-src 'self'";
String connectSrc = "connect-src 'self'";
String frameAncestors = "frame-ancestors 'self'";
String formAction = "form-action 'self'";
csp = Arrays.asList(defaultSenter code hererc,styleSrc,fontSrc,scriptSrc,imgSrc,connectSrc,frameAncestors,formAction).stream().collect(Collectors.joining(";"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Vaadin 文档 使用
scriptSrc = "script-src 'unsafe-inline' 'unsafe-eval' 'self'";
是已知的“限制”或如果不对框架进行重大修改,您就无法更改开发人员的架构选择:XSS/代码注入安全方面,您可以做的(或可能已经做的)是使用 内置转义用于输出:
和清理:
此外,这些被标记为是有原因的“不安全-”,问题是如果框架中存在缺陷或者您错过了转义,那么 CSP 无法区分注入的代码和原始代码。您应该始终通过将自己的安全脚本放入外部文件或使用 nonce 来“标记”您自己的安全脚本。
As per Vaadin documentation using
scriptSrc = "script-src 'unsafe-inline' 'unsafe-eval' 'self'";
is a known "limitation" or architectural choice of the devs that you can't change without major modifications in the framework:XSS/Code injection securitywise, what you can do (or may already did) is using the built in escaping for outputs:
and sanitization:
Furthermore there is a reason why those are marked as "unsafe-", the problem is that if there is a flaw in the framework or you miss an escaping then CSP can't differentiate injected code from the original. You should always "tag" your own safe scripts by putting them in external files or using nonce.
因此,如果我使用此代码
scriptsrc =“ script-src'nonce-rand 0m''unsaffe-eval''self'';
它行不通。我有此错误
拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“ script-src'nonce-rand land land land 0m''unnesfafe-eval''self'“”。需要“不安全限制”关键字,即Hash('SHA256-2+3KFFW9BJFUMMZU872AJ+B2DMGLMN/HEL8BO8Y9XG ='),或者需要nonce('nonce -...')来启用内线执行。
So if I use this code
scriptSrc = "script-src 'nonce-rAnd0m' 'unsafe-eval' 'self'";
It doesn't work. I have this error
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'nonce-rAnd0m' 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-2+3KFFww9bjFUMmzU872aJ+b2DMgLMn/Hel8bO8Y9xg='), or a nonce ('nonce-...') is required to enable inline execution.