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

113
Visualizações
Check SVG with JS dompurify

I'm using DomPurify to sanitize SVG code.

It works fine however I would like to show a message if SVG code entered in a textarea is not valid.

I'm trying to compare the SVG code added with the SVG code sanitized. If they are different I will show a message.

function validate() {
  if( svgCode.trim() === DOMPurify.sanitize(svgCode).trim() ) {
    console.log('All right!');
  } else {
    console.log('Uuuh-oooh! The SVG code is not valid!');
  }
}

validate();

The issue: I keep getting Uuuh-oooh! The SVG code is not valid! because dompurify turns closing paths like /> into full paths '`.

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

0

You can use removed property to check if any sanitization happened or not.

e.g.

  DOMPurify.sanitize('<svg onload=alert(1) />');
  console.log(DOMPurify.removed.length); // 1
  DOMPurify.sanitize('<svg />');
  console.log(DOMPurify.removed.length); // 0

https://github.com/is2ei/DOMPurify#okay-makes-sense-lets-move-on

After sanitizing your markup, you can also have a look at the property DOMPurify.removed and find out, what elements and attributes were thrown out. Please do not use this property for making any security critical decisions. This is just a little helper for curious minds.

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