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

142
Vistas
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 Respuestas
Responde la pregunta

0

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

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