Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!