Manikandan Ram
Manikandan Ram

Reputation: 231

WARNING: sanitizing HTML stripped some content, see http://g.co/ng/security#xss

I have getting warning like this in my angular sample.

WARNING: sanitizing HTML stripped some content, see http://g.co/ng/security#xss

Stackblitz: https://stackblitz.com/edit/angular-e4otvr-mjm48m?file=app.component.ts

Some one please help me out of here.

Thanks in advance.

I have tried this solution.

https://blog.angularindepth.com/warning-sanitizing-html-stripped-some-content-and-how-to-deal-with-it-properly-10ff77012d5a

Still warning occurs.

getCellContent(e): string {


    if (e && e.targetCell.className.indexOf('e-valuescontent') > -1 ) {
        template = '<input type="checkbox">'; //Here,  you can append the html elements

    }
     else {
        template = '';
     }

    return this.sanitizer.sanitize(SecurityContext.HTML, template) || '';
}

WARNING: sanitizing HTML stripped some content, see http://g.co/ng/security#xss

Upvotes: 0

Views: 2568

Answers (1)

Chinmoy Acharjee
Chinmoy Acharjee

Reputation: 550

Have you tried this?

return this.sanitizer.bypassSecurityTrustHtml(template);

instead of

return this.sanitizer.sanitize(SecurityContext.HTML, template) || '';

Angular needs to trust the html you inserting through innerHTML. This bypassSecurityTrustHtml(template) method will help. It worked for me. Let me know yours.

Upvotes: 1

Related Questions