I am creating a webapp and users can dynamically create HTML content. Is it safe (e.g. wrt XSS attacks) so that they can create links starting with # ?
I donโt know why this will not happen - maybe I'm just paranoid. (My Javascript code does nothing specific for # urls.)
In any case, one of the reasons I ask is because I use the Google Caja html-sanitizer to sanitize HTML. It filters URL: s, however the default filter looks like this:
function urlX(url) { if(/^https?:\/\//.test(url)) { return url }}
That is, the protocol should be specified and allowed only HTTP and HTTPS, but not javascript: I recently changed the URL filtering function:
function urlX(url) { if (/^https?:\/\//.test(url) || /^#/.test(url)) return url; }
(That is, #.... also allowed.)
I thought maybe I should ask if you think the #... links are safe?
(For example, the browser will not do anything crazy with links such as `href = '# javascript: ....'? Well, itโs not (not my browser), but maybe there are others .. something else. .. what I do not know)
source share