Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { EngineStatus } from './saved_objects';
import type { EntityStoreStatus } from './types';

export const ECS_MAPPINGS_COMPONENT_TEMPLATE = 'ecs@mappings';
export const HASH_ALG = 'sha256' as const;

export const ENTITY_STORE_SOURCE_INDICES_PRIVILEGES = ['read', 'view_index_metadata'];
export const ENTITY_STORE_TARGET_INDICES_PRIVILEGES = ['read', 'manage'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { createHash } from 'crypto';
import { isNotEmptyCondition } from '../../../common/domain/definitions/common_fields';
import type { Entity } from '../../../common/domain/definitions/entity.gen';
import {
Expand All @@ -13,6 +14,7 @@ import {
type ManagedEntityDefinition,
} from '../../../common/domain/definitions/entity_schema';
import { getEntityDefinition } from '../../../common/domain/definitions/registry';
import { HASH_ALG } from '../constants';
import { BadCRUDRequestError } from '../errors';
import { hashEuid, validateAndTransformDoc, validateDocIdentification } from './utils';

Expand Down Expand Up @@ -53,11 +55,12 @@ describe('crud_client utils', () => {
});

describe('hashEuid', () => {
it('returns a valid MD5 hash', () => {
it('returns a valid SHA-256 hash', () => {
const hashedId = hashEuid('entity-id');
const expectedHash = createHash(HASH_ALG).update('entity-id').digest('hex');

expect(hashedId).toMatch(/^[a-f0-9]{32}$/);
expect(hashedId).toBe('169fbe0cb705d8d8811b5098d0cf4588');
expect(hashedId).toMatch(/^[a-f0-9]{64}$/);
expect(hashedId).toBe(expectedHash);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ import type {
EntityField,
ManagedEntityDefinition,
} from '../../../common/domain/definitions/entity_schema';
import { HASH_ALG } from '../constants';
import { BadCRUDRequestError } from '../errors';

type CrudOperation = 'create' | 'update';
const GENERIC_TYPE = 'generic' as EntityType;

export function hashEuid(id: string): string {
// EUID generation uses MD5. It is not a security-related feature.
// eslint-disable-next-line @kbn/eslint/no_unsafe_hash
return createHash('md5').update(id).digest('hex');
return createHash(HASH_ALG).update(id).digest('hex');
}

// validateDocIdentification checks provided and generated EUIDs. It
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type EntityType,
} from '../../../common/domain/definitions/entity_schema';
import { getEuidEsqlEvaluation } from '../../../common/domain/euid/esql';
import { HASH_ALG } from '../constants';
import {
buildExtractionSourceClause,
buildFieldEvaluations,
Expand All @@ -38,7 +39,6 @@ import {
} from './query_builder_commons';

export const HASHED_ID_FIELD = 'entity.hashedId';
const HASH_ALG = 'MD5';

export const MAIN_EXTRACTION_PAGINATION_FIELDS: PaginationFields = {
timestampField: ENGINE_METADATA_PAGINATION_FIRST_SEEN_LOG_FIELD,
Expand Down
Loading
Loading