当前位置: 首页 > 面试题库 >

Jenkins错误-阻止脚本执行 。因为文档的框架是沙盒,并且未设置“允许脚本”权限

董高逸
2023-03-14
问题内容

我知道,如果我们在HTML中使用iFrame,则必须对其进行沙箱处理,并添加“ allow-scripts”权限为true。

但是我的问题是我的纯Angular JS应用程序中根本没有iFrame。当我在本地计算机上运行它时,它可以正常工作。

将其部署到服务器后,Chrome会显示此错误消息以及以下错误:

拒绝加载样式’bootstrap.min.css’,因为它违反了以下内容安全策略指令:“ style-src’self’”。

在dashboard.html中阻止了脚本执行,因为文档的框架已被沙箱化,并且未设置’allow-scripts’权限。

我不是从第三方网站或其他地方调用该页面,而这可能会注入我的源并将其显示在iframe中。我检查了代码,并且可以确认根本没有iframe。

顺便说一句,我使用的是Chrome(26)和Firefox(10)的非常旧的版本[组织限制]。IE11上也会发生这种情况(尽管没有错误消息显示),页面也无法加载。

是什么原因造成的?我在这里想念什么吗?任何指针将不胜感激。

以下是我要执行的操作的快照。琐碎的部分已修剪..

<html lang="en" ng-app="dashboard">
   <head>
      <title>Dashboard</title>
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <script src="js/jquery.min.js"></script>
      <script src="js/angular.min.js"></script>
      <script src="js/ui-bootstrap-tpls-0.6.0.js"></script>
      <script src="js/bootstrap.min.js"></script>
      <script src="js/notifications.js"></script>
      <style>
         body { background-color: #F3F3F4; color: #676a6c; font-size: 13px;}
      </style>
      <script>
         var dashboardApp = angular.module('dashboard', ['ui.bootstrap', 'notificationHelper']);

         Type = {
            APP : 0, CTL : 1
         }


         function DashboardCtrl($scope, $location, $timeout, $http, $log, $q) {
            $scope.environments = [ { ... }];
            $scope.columns = [ { ... } ];

             $scope.Type = window.Type;
            $scope.applications = [{ ... }];

            $scope.selectedEnv = null;

            var resetModel = function(applications) {
                applications.forEach(function(app) {
                     var hosts=$scope.findHosts(app, $scope.selectedEnv);
                     if(hosts){
                         hosts.forEach(function(host){
                             $scope.initStatus(app.status,host);
                         });
                     }
                });
            };

            var timeoutPromise = null;

             $scope.initStatus = function (status,host) {
                 status[host]=[{
                     ...
                 }];

             };             
         }

      </script>
   </head>
   <body ng-controller="DashboardCtrl">
      <div class="request-notifications" ng-notifications></div>
      <div>
         <tabset>
            <tab ng-repeat="env in environments" heading="{{env.name}}" select="set(env)" active="env.tab_active">
               <div class="col-md-6" ng-repeat="column in columns" ng-class="{'vertical-seperator':$first}">
                  <div class="panel" ng-class="{'first-child':$first}">
                     <div class="panel-heading">
                        <h3>{{column.column}}</h3>
                     </div>
                     <div class="panel-body">
                        <div class="frontends" ng-repeat="layer in column.layers">
                           <h4>{{layer.name}}</h4>
                           <div class="category" ng-repeat="category in layer.categories" ng-class="category.css">
                              <div class="category-heading">
                                 <h4>{{category.name}}</h4>
                              </div>
                              <div class="category-body group" ng-repeat="group in category.groups">
                                 <div ng-if="!env[group.host]">
                                    <h4>{{group.name}}</h4>
                                    <span class="label label-danger">Not deployed</span>
                                 </div>
                                 <div ng-repeat="host in env[group.host]">
                                    <div class="group-info">
                                       <div class="group-name">{{group.name}}</div>
                                       <div class="group-node"><strong>Node : </strong>{{host}}</div>
                                    </div>
                                    <table class="table table-striped">
                                       <thead>
                                          <tr>
                                             ...
                                          </tr>
                                       </thead>
                                       <tbody>
                                          <tr class="testStatusPage" ng-repeat="app in apps | filter: { column: column.column, layer: layer.name, category: category.name, group: group.name } : true">
                                             <!-- Application Home Links -->
                                             <td class="user-link" ng-if="app.type === Type.A || app.type === Type.A1 || app.type === Type.B || app.type === Type.B1 || app.type === Type.C"><a href="{{app.link}}">{{app.text}}</a></td>                                                                                          <td ng-if="app.status[host].statusCode == 0" class="result statusResult"><span class="label label-success">Success</span></td>
                                             <td ng-if="app.status[svr].status != null && app.status[host].status != 0" class="result statusResult"><span class="label label-danger">{{app.status[host].error}}</span></td>
                                          </tr>
                                       </tbody>
                                    </table>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </tab>
         </tabset>
      </div>
   </body>
</html>

问题答案:

我们在Jenkins userContent目录中使用了此内容HTML。我们最近升级到最新的Jenkins 1.625
LTS版本,似乎他们引入了新的内容安全策略,该策略将以下标头添加到响应标头中,浏览器只是拒绝执行样式表/ Javascript之类的内容。

X-Content-Security-Policy: sandbox; default-src 'none'; img-src 'self'; style-src 'self';

为了克服它,我们只需要通过重置Jenkins中的below属性来删除此标头。

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

那些升级到Jenkins 1.625并使用userContent文件夹的用户可能会受到此更改的影响。

有关更多信息,请参阅https://wiki.jenkins-
ci.org/display/JENKINS/Configuring+Content+Security+Policy



 类似资料:
  • 问题内容: 我正在尝试从Jenkins运行PowerShell脚本,但是它似乎完全忽略了执行策略!通过直接执行powershell.exe或使用PowerShell插件来实现 附加信息: Jenkins作为Windows服务运行(使用本地系统帐户,非交互式)。连接到该服务器并检查执行策略确实是: 但是,在运行Jenkins构建时,情况并非如此。这是在构建步骤中执行的输出: 我还尝试从构建步骤明确设

  • 问题内容: 当我尝试在Jenkins控制台中执行以下Groovy脚本时,发生以下错误。 这已从“ 使用Jenkins”>“ Jenkins脚本控制台”>“参数化系统Groovy脚本”中获取。 该错误表明它包含一些缺少的属性: 我已经尝试使用Groovy脚本插件从Jenkins运行RunningGroovy命令,但在我的情况下不起作用。 问题答案: 如果我→ 执行系统Groovy脚本 → Groov

  • 问题内容: 我是詹金斯的新手,需要帮助。 我有4个Shell脚本:test1.sh,test2.sh,test3.sh和test4.sh 我希望test2.sh仅在test1.sh成功运行时运行,而test4.sh仅在test3.sh成功运行时运行。我还希望test1.sh和test3.sh并行运行。 我如何在詹金斯实现呢? 我正在使用“使用ssh在远程主机上执行shell脚本”和“有条件的步骤(

  • 本文向大家介绍Powershell直接脚本时出现无法加载文件因为禁止执行脚本,包括了Powershell直接脚本时出现无法加载文件因为禁止执行脚本的使用技巧和注意事项,需要的朋友参考一下 在Powershell直接脚本时会出现: 无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。 所在位置 行:1 字符: 17

  • 我能够在Jenkins管道脚本中以沙盒和非沙盒模式使用@Grab注释。我的问题是,依赖项在默认情况下是针对maven central repository解决的,但我需要针对我们公司的Artifactory解决它们。要演示此问题,请使用以下简单的管道脚本: 当我按原样运行脚本时,我将在输出中看到类的完全限定名称。然而,当我取消注释与公司artifactory脚本中公开的依赖项一起工作的注释行时,失

  • 问题内容: 可以说我有一个纯文本文件,并且我的Web服务器上有一个PHP脚本。 我想做的是防止用户直接键入和查看文本文件,但我仍然希望人们能够加载从文件中读取内容并对其进行处理的文件(可能显示文件的内容) 。 此外,如果可以做到,那么最好的方法是什么? 问题答案: 是的,这很容易做到。 阻止用户访问的主要方法有两种。第一种是将其放置在Web文件夹之外的文件夹中(通常称为或),第二种是使用examp