dkhd / node-group-chat

Build A Group-Chat App in 30 Lines Using Node.js
143 stars 102 forks source link

XSS issue #12

Open weathon opened 4 years ago

weathon commented 4 years ago

If I set my name as <script>alert()</script>, it will pop up a alert. Which is a XSS issue

weathon commented 4 years ago

I wrote a function and I think it can fix the issue

xssdangerous = ['&','/', '<', '>', "'", '"', "$","`"] 
function axss(astring)
{
    for (var i = 0; i < xssdangerous.length; i++) {//forget the g
        var regex = new RegExp(xssdangerous[i], "g");
        astring=astring.replace(regex,"&#"+xssdangerous[i].charCodeAt(0)+";")
    }
    return astring;
}

Put it into server