Skip to content

false positives: js/xss #205

@ktsaou

Description

@ktsaou

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, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/#/g, '&#35;')
        .replace(/'/g, '&#39;')
        .replace(/\(/g,'&#40;')
        .replace(/\)/g,'&#41;')
        .replace(/\//g,'&#47;');
}

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions