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

156
Visualizações
Modern best practice for innerHTML replacement when you want to insert formatted text?

From what I understand, setting innerHTML on an element is bad, because if the new contents come from users, a malicious user can use it to inject <script> tags and other harmful content.

As demonstrated by this question, there are now about eight different alternative tags (with some non-standard).

In my case, I want to be able to insert actual html tags like <b> and <i>, and even <a>.

But I never need <script> to be inserted.

Is there a standardized best-practice alternative to innerHTML using vanilla Javascript?

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

0

There are a million things you can mess up that will allow XSS if you do this yourself. Your best option is a library to sanitize the html for you.

See some options here Sanitize/Rewrite HTML on the Client Side

After you've sanitized it matters less which property you set.

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