「Jenkins」- Note that ‘frame-src‘ was not explicitly set, so ‘default-src‘ is used as a fallback. @2

本文介绍了解决Jenkins测试报告页面加载失败的问题。主要表现为页面空白且控制台提示因ContentSecurityPolicy设置不当导致的错误。提供了两种解决方案:一是通过Script Console放宽安全策略(不推荐),二是设置Resource Root URL(推荐)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

在 Jenkins 中,当访问测试报告时,页面无法正常显示(页面没有显示内容)。浏览器控制台显示如下错误消息:

...
Refused to frame 'https://jenkins.example.com/' because it violates the following 
Content Security Policy directive: "default-src 'none'". Note that 'frame-src' was 
not explicitly set, so 'default-src' is used as a fallback.

Blocked script execution in '<URL>' because the document's frame is sandboxed and 
the 'allow-scripts' permission is not set.
...

软件版本:Jenkins 2.274 in Docker

解决方案

方案一、放宽规则(不推荐)

在 Script Console 中,执行 System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "") 脚本,以此来解决问题。

但是该方法放宽规则,官方并不鼓励该做法。并且我们使用该方法也没有生效,可能在新版本 Jenkins 中被废弃。

方案二、Resource Root URL(推荐)

官方推荐的方法:
1)为 Jenkins 服务再绑定新域名(当然要配置 Nginx 指向 Jenkins 服务);
2)并在 Manage Jenkins / Configure System / .. / Resource Root URL 中填写带地址;

参考文献

WikiNotes/Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.
Configuring Content Security Policy
javascript - Jenkins error - Blocked script execution in <URL>. because the document's frame is sandboxed and the 'allow-scripts' permission is not set - Stack Overflow
html - because the document's frame is sandboxed and the 'allow-scripts' permission is not set - Stack Overflow
javascript - Blocked script execution in because the document's frame is sandboxed - Angular application - Stack Overflow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值