Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
xss prevention with innerHtml and quotes

I am trying to implement rule 1 in the OWASP XSS prevention cheat sheet. Rule 1 states the following characters should be encoded before inserting them into the body of a <div>:

 & --> &amp;
 < --> &lt;
 > --> &gt;
 " --> &quot;
 ' --> &#x27;

My goal is to insert the encoded characters into the DOM and have them render as their non encoded values. However this does not seem to be possible, with quotes.

When you put either &quot; or &#x27; into the innerHTML of a div, the browser converts it back to " or '.

document.getElementById("encodingNotWorking").innerHTML = "&amp; &gt; &lt; &quot;  &#x27; &#39; &#34;"

let domData = document.getElementById("encodingNotWorking").innerHTML;

document.getElementById("actualCharacters").innerText = domData;
Encoded quote characters:
<div id = "encodingNotWorking">
</div>

Characters in the dom:
<div id = "actualCharacters">
</div>

(JSFiddle)

How can I put the encoded entities (quotes) into the DOM, have them render as their non encoded values, and verify the encoded entities are actually in the DOM?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda