SkyCrypt icon indicating copy to clipboard operation
SkyCrypt copied to clipboard

Sanitize item names to prevent possible future XSS attacks

Open dukio opened this issue 3 years ago • 4 comments

If hypixel will ever allow players to rename one of their items with a custom name we are at risk of XSS attacks (tested). We need to sanitize item.display_name and item.display_name_print

My 2 minute google search found this on stack overflow, but it's probably better to use something more advanced. Keep in mind item.display_name_print will contain HTML tags that must not be sanitized.

if (/[<>&]/.test(item.display_name)) {
    const tagsToReplace = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;'
    }

    item.display_name = item.display_name.replace(
        /[&<>]/g,
        tag => tagsToReplace[tag] || tag
    )
}

dukio avatar May 16 '21 22:05 dukio

Thank you for bringing this issue to our attention. Expect a developer to comment within the first 2-3 days of issue submission

github-actions[bot] avatar May 16 '21 22:05 github-actions[bot]

we could also probably use <%= %>

nstringham avatar May 16 '21 22:05 nstringham

we could also probably use <%= %>

I just had to change some of those to print the HTML for master stars. Also the issue seems to be mainly when we output the calculated and items in json to be parsed by js (I didn't dig too far into this since it wasn't a real issue for the moment).

dukio avatar May 16 '21 22:05 dukio

I doubt that Hypixel will ever allow custom item names because there would be a lot of work required to keep the names of people's items free from abusive content

nstringham avatar May 16 '21 23:05 nstringham

@metalcupcake5 what Nate said ^^

DuckySoLucky avatar Aug 07 '23 17:08 DuckySoLucky