I was wondering if there is a programmatic way of sanitizing (user provided) URLs in AngularJs 1.5. I know there is $sanitize service, which is for sanitizing HTML but I can't find something that would work for URL.
Sample Good URL:
http://www.somedomain.com
Sample Dangerous URL:
javascript:document.write('Time for some fun');
There is undocumented
$$sanitizeUriservice that does this. It's basically a function that addsunsafeprefix to supplied URL. There's no need to use it for URLs are bound tohreflikebecause this is already done by compiler (
$$sanitizeUriis used there).For malformed URLs in general it may be better to process them by hand and possibly add
http://if it doesn't contain acceptable (http/https) protocol.