-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSP and Ionic 2 (Angular 2), 'Refused to load the image "unsafe:cdvphotolibrary"' #15
Comments
Nice finding. I don't use ng2 in my current project, so I cannot tell exactly what's going on here, but... |
@viskin Apologies if this is not the same issue--I'm using Angular 1.5 and I get this error when I try to construct the url:
My CSP tag looks like:
|
@metalaureate, as explained, Angular 1 and 2 will always sanitize data that gets injected into the DOM, it will not respect any CSP rules present, thus also in Angular 1 you need to whitelist the var app = angular
.module('myApp', [])
.config([
'$compileProvider',
function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|cdvphotolibrary):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}
]); |
@viskin, the So as a note to the use of Ionic 2, one can construct a Pipe, to sanitize the URL's used in this plugin. Another solution might be returning a @Pipe({name: 'safeUrl'})
export class Safe {
constructor(private sanitizer:DomSanitizer){}
transform(url) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
} @Component({
selector: 'app',
template: '<img [src]="url | safeUrl"></div>',
pipes: [
SanitizeHtml
]
})
export class AppComponent{
public url: string = 'placeholder.jpg';
constructor() {
// fetch thumbnail URL's
this.url = libraryItem.thumbnailURL;
}
} |
Great, I will add this info to README. @dnmd, we already support returning blob instead of url with photoLibrary.getThumbnail and photoLibrary.getPhoto. |
I have some issues with sanatization. The guideline for Angular 2 in the Readme is not correct. However, even after doing that, I get Does anybody else has this issue in ios ? |
@ArberK Thanks, I updated the readme. |
Can anybody give the syntax for IONIC 1 i.e angular 1 as i have project running in Angular 1. Any help is highly appreciated. |
Excellent plugin, I hope it becomes part of the native plugins soon, I'll contribute where possible (and will look into making the wrapper)!
Just a small issue, I think it is related to CSP and Angular 2 (thus Ionic 2), but I can't get thumbnails to be displayed without sanitizing the URL's. When doing so, the whole
<meta>
tag is not required anymore, therefore it feels wrong but it is the only way I got it working. Maybe I'm missing something... I posted my current solution below.The text was updated successfully, but these errors were encountered: