-1

My code:

router.post('/loadDetails', async (req, res) => {
    try {
        var resultData = await myService.postRequest(req.body, 'myconfig/loadAllSDetails');
        res.send(resultData);
    }
    catch(error) {
        res.status(500).send(error.message);
    }
})

Here I am getting vulnerability while passing input and output as

The application's router.post embeds untrusted data in the generated output with send, at line 626 of routes\myConfigRouter.js. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.

The attacker would be able to alter the returned web page by simply providing modified data in the user input body, which is read by the router.post method at line 625 of routes\myConfigRouter.js. This input then flows through the code straight to the output web page, without sanitization.

This can enable a Reflected Cross-Site Scripting (XSS) attack.

I am passing req.body with sanitize method like below but it's not working:

sanitize(req.body);
  • What does `ltgService.postRequest` do? Please post its code or we won't be able to help you with it. – Bergi Aug 08 '23 at 23:27
  • "*it's not working*" - are you saying that you still have a vulnerability (that you can reproduce) and you don't know how to fix it, or are you saying that you are sure you sanitised the input correct but the xss warning won't go away? – Bergi Aug 08 '23 at 23:28
  • In the latter case, what kind of (automated) vulnerability scanner are you using? – Bergi Aug 08 '23 at 23:29
  • Yes after input sanitization vulnerability won't go away and i am using Scava Scanner – bhanu prakash Aug 09 '23 at 03:34
  • If you're sure it's fixed, just ignore the warning - it might still be a false positive. If the scanner is still reporting it, file an issue with them or contact their customer support. – Bergi Aug 09 '23 at 03:51
  • _"I am passing req.body with sanitize method"_ - shouldn't you rather be sanitizing what your route _returns_? This: `res.send(resultData);` – CBroe Aug 09 '23 at 07:49
  • yes doing same but still getting same issue can you please guide me here – bhanu prakash Aug 15 '23 at 17:16
  • Hi All, please suggest here to resolve the vulnerabilities in above snippet – bhanu prakash Aug 24 '23 at 18:18

0 Answers0