각진 안전하지 않은 링크
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
'programing' 카테고리의 다른 글
| @RunWith 및 @ContextConfiguration으로 주석이 달린 jUnit 테스트에서 Spring 컨텍스트에 액세스하는 방법은 무엇입니까? (0) | 2023.10.06 |
|---|---|
| Powershell에서 Start-Website 명령을 실행할 때 "파일을 만들 수 없습니다" 오류가 발생했습니다. (0) | 2023.10.06 |
| Oracle PL/SQL의 테이블 변수? (0) | 2023.10.01 |
| Vulkan: vk*CreateInfo structs에서 sType의 요점은 무엇입니까? (0) | 2023.10.01 |
| Vulkan: What is the point of sType in vk*CreateInfo structs? (0) | 2023.10.01 |