Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda