简体   繁体   English

angularjs应用程序中的XSS问题

[英]XSS issue in the angularjs application

This is regarding injecting the script tag (given below) in one of the input and it's description field. 这是关于在输入及其描述字段之一中注入脚本标记(如下所示)。 Values are saving fine and showing in the grid. 值可以很好地保存并显示在网格中。

Go to this <script>window.alert('abc')</script> and fill out the FAFSA.

Form fields:- 表格栏位:-

在此处输入图片说明

You can see in the below screenshot that the alert script is running from the description field. 您可以在下面的屏幕截图中从描述字段中看到警报脚本正在运行。

Modal implementation (execute on click of the document type link in the listing):- 模态实现(单击列表中的文档类型链接即可执行):-

  $rootScope.showNormalModal = function (message) {
        var modalHtml = "<div class='modal-header'><button type='button' ng-click='cancel()' class='close' data-dismiss='modal' aria-label='Close'>" +
            "<span aria-hidden='true'>×</span></button> " +
            "<h4 class='modal-title' id='myModalLabel'><div>" +
            "</div>" + message + "</h4></div>";

        var modalInstance = $modal.open({
            template: modalHtml,
            controller: function ($scope, $modalInstance) {
                $scope.cancel = function () {
                    $modalInstance.dismiss('cancel');
                };
            }
        });
    }
});

If the input parameter has script tag with some operation, it is not showing in the UI as it is, instead the script is running before the modal. 如果输入参数具有执行某些操作的脚本标记,则它不会按原样显示在UI中,而是脚本在模式之前运行。

Expected behavior here is when I clicked on the anchor in the listing, it should show its description in the popup. 预期的行为是当我单击列表中的锚点时,它应该在弹出窗口中显示其描述。 what is happening here is, before showing the description, I am getting a alert window because of the script tag injection. 这里发生的是,在显示描述之前,由于脚本标签的插入,我得到了一个警报窗口。

How will I avoid the alert script getting executed before the popup. 我如何避免警报脚本在弹出窗口之前执行。

Attached all the screenshots below. 随附以下所有屏幕截图。

Listing Page :- 列表页:-

列表页面

Alert Window :- 警报窗口:-

警报窗口

Description Popup :- 说明弹出窗口:-

描述

Thanks in advance. 提前致谢。

Can you please try below code 可以请您尝试以下代码

$rootScope.showNormalModal = function (message) {
  var modalHtml = "<div class='modal-header'><button type='button' ng-click='cancel()' class='close' data-dismiss='modal' aria-label='Close'>" +
    "<span aria-hidden='true'>×</span></button> " +
    "<h4 class='modal-title' id='myModalLabel'><div>" +
    "</div><div ng-bind=\"message\"></div></h4></div>";

  var modalInstance = $modal.open({
    template: modalHtml,
    controller: function ($scope, $modalInstance, message) {
      $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
      };
      $scope.message = message;
    },
    resolve: {
      message: function () {
        return message;
      }
    }
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM