2017-12-20 13 views
2

これは、スクリプトタグ(以下に示す)を入力フィールドとその説明フィールドのいずれかに注入することに関するものです。値は細かく保存され、グリッドに表示されます。angularjsアプリケーションのXSS問題

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

フォームフィールド: -

enter image description here

アラートスクリプトは、説明フィールドから実行されている下のスクリーンショットで見ることができます。

モーダル実装(リストのドキュメントタイプリンクのクリック時に実行): -

$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'); 
       }; 
      } 
     }); 
    } 
}); 

入力パラメータは、いくつかの操作でスクリプトタグを持っている場合、それはそれとして、UIに表示されていません代わりに、スクリプトはモーダルの前に実行されています。

ここで期待される動作は、リスト内のアンカーをクリックすると、その説明がポップアップに表示されるはずです。ここで起こっているのは、説明を表示する前に、スクリプトタグの注入のために警告ウィンドウが表示されています。

ポップアップの前に警告スクリプトが実行されるのを避ける方法を教えてください。

以下のすべてのスクリーンショットを添付しました。

一覧ページ: -

Listing Page

警告ウィンドウ: -

Alert Window

説明ポップアップ: -

ありがとうございます。

+0

下にしてみてくださいことはできますか? (名前、リンクをお願いします)? それ以外の場合は、あなたの質問と同じくらい幅広い答えが表示されます。「浄化してください」 – 2oppin

+0

htmlコンテンツをサニタイズします。 https://docs.angularjs.org/api/ngSanitize/service/$sanitize – Ashish

+4

ユーザー提供のコンテンツとの文字列連結を介したHTMLの構築は、常に大きな点滅で行わなければなりません。* XSS VULNERABILITY *あなたのコードをリファクタリングできる場合それをしないために、私は非常にそれをお勧めします。そうでなければ '$ sanitize'します。 –

答えて

3

あなたはいくつかの標準的な公開/コンポーネントを使用してくださいコード

$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; 
     } 
    } 
    }); 
} 
+1

魅力のように動作します...ありがとうございました:) –

+1

将来の読者のための説明を追加すると非常に役に立ちます。 – Rachmaninoff