Skip to content

Commit

Permalink
[backend] do not send restricted entities with distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
labo-flg committed Mar 26, 2024
1 parent 55ff687 commit 9a79388
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,19 @@ export const stixLoadByFilters = async (context, user, types, args) => {
// region Graphics
const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => {
const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution));
const resolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true });
return data // Depending of user access, info can be empty, must be filtered
.filter((n) => isNotEmptyField(resolveLabels[n.label.toLowerCase()]))
.map((n) => R.assoc('entity', resolveLabels[n.label.toLowerCase()], n));
// resolve all of them, limited to ids for comparison in next step
const allResolveLabels = await elFindByIds(context, SYSTEM_USER, data.map((d) => d.label), { toMap: true });
const grantedResolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true });
// entities not granted shall be sent as "restricted" with limited information
return data
.filter((n) => isNotEmptyField(allResolveLabels[n.label.toLowerCase()]))
.map((n) => {
if (grantedResolveLabels[n.label.toLowerCase()]) {
return R.assoc('entity', grantedResolveLabels[n.label.toLowerCase()], n);
}
// return R.assoc('entity', { id: n.label, entity_type: n.entity_type, name: 'Restricted' }, n);
return n; // no entity details
});
};
export const timeSeriesHistory = async (context, user, types, args) => {
const { startDate, endDate, interval } = args;
Expand Down

0 comments on commit 9a79388

Please sign in to comment.