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

89
Visualizações
How do i replace eval

I have some existing code that looks like this.

i = new Function("obj", "_", s);

The parameter s contains an executable javascript code, as a string. At a later point in the method, it gets called like

i.call(this, e, v)

I get a csp error for unsafeeval for the new Function line. How do I resolve this such that the unsafe eval does not come up again? Please help.

Basically what I'm trying to do is, I have a third party application which I have localised to fix the eval errors for CSP.

Why does the new Function cause the unsafe-eval error?

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

0

As @James mentioned, new Function("obj", "_", s) evaluates the s part, and generates a function based on the string.

It really depends on what's the s here. Is it dynamically calculated?

  • If no, then you can just copy the s as a real code:
const i = function(obj, _) {
  // paste s here
}
  • If yes, you will have to explicitly list all possible implementations. For example:
const i = function(obj, _) {
  if (xxx) {
    // implementation 1
  } else if (xxx) {
    // implementation 2
  }
}
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