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

308
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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