Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY SOLUTION] Fix unmapped field timeline #99130

Merged
merged 5 commits into from
May 4, 2021
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 @@ -35,7 +35,7 @@ export interface TimelineEventsAllStrategyResponse extends IEsSearchResponse {
}

export interface TimelineEventsAllRequestOptions extends TimelineRequestOptionsPaginated {
fields: string[];
fields: string[] | Array<{ field: string; include_unmapped: boolean }>;
fieldRequested: string[];
language: 'eql' | 'kuery' | 'lucene';
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ describe('getColumns', () => {
checkboxColumn = getColumns(defaultProps)[0] as Column;
});

test('should be disabled when the field does not exist', () => {
test('should be enabled when the field does not exist', () => {
const testField = 'nonExistingField';
const wrapper = mount(
<TestProviders>{checkboxColumn.render(testField, testData)}</TestProviders>
) as ReactWrapper;
expect(
wrapper.find(`[data-test-subj="toggle-field-${testField}"]`).first().prop('disabled')
).toBe(true);
).toBe(false);
});

test('should be enabled when the field does exist', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export const getColumns = ({
width: '30px',
render: (field: string, data: EventFieldsData) => {
const label = data.isObjectArray ? i18n.NESTED_COLUMN(field) : i18n.VIEW_COLUMN(field);
const fieldFromBrowserField = getFieldFromBrowserField(
[data.category, 'fields', field],
browserFields
);
return (
<EuiToolTip content={label}>
<EuiCheckbox
Expand All @@ -110,9 +106,7 @@ export const getColumns = ({
initialWidth: DEFAULT_COLUMN_MIN_WIDTH,
})
}
disabled={
(data.isObjectArray && data.type !== 'geo_point') || fieldFromBrowserField == null
}
disabled={data.isObjectArray && data.type !== 'geo_point'}
/>
</EuiToolTip>
);
Expand Down Expand Up @@ -192,40 +186,56 @@ export const getColumns = ({
name: i18n.VALUE,
sortable: true,
truncateText: false,
render: (values: string[] | null | undefined, data: EventFieldsData) => (
<FullWidthFlexGroup
direction="column"
alignItems="flexStart"
component="span"
gutterSize="none"
>
{values != null &&
values.map((value, i) => (
<FullWidthFlexItem
grow={false}
component="span"
key={`event-details-value-flex-item-${contextId}-${eventId}-${data.field}-${i}-${value}`}
>
<div data-colindex={3} onFocus={onFocusReFocusDraggable} role="button" tabIndex={0}>
{data.field === MESSAGE_FIELD_NAME ? (
<OverflowField value={value} />
) : (
<FormattedFieldValue
contextId={`event-details-value-formatted-field-value-${contextId}-${eventId}-${data.field}-${i}-${value}`}
eventId={eventId}
fieldFormat={data.format}
fieldName={data.field}
fieldType={data.type}
isObjectArray={data.isObjectArray}
value={value}
linkValue={getLinkValue(data.field)}
/>
)}
</div>
</FullWidthFlexItem>
))}
</FullWidthFlexGroup>
),
render: (values: string[] | null | undefined, data: EventFieldsData) => {
const fieldFromBrowserField = getFieldFromBrowserField(
[data.category, 'fields', data.field],
browserFields
);
return (
<FullWidthFlexGroup
direction="column"
alignItems="flexStart"
component="span"
gutterSize="none"
>
{values != null &&
values.map((value, i) => {
if (fieldFromBrowserField == null) {
andrew-goldstein marked this conversation as resolved.
Show resolved Hide resolved
return <EuiText size="s">{value}</EuiText>;
}
return (
<FullWidthFlexItem
grow={false}
component="span"
key={`event-details-value-flex-item-${contextId}-${eventId}-${data.field}-${i}-${value}`}
>
<div
data-colindex={3}
onFocus={onFocusReFocusDraggable}
role="button"
tabIndex={0}
>
{data.field === MESSAGE_FIELD_NAME ? (
<OverflowField value={value} />
) : (
<FormattedFieldValue
contextId={`event-details-value-formatted-field-value-${contextId}-${eventId}-${data.field}-${i}-${value}`}
eventId={eventId}
fieldFormat={data.format}
fieldName={data.field}
fieldType={data.type}
isObjectArray={data.isObjectArray}
value={value}
linkValue={getLinkValue(data.field)}
/>
)}
</div>
</FullWidthFlexItem>
);
})}
</FullWidthFlexGroup>
);
},
},
{
field: 'valuesConcatenated',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import { INDICATOR_MATCH_SUBFIELDS } from '../../../../../../../common/cti/const
import { Ecs } from '../../../../../../../common/ecs';
import { ThreatIndicatorEcs } from '../../../../../../../common/ecs/threat';

const getIndicatorEcs = (data: Ecs): ThreatIndicatorEcs[] =>
get(data, INDICATOR_DESTINATION_PATH) ?? [];
const getIndicatorEcs = (data: Ecs): ThreatIndicatorEcs[] => {
const threatData = get(data, INDICATOR_DESTINATION_PATH);
if (threatData == null) {
return [];
} else if (!Array.isArray(threatData)) {
return [threatData];
}
return threatData;
};

export const hasThreatMatchValue = (data: Ecs): boolean =>
getIndicatorEcs(data).some((indicator) =>
Expand Down
Loading