I use angular 2.1.2, and I want to use sanitize method to prevent XSS/CSRF attacks.
I implemented:
this.sanitizer.sanitize(SecurityContext.HTML, this.content)
The html file have html, style, javascript. So this method will unwrap the style and javascript.
But I just only want unwrap for javascript and skip html and style. So, any solution for me to implement this issue.
HTML before sanitation
<html>
<head><style>h2 {color: #FFFF7C}</style>
<script>alert("hi")</script>
</head>
<body>
<h2>HTML Content</h2>
</body>
</html>
Result after sanitation:
//HTML content: " h2 {color: #FFFF7C} alert("hi") <h2>HTML Content</h2> "
//HTML content view:
h2 {color: #FFFF7C} alert("hi")
HTML Content
Result expect:
alert("hi")
HTML Content //I expect this line will be applied the color: #FFFF7C
HTML Content
"`. The `style` tag is also unwrap. I just update post. – ThuyNguyen Jan 24 '18 at 07:50