Skip to content

Commit 1115f12

Browse files
author
Arthur Cinader
committed
Strip personally identifiable information from user table for unauthorized users.
- add a config option to explicitly enumerate pii fields beyond email - in query controller, strip pii of user table results before sending out the door.
1 parent 11f7712 commit 1115f12

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

src/Config.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class Config {
3434
this.fileKey = cacheInfo.fileKey;
3535
this.facebookAppIds = cacheInfo.facebookAppIds;
3636
this.allowClientClassCreation = cacheInfo.allowClientClassCreation;
37+
this.userSensitiveFields = cacheInfo.userSensitiveFields;
3738

3839
// Create a new DatabaseController per request
3940
if (cacheInfo.databaseController) {

src/ParseServer.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class ParseServer {
113113
webhookKey,
114114
fileKey,
115115
facebookAppIds = [],
116+
userSensitiveFields = [],
116117
enableAnonymousUsers = defaults.enableAnonymousUsers,
117118
allowClientClassCreation = defaults.allowClientClassCreation,
118119
oauth = {},
@@ -155,6 +156,11 @@ class ParseServer {
155156
throw 'When using an explicit database adapter, you must also use an explicit filesAdapter.';
156157
}
157158

159+
userSensitiveFields = Array.from(new Set(userSensitiveFields.concat(
160+
defaults.userSensitiveFields,
161+
userSensitiveFields
162+
)));
163+
158164
const loggerControllerAdapter = loadAdapter(loggerAdapter, WinstonLoggerAdapter, { jsonLogs, logsFolder, verbose, logLevel, silent });
159165
const loggerController = new LoggerController(loggerControllerAdapter, appId);
160166
logging.setLogger(loggerController);
@@ -222,7 +228,8 @@ class ParseServer {
222228
revokeSessionOnPasswordReset,
223229
databaseController,
224230
schemaCacheTTL,
225-
enableSingleSchemaCache
231+
enableSingleSchemaCache,
232+
userSensitiveFields
226233
});
227234

228235
// To maintain compatibility. TODO: Remove in some version that breaks backwards compatability

src/RestQuery.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,16 @@ RestQuery.prototype.replaceDontSelect = function() {
386386
})
387387
};
388388

389+
const cleanResultOfSensitiveUserInfo = function (result, auth, config) {
390+
if (auth.isMaster || ( auth.user && auth.user.id === result.objectId)) {
391+
return;
392+
}
393+
394+
for (const field of config.userSensitiveFields) {
395+
delete result[field];
396+
}
397+
}
398+
389399
// Returns a promise for whether it was successful.
390400
// Populates this.response with an object that only has 'results'.
391401
RestQuery.prototype.runFind = function(options = {}) {
@@ -407,7 +417,7 @@ RestQuery.prototype.runFind = function(options = {}) {
407417
if (this.className === '_User') {
408418
for (var result of results) {
409419
delete result.password;
410-
420+
cleanResultOfSensitiveUserInfo(result, this.auth, this.config);
411421
if (result.authData) {
412422
Object.keys(result.authData).forEach((provider) => {
413423
if (result.authData[provider] === null) {

src/cli/definitions/parse-server.js

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ export default {
160160
help: "Max file size for uploads.",
161161
default: "20mb"
162162
},
163+
"userSensitiveFields": {
164+
help: "Personally identifiable information fields in the user table the should be removed for non-authorized users.",
165+
default: "email"
166+
},
163167
"sessionLength": {
164168
env: "PARSE_SERVER_SESSION_LENGTH",
165169
help: "Session duration, defaults to 1 year",

src/defaults.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ export default {
3131
sessionLength: 31536000,
3232
expireInactiveSessions: true,
3333
revokeSessionOnPasswordReset: true,
34-
schemaCacheTTL: 5000 // in ms
34+
schemaCacheTTL: 5000, // in ms
35+
userSensitiveFields: ['email']
3536
}

0 commit comments

Comments
 (0)