fix(core): Remove sensitive data from User entity during serialization (no-changelog) (#8773)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-02-29 14:20:39 +01:00 committed by GitHub
parent 75e4df138f
commit d1b48ddcac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -141,4 +141,9 @@ export class User extends WithTimestamps implements IUser {
scopeOptions,
);
}
toJSON() {
const { password, apiKey, mfaSecret, mfaRecoveryCodes, ...rest } = this;
return rest;
}
}

View file

@ -0,0 +1,20 @@
import { User } from '@db/entities/User';
describe('User Entity', () => {
describe('JSON.stringify', () => {
it('should not serialize sensitive data', () => {
const user = Object.assign(new User(), {
email: 'test@example.com',
firstName: 'Don',
lastName: 'Joe',
password: '123456789',
apiKey: '123',
mfaSecret: '123',
mfaRecoveryCodes: ['123'],
});
expect(JSON.stringify(user)).toEqual(
'{"email":"test@example.com","firstName":"Don","lastName":"Joe"}',
);
});
});
});