Skip to content

Commit dde5551

Browse files
[backend] Improve redaction of user information in demo mode
1 parent e25c747 commit dde5551

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

opencti-platform/opencti-graphql/src/database/entity-representative.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import moment from 'moment';
2-
import { isEmptyField, isNotEmptyField } from './utils';
2+
import { isEmptyField, isNotEmptyField, REDACTED_INFORMATION } from './utils';
33
import { isStixRelationship } from '../schema/stixRelationship';
4-
import { ENTITY_TYPE_CAPABILITY, ENTITY_TYPE_STATUS } from '../schema/internalObject';
4+
import { ENTITY_TYPE_CAPABILITY, ENTITY_TYPE_STATUS, ENTITY_TYPE_USER } from '../schema/internalObject';
55
import { isStixCyberObservable } from '../schema/stixCyberObservable';
66
import { observableValue } from '../utils/format';
7+
import { ENABLED_DEMO_MODE } from '../config/conf';
78

89
export const extractRepresentativeDescription = (entityData) => {
910
let secondValue;
@@ -40,7 +41,9 @@ const extractRelationshipRepresentative = (relationshipData) => {
4041
// TODO migrate to extractStixRepresentative from convertStoreToStix
4142
export const extractEntityRepresentativeName = (entityData) => {
4243
let mainValue;
43-
if (isStixCyberObservable(entityData.entity_type)) {
44+
if (entityData.entity_type === ENTITY_TYPE_USER) {
45+
mainValue = ENABLED_DEMO_MODE ? REDACTED_INFORMATION : entityData.name;
46+
} else if (isStixCyberObservable(entityData.entity_type)) {
4447
mainValue = observableValue(entityData);
4548
} else if (entityData.entity_type === ENTITY_TYPE_STATUS && entityData.name && entityData.type) {
4649
mainValue = `${entityData.type} - ${entityData.name}`;

opencti-platform/opencti-graphql/src/database/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const RABBIT_QUEUE_PREFIX = rabbitmqPrefix ? `${rabbitmqPrefix}_` : '';
2222

2323
export const MAX_EVENT_LOOP_PROCESSING_TIME = 50;
2424

25+
export const REDACTED_INFORMATION = '*** Redacted ***';
26+
2527
export const EVENT_TYPE_CREATE = 'create';
2628
export const EVENT_TYPE_DELETE = 'delete';
2729
export const EVENT_TYPE_DEPENDENCIES = 'init-dependencies';

opencti-platform/opencti-graphql/src/domain/user.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const buildCreatorUser = (user) => {
218218
return {
219219
id: user.id,
220220
entity_type: user.entity_type,
221-
name: user.name,
221+
name: ENABLED_DEMO_MODE ? REDACTED_USER.name : user.name,
222222
description: user.description,
223223
standard_id: user.id
224224
};

opencti-platform/opencti-graphql/src/resolvers/stix.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { batchCreators } from '../domain/user';
55
import { batchInternalRels } from '../domain/stixCoreObject';
66
import { schemaRelationsRefDefinition } from '../schema/schema-relationsRef';
77
import { INPUT_GRANTED_REFS } from '../schema/general';
8-
import { isUserHasCapability, KNOWLEDGE_ORGANIZATION_RESTRICT } from '../utils/access';
8+
import { isUserHasCapability, KNOWLEDGE_ORGANIZATION_RESTRICT, REDACTED_USER } from '../utils/access';
9+
import { ENABLED_DEMO_MODE } from '../config/conf';
10+
import { ENTITY_TYPE_USER } from '../schema/internalObject';
911

1012
const creatorsLoader = batchLoader(batchCreators);
1113
const relBatchLoader = batchLoader(batchInternalRels);
12-
export const loadThroughDenormalized = (context, user, element, inputName, args = {}) => {
14+
const internalLoadThroughDenormalized = (context, user, element, inputName, args = {}) => {
1315
if (inputName === INPUT_GRANTED_REFS) {
1416
if (!isUserHasCapability(user, KNOWLEDGE_ORGANIZATION_RESTRICT)) {
1517
return []; // Granted_refs visibility is only for manager
@@ -28,6 +30,22 @@ export const loadThroughDenormalized = (context, user, element, inputName, args
2830
return relBatchLoader.load({ element, definition: ref }, context, user, args);
2931
};
3032

33+
export const loadThroughDenormalized = async (context, user, element, inputName, args = {}) => {
34+
const data = await internalLoadThroughDenormalized(context, user, element, inputName, args);
35+
if (ENABLED_DEMO_MODE) {
36+
if (Array.isArray(data)) {
37+
return data.map((d) => {
38+
if (d.entity_type === ENTITY_TYPE_USER) {
39+
return { ...d, name: REDACTED_USER.name, user_email: REDACTED_USER.user_email };
40+
}
41+
return d;
42+
});
43+
}
44+
return data ? { ...data, name: REDACTED_USER.name, user_email: REDACTED_USER.user_email } : data;
45+
}
46+
return data;
47+
};
48+
3149
const stixResolvers = {
3250
Query: {
3351
stix: async (_, { id }, context) => stixLoadByIdStringify(context, context.user, id),

opencti-platform/opencti-graphql/src/utils/access.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { BasicStoreSettings } from '../types/settings';
1818
import { ACCOUNT_STATUS_ACTIVE } from '../config/conf';
1919
import { schemaAttributesDefinition } from '../schema/schema-attributes';
2020
import { FunctionalError } from '../config/errors';
21-
import { isNotEmptyField } from '../database/utils';
21+
import { isNotEmptyField, REDACTED_INFORMATION } from '../database/utils';
2222
import { isStixObject } from '../schema/stixCoreObject';
2323

2424
export const DEFAULT_INVALID_CONF_VALUE = 'ChangeMe';
@@ -288,8 +288,8 @@ export const REDACTED_USER: AuthUser = {
288288
id: REDACTED_USER_UUID,
289289
internal_id: REDACTED_USER_UUID,
290290
individual_id: undefined,
291-
name: '*** Redacted ***',
292-
user_email: '*** Redacted ***',
291+
name: REDACTED_INFORMATION,
292+
user_email: REDACTED_INFORMATION,
293293
inside_platform_organization: false,
294294
origin: { user_id: REDACTED_USER_UUID, socket: 'internal' },
295295
roles: [],

0 commit comments

Comments
 (0)