adrianAR (Community Member) asked a question.

How to solve XSS when using .textContent

¡Hello!

We are getting a XSS flow on the next code:

 

 let divPrincipal = document.createElement("div");

    divPrincipal.setAttribute("class", "col-4 text-center stack-order");

 

    let h2 = document.createElement("h2");

    h2.setAttribute("class", "no-margins");

    h2.textContent = pModelo.Total;

 

    let small = document.createElement("small");

    small.textContent = pModelo.Nombre;

 

    divPrincipal.appendChild(h2);

    divPrincipal.appendChild(small);

 

    return divPrincipal;

 

The flaw is marked in both append child, but I think there must not be problem, because we are using setAttribute for class and textContent for data. How can i solve this issue?

 

Thank you in advance.


  • Hi,

    You can raise this XSS finding reported on line for .textContent = $var as Potential False Positive.

    Regards

    Kashif

Topics (3)

No articles found
Loading

Ask the Community

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