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

301
Vistas
Secure way to sanitize an object (javascript)?

In order to avoid the JavaScript delete operator (ref:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/delete) I am currently using object destructuring to get rid of private properties:

//sample helper-function in ts

const sanitizeUser = (user: User): UserSanitized => {
                const { googleData, ...rest } = user
                return rest
            }

My question is, if the return value sanitizeUser can be securely used, without the possibility to recover the googleData property.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can be sure that the object returned by sanitizeUser will not have the googleData property. That probably means there's no way to get to that property's value from that "sanitized" object, but that depends entirely on the User object. If the User object has any properties that refer back to it (as is sometimes the case with parent/child relationships), then the sanitized object returned by sanitizeUser will have that property too — and it will still refer to the original User object, so it would be possible to get to googleData via that property.

Here's an example of that using equivalent JavaScript code:

const sanitizeUser = (user/*: User*/)/*: UserSanitized*/ => {
    const { googleData, ...rest } = user;
    return rest;
};

const user = {
    googleData: "secret data!",
};
user.self = user;

const sanitized = sanitizeUser(user);
console.log(sanitized.self.googleData); // "secret data!"

But if the User object doesn't have anything referring back to itself (directly or indirectly), then no, the sanitized object is fine and there's no way to get back to the googleData property from it.

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