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

179
Vistas
Access Express res.render locals in <script> WITHOUT data being visible in source?

I've been doing this to access variables passed to the EJS template via Express's res.render:

router.route("/build")
.get([isLoggedIn, finishedRegistration], function(req, res){
    res.render("build", {loggedInUser: req.loggedInUser});
})

And then utilizing them on the client side within script tags as needed:

<script>
    var user = <%- JSON.stringify(loggedInUser) %>
  //do something with stringified variable
  //do another thing with it
</script>

This solution is given in many Stackoverflow questions, and it works fine, but if you peek at the source code in the browser...

<script>

    var user = {"tokens":-3,"_id":"615c62ba5d2315162893a4ac","username":"dev","email":"shg.webdev... (and so on)

Oops, everybody and their dog can see the data being stringified. This seems vulnerable to me. Is there an alternative way that doesn't expose data like that? Or, can I hide the stringified data from being seen in the source?

about 4 years ago · Juan Pablo Isaza
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