-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 IP/geo location in Top N Flow Table #149369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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( | ||
|
@@ -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`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was very silly. If for some reason a non-geo field is in there (ahem, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, it looks ten times better 🤩 |
||
`${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; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bug surfaced because some returned geo data included the timestamp. Adding this field here would break tests in
main
and proves the fix