programing

각진 안전하지 않은 링크

sourcejob 2023. 10. 6. 21:02
반응형

각진 안전하지 않은 링크

AngularJS에서, 다음 시나리오에서, Firefox는unsafe:다음과 같은 방식으로 생성되는 URL 앞에서.그런 다음 "주소를 이해할 수 없었습니다"라는 오류 페이지가 표시됩니다.이것은 내 로컬 PC의 파일 요청입니다.

링크:

<li ng-repeat="fruit in fruits">
    <a href="{{ fruit.link }}">{{ fruit.title }}</a>
</li>

배열:

$scope.fruits = [
    {   "title"     :   "Orange",
        "link"      :   "fruits_orange.html"  }
];

일부 보안 위험을 해결하기 위한 이 커밋(https://github.com/angular/angular.js/commit/9532234bf1c408af9a6fd2c4743fdb585b920531 )의 부작용을 확인할 수 있습니다.

이 커밋은 다음으로 시작하는 URL에 대해 이전 버전과 호환되지 않는 변경을 도입했습니다.file://(이후 https://github.com/angular/angular.js/commit/7b236b29aa3a6f6dfe722815e0a2667d9b7f0899 에서 완화되었습니다.

1.0.5 또는 1.1.3 Angular 중 하나를 사용한다고 가정합니다.JS 버전.그렇다면 에 대한 지원을 다시 활성화할 수 있습니다.file://구성별 URL$compileProvider다음과 같습니다.

angular.module('myModule', [], function ($compileProvider) {

  $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file):/);

});

또는 Angular 1.2.8 이상에서:

angular.module('myModule', [], function ($compileProvider) {

  $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file):/);

});

컨트롤러에 흰색 목록을 추가합니다.

Angular.js 1.2의 경우:

app.config(['$compileProvider', function($compileProvider) {
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|tel):/);
}]);

Angular 1.1.x 및 1.0.x의 경우 다음을 사용합니다.urlSanitizationWhitelist. 참고.

    angular.module('somemodule').config(['$compileProvider' , function ($compileProvider)
    {
          $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto):/);
    }]);

사용하고 있습니다.angular 1.4.0다음과 같은 형식으로 작동했습니다.

ng-href="http://{{baseURLHref}}{{baseURLPort}}/routingPathName"

추가하기http://처음에ng-href그것을 없애는 데 도움이 되었습니다.unsafe가 추가한ng-Sanitize

  • 만약에.https, 모든 것을 하드코딩하는 것은 문제가 되지 않습니다.
  • 하지만 두 환경 모두에서 작동해야 하는 시스템이 있는 경우, 다음의 프로토콜 탐지 기능을 사용할 수 있습니다.location.protocol

제가 변수를 설정하고 있습니다.$rootScope(그들은 내 사이트에서 CSS를 소비하는 프록시 서버의 문제를 돕습니다.)

angular.module('myApp').run(function ($route, $rootScope, $location) {
    $rootScope.baseURLHref = '';
    $rootScope.baseURLPort = '';
    if($location.host() != 'localhost'){
      $rootScope.baseURLHref = $location.host();
      $rootScope.baseURLPort = ':' + $location.port();
    }
    ...
<a href="{{applicant.resume}}" download> download resume</a>


var app = angular.module("myApp", []);

    app.config(['$compileProvider', function($compileProvider) {
         $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|local|data|chrome-extension):/);
        $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|local|data|chrome-extension):/);

        }]);

언급URL : https://stackoverflow.com/questions/15637133/unsafe-link-in-angular

반응형