-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Hi,
I have a few alerts about js/xss
I can't understand how to work around them.
Here is an example:
https://lgtm.com/projects/g/netdata/netdata/alerts/?mode=list&rule=js%2Fxss
As you can see, I have escaped everything, but still LGTM complaints about XSS:
function escapeUserInputHTML(s) {
return s.toString()
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/#/g, '#')
.replace(/'/g, ''')
.replace(/\(/g,'(')
.replace(/\)/g,')')
.replace(/\//g,'/');
}
function verifyURL(s) {
if(typeof(s) === 'string' && (s.startsWith('http://') || s.startsWith('https://')))
return s
.replace(/'/g, '%22')
.replace(/"/g, '%27')
.replace(/\)/g, '%28')
.replace(/\(/g, '%29');
console.log('invalid URL detected:');
console.log(s);
return 'javascript:alert("invalid url");';
}
Any ideas?
Thank you!