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

126
Visualizações
new Function("JS string") unavoidable?

On an API call from online stores to our Rails app, I need to send strings of HTML, CSS and JS to build a modal on their frontend. If the HTML and CSS are not an issue, the JS looks problematic as I am willing to use new Function ("js script in string") to add JS to my modal.

I read everywhere that new Function(), like eval(), is not secure at all but I cannot see any other way to do it.

To give more context, I am subject to two constraints

  • I have hundreds of templates saved in my DB (template_id, html, css, js) that can be called by each store
  • I need to access functions/modules that have been declared before like in the example below
import moduleX from 'moduleX'

const functionX = () => { something() }

const runJS = (js_string) => {
  const specificJS = new Function('moduleX', 'functionX', js_string)
  specificJS(moduleX, functionX)
}

const buildPopup = (popup_data) => {
  insertHtml(popup_data.html)
  insertCss(popup_data.css)
  runJS(popup_data.js)
}

Is there a more secure way to do it?

about 4 years ago · Santiago Trujillo
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