
QNguyen509744 (Community Member) asked a question.
const result = await getHttpClient({
baseURL: utils.getApiUrl(),
headers: { Authorization: 'Bearer ' + utils.getAccessToken(req) }
}).get(url);
if (result) {
return res.send(result.data);
} else {
return res.sendStatus(404);
}
I have the code above having issue with res.send(data). How to fix that veracode xss above. Thanks
.png)
Hello @QNguyen509744 (Community Member) ,
Thank you for reaching out to the Community.
Is that your code that our scanner is flagging for an XSS flaw?
It may be best to open a support case and provide the scan link and flawID to further assist you on this issue.
Best regards,
Steven
Veracode Support Engineer
Hi @QNguyen509744 (Community Member) ,
Veracode Static Analysis reports CWE 80 when it can see that data from outside of the application is used written to an HTTP Response.
In the provided code it appears that the application is making an HTTP Request to a downstream API, then directly using that data in it's own HTTP Response. This is sometimes also done with an 'http proxy' that proxies external requests to an internal service.
Frequently, this is done with JSON responses, if this is the case you can help Veracode Static Analysis see that by changing from `res.data` to `res.json`. This should automatically close the flaw as Veracode Static Analysis will now be guaranteed this will always result in a "application/json" Content-Type header in the response.
You can find a similar example on line 17 here: https://runkit.com/relaxnow/63b3fd8eeff984000815131c/branches/master
If however, you are proxying HTML from another service you are tying the security of this application to the security of the other application. This can be dangerous to do if for example, the other service is a third party service that you are not in control of or if the underlying service does not appropriately encode user data in it's HTML.
Options you could consider include:
Please let me know if you have any remaining questions or concerns.
Thank you,
Boy Baukema