UMalik214428 (Community Member) asked a question.

"CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)" flaw in my React app's file-download code.

The flaw is related to code for downloading a file after a user clicks a link. The file is fetched from my API as follows:

 

fetch(...)

.then((response) => {

  response.blob().then((blob) => {

    const url = window.URL.createObjectURL(new Blob([blob]));

    const link = document.createElement('a');

    link.href = url;

    link.setAttribute('download', `${fileName}`);

    document.body.appendChild(link); // <<<--- the flaw complains about this line

    link.click();

    if (link.parentNode)

      link.parentNode.removeChild(link);

  });

})

 

I don't know how to fix this. Any help would be appreciated.


Topics (1)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.