Assume that you have a form element with inputs, and the user insert to the input something like drop table users
. If you have weak server code or some service that you have no idea what it's security level you can loose your data.
Now, this is an example. There is a lot of ways to do bad things in similiar way.
Other example is to insert to images src
some url with query paramters like
<img
src='http://somehackingsite.com/images/lol.png?userIp="some scriptor other hacking style"' />
AngularJs offers a way to solve it by ngSanitize
Sanitizes an html string by stripping all potentially dangerous
tokens.
The input is sanitized by parsing the HTML into tokens. All safe
tokens (from a whitelist) are then serialized back to properly escaped
html string. This means that no unsafe input can make it into the
returned string.
The whitelist for URL sanitization of attribute values is configured
using the functions aHrefSanitizationWhitelist and
imgSrcSanitizationWhitelist of $compileProvider.