Skip to content

Commit

Permalink
[Security solution] Fix IP/geo location in Top N Flow Table (#149369)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Jan 24, 2023
1 parent 02d99a9 commit bd940e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const mockSearchStrategyResponse: IEsSearchResponse<unknown> = {
_id: 'dd4fa2d4bd-1526378075029582',
_score: 0,
fields: {
'@timestamp': ['2022-07-18T15:08:48.064Z'],
'source.geo.continent_name': ['North America'],
'source.geo.region_iso_code': ['US-VA'],
'source.geo.country_iso_code': ['US'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import type {
NetworkTopNFlowEdges,
NetworkTopNFlowRequestOptions,
AutonomousSystemItem,
} from '../../../../../../common/search_strategy';
import {
NetworkTopTablesFields,
FlowTargetSourceDest,
} from '../../../../../../common/search_strategy';
import { NetworkTopTablesFields } from '../../../../../../common/search_strategy';
import { getOppositeField } from '../helpers';
import {
formatResponseObjectValues,
Expand All @@ -48,7 +46,7 @@ const formatTopNFlowEdges = (
[flowTarget]: {
domain: bucket.domain.buckets.map((bucketDomain) => bucketDomain.key),
ip: bucket.key,
location: getGeoItem(bucket),
location: getGeoItem(bucket, flowTarget),
autonomous_system: getAsItem(bucket),
flows: getOr(0, 'flows.value', bucket),
[`${getOppositeField(flowTarget)}_ips`]: getOr(
Expand All @@ -68,24 +66,22 @@ const formatTopNFlowEdges = (
},
}));

const getFlowTargetFromString = (flowAsString: string) =>
flowAsString === 'source' ? FlowTargetSourceDest.source : FlowTargetSourceDest.destination;

const getGeoItem = (result: NetworkTopNFlowBuckets): GeoItem | null =>
const getGeoItem = (
result: NetworkTopNFlowBuckets,
flowTarget: FlowTargetSourceDest
): GeoItem | null =>
result.location.top_geo.hits.hits.length > 0 && result.location.top_geo.hits.hits[0].fields
? {
geo: formatResponseObjectValues(
getOr(
'',
`${Object.keys(result.location.top_geo.hits.hits[0].fields)[0].split('.geo')[0]}.geo`,
`${flowTarget}.geo`,
unflattenObject(
transformLocationFields(getOr({}, `location.top_geo.hits.hits[0].fields`, result))
)
)
),
flowTarget: getFlowTargetFromString(
Object.keys(result.location.top_geo.hits.hits[0].fields)[0].split('.geo')[0]
),
flowTarget,
}
: null;

Expand Down

0 comments on commit bd940e8

Please sign in to comment.