2016-08-04 18 views
0

$ sceDelegateProvider文檔https://docs.angularjs.org/api/ng/provider/ $ sceDelegateProvider指出您可以使用resourceUrlBlacklist來阻止打開的指示。

根據我的理解,$ sceDelegateProvider僅用於從ng-include等渲染模板時,如果將它們包含在黑名單中,它會停止加載這些資源。

混亂的部分,我是他們的文件看起來是這樣的:

:考慮以下情況。

他們的例子是這樣的:

angular.module('myApp', []).config(function($sceDelegateProvider) { 
    $sceDelegateProvider.resourceUrlWhitelist([ 
    // Allow same origin resource loads. 
    'self', 
    // Allow loading from our assets domain. Notice the difference between * and **. 
    'http://srv*.assets.example.com/**' 
    ]); 

    // The blacklist overrides the whitelist so the open redirect here is blocked. 
    $sceDelegateProvider.resourceUrlBlacklist([ 
    'http://myapp.example.com/clickThru**' 
    ]); 
}); 

您通常在AngularJS中執行重定向的方式是通過$ window.location.href,如果執行不正確,可能會使某人執行開放重定向。

我創建了一個示例應用程序,以反映什麼,我覺得這應該是這樣的:http://plnkr.co/edit/cjXsCVcRGwgtgqZr13mE?p=preview

的index.html:

<!doctype html> 
<html lang="en" ng-app="app"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Example - example-example85-production</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-animate.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-sanitize.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.js"></script> 
    <script src="script.js"></script> 
</head> 
<body> 
    <h1>Redirect Example</h1> 
    <p>Why doesn't this work?.</p> 

    <h2>Demo</h2> 
    <div> 
     <h3>redirect</h3> 
     <ng-view></ng-view> 
     <ul> 
      <li > 
       <a href="/redirect?url=https://angularjs.org"> 
        AngularJS (https) 
       </a> 
      </li> 
      <li> 
       <a href="/redirect?url=http://angularjs.org"> 
        AngularJS (http) 
       </a> 
      </li> 
     </ul> 
    </div> 

</body> 
</html> 

的script.js:

// script.js 
(function() { 
    'use strict'; 

    angular 
     .module('app', [ 
      'ngSanitize', 
      'ngRoute' 
     ]); 
})(); 

// app.config.js 
(function() { 
    'use strict'; 

    angular 
     .module('app') 
     .config(function ($sceDelegateProvider, $routeProvider) { 
     $sceDelegateProvider.resourceUrlWhitelist([ 
     // Allow same origin resource loads. 
     'self', 
     // Allow loading from our assets domain. Notice the difference between * and **. 
     'http://srv*.assets.example.com/**' 
     ]); 

     // The blacklist overrides the whitelist so the open redirect here is blocked. 
     $sceDelegateProvider.resourceUrlBlacklist([ 
     'http://example.com/redirect?url=https://angularjs.org', 
     'http://example.com/redirect?url=http://angularjs.org' 
     ]); 

      $routeProvider 
       .when('/redirect', { 
        template: '<em>redirecting', 
        controller: function ($scope, $location,$window) { 
         $scope.url = $location.$$search['url']; 
         $window.location.href = $scope.url; 
        } 
     }) 
      } 
     ); 
})(); 

誰能給如果文檔意味着其他的東西,我有些清楚嗎?

回答

0

回答我的問題...

的$ sceDelegateProvider不使用使用$位置和$窗口時,防止重定向。當加載ngRoute,指令,ngSrc,ngInclude等的模板時,$ sceDelegateProvider被嚴格使用,並且僅針對初始URL而不是最終目標進行檢查。

例如,如果您使用whitelist facebook.com並且它包含重定向到未列入白名單的頁面(例如malicious.com),只要它獲得惡意網站的CORS策略的認可,它仍會成功加載。

1

$ sceDelegateProvider只有sandboxes模板url解析和打開過程中發生的重定向。例如,如果您將ng-include白名單資源301重定向到不是列入白名單的其他資源,則會被拒絕。

它不會插入$ window.location(或$ location)。

+0

謝謝你對$ window和$ location的說明,我知道這一點,但它似乎是我能想到的唯一的東西。不幸的是,這是不正確的,我創建了一個PoC;如果您將某個網址列入白名單並且其中包含重定向,並且即使該重定向網址位於黑名單中或未包含在白名單中,只要啓用CORS,頁面就會加載(我相信這是因爲您已將上一頁列入白名單)。 我打算結果是,如果你在你的網站有一個開放的重定向,並且你知道它,你可以採取措施列入黑名單訪問該頁面。 – Lewis