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

307
Vistas
XSS - Does loading external HTML by setting innerHTML on DOM element prevent attack?

If I will need to load some untrusted external HTML content and render them on the DOM, will using the innerHTML property be adequate protection against malicious scripts?

Through my own testing and this article, <script> tags inside HTML that is set via innerHTML to an existing element in the DOM (main or shadow) is not executed. So even if the script is there, would not executing it prevent security risks?

For added measure, it can also help to find all <script> tags and remove them in the DOM. Is this even necessary?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No, that's not good enough. Inline handlers can still execute - most notably, those that'll execute immediately. For example:

const untrustworthyContent = `
<div>
  <img src onerror="alert('evil');">
</div>
`;
document.querySelector('div').innerHTML = untrustworthyContent;
<div></div>

And anything can be put into such an inline handler attribute, including loading other malicious scripts.

For added measure, it can also help to find all tags and remove them in the DOM. Is this even necessary?

Best to do it thoroughly. Remove all <script> tags and inline handlers before even thinking about rendering.

about 4 years ago · Juan Pablo Isaza Denunciar
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