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

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

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 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