Skip to content

Commit 73a7773

Browse files
committed
fix: don't return email for members
stop retrieving additional fields which has been added to ES for members as they can be outdated also, returning email from ES may leak it, while email should be only returned to admins as controlled by "getObjectsWithMemberDetails" method
1 parent 34af2aa commit 73a7773

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/routes/projectMembers/get.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { middleware as tcMiddleware } from 'tc-core-library-js';
77
import models from '../../models';
88
import util from '../../util';
99

10+
const PROJECT_MEMBER_ATTRIBUTES = _.without(_.keys(models.ProjectMember.rawAttributes));
11+
1012
/**
1113
* API to get project member.
1214
*
@@ -30,7 +32,7 @@ module.exports = [
3032
(req, res, next) => {
3133
const projectId = _.parseInt(req.params.projectId);
3234
const memberRecordId = _.parseInt(req.params.id);
33-
const fields = req.query.fields ? req.query.fields.split(',') : null;
35+
const fields = req.query.fields ? req.query.fields.split(',') : [];
3436

3537
util.fetchByIdFromES('members', {
3638
query: {
@@ -74,7 +76,15 @@ module.exports = [
7476
});
7577
}
7678
req.log.debug('project member found in ES');
77-
return data[0].inner_hits.members.hits.hits[0]._source; // eslint-disable-line no-underscore-dangle
79+
return _.pick(
80+
data[0].inner_hits.members.hits.hits[0]._source, // eslint-disable-line no-underscore-dangle
81+
// Elasticsearch index might have additional fields added to members like
82+
// 'handle', 'firstName', 'lastName', 'email'
83+
// but we shouldn't return them, as they might be outdated
84+
// method "getObjectsWithMemberDetails" would populate these fields again
85+
// with up to date data from Member Service if necessary
86+
PROJECT_MEMBER_ATTRIBUTES,
87+
);
7888
}).then(member => (
7989
util.getObjectsWithMemberDetails([member], fields, req)
8090
.then(([memberWithDetails]) => memberWithDetails)

src/routes/projectMembers/list.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import models from '../../models';
99
import util from '../../util';
1010
import { PROJECT_MEMBER_ROLE } from '../../constants';
1111

12+
const PROJECT_MEMBER_ATTRIBUTES = _.without(_.keys(models.ProjectMember.rawAttributes));
13+
1214
const permissions = tcMiddleware.permissions;
1315

1416
const schema = {
@@ -31,7 +33,7 @@ module.exports = [
3133
permissions('project.viewMember'),
3234
(req, res, next) => {
3335
const projectId = _.parseInt(req.params.projectId);
34-
const fields = req.query.fields ? req.query.fields.split(',') : null;
36+
const fields = req.query.fields ? req.query.fields.split(',') : [];
3537
const must = [
3638
{ term: { 'members.projectId': projectId } },
3739
];
@@ -89,7 +91,15 @@ module.exports = [
8991
});
9092
}
9193
req.log.debug('project members found in ES');
92-
return data[0].inner_hits.members.hits.hits.map(hit => hit._source); // eslint-disable-line no-underscore-dangle
94+
return data[0].inner_hits.members.hits.hits.map(hit => _.pick(
95+
hit._source, // eslint-disable-line no-underscore-dangle
96+
// Elasticsearch index might have additional fields added to members like
97+
// 'handle', 'firstName', 'lastName', 'email'
98+
// but we shouldn't return them, as they might be outdated
99+
// method "getObjectsWithMemberDetails" would populate these fields again
100+
// with up to date data from Member Service if necessary
101+
PROJECT_MEMBER_ATTRIBUTES,
102+
));
93103
})
94104
.then(members => (
95105
util.getObjectsWithMemberDetails(members, fields, req)

0 commit comments

Comments
 (0)