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

143
Visualizações
How to prevent event handlers in HTML attributes from firing?

I recently learned that the browser will fire the toggle event of the details element simply by setting the contents on an element, even when it's not in the DOM. The following executes an alert:

document.createElement('p').innerHTML = "<details open ontoggle=\"alert('BAD')\">"

Same works for images and their onload event.

Compare this with using a script tag. The following does nothing:

document.createElement('p').innerHTML = "<script>alert('FINE')</script>"

Tested in Chrome and Firefox.

Is there a way to suppress execution of inline event handlers like this? Ideally something that can be set on the parent element

I considered adding an event handler on the parent, but the toggle event doesn't bubble!

An obvious solution is to sanitise the html source, but I am looking for something more graceful and bulletproof than string manipulation.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The answer is Content-Security-Policy. Simply don't allow unsafe-inline.

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