-
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] Remove fields
from sourcerer response
#130917
Changes from all commits
68422c9
f707f4e
59588ca
08ec8a9
fc92e8f
b73deff
02c7160
5976e8f
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 |
---|---|---|
|
@@ -54,16 +54,8 @@ export const createSourcererDataViewRoute = ( | |
); | ||
|
||
let allDataViews: DataViewListItem[] = await dataViewService.getIdsWithTitle(); | ||
let siemDataView = null; | ||
try { | ||
siemDataView = await dataViewService.get(dataViewId); | ||
} catch (err) { | ||
const error = transformError(err); | ||
// Do nothing if statusCode === 404 because we expect that the security dataview does not exist | ||
if (error.statusCode !== 404) { | ||
throw err; | ||
} | ||
} | ||
let siemDataView: DataView | DataViewListItem | null = | ||
allDataViews.find((dv) => dv.id === dataViewId) ?? null; | ||
|
||
const { patternList } = request.body; | ||
const patternListAsTitle = patternList.sort().join(); | ||
|
@@ -90,6 +82,7 @@ export const createSourcererDataViewRoute = ( | |
} | ||
} | ||
} else if (patternListAsTitle !== siemDataViewTitle) { | ||
siemDataView = await dataViewService.get(dataViewId); | ||
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. We can get to this line only if 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. yes, unfortunately to make the 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. @stephmilovic is this still true? From the docs it says 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. @yctercero unfortunately, if we do not do the GET call we do not get the saved object methods. It's kind of silly, they should really fetch it on their end. But alas, sending only id and title to
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. Thanks for the follow-up Steph! That stinks... |
||
siemDataView.title = patternListAsTitle; | ||
await dataViewService.updateSavedObject(siemDataView); | ||
} | ||
|
@@ -160,8 +153,9 @@ export const getSourcererDataViewRoute = ( | |
request, | ||
true | ||
); | ||
|
||
const siemDataView = await dataViewService.get(dataViewId); | ||
const allDataViews: DataViewListItem[] = await dataViewService.getIdsWithTitle(); | ||
const siemDataView: DataViewListItem | null = | ||
allDataViews.find((dv) => dv.id === dataViewId) ?? null; | ||
const kibanaDataView = siemDataView | ||
? await buildSourcererDataView( | ||
siemDataView, | ||
|
@@ -186,14 +180,27 @@ export const getSourcererDataViewRoute = ( | |
); | ||
}; | ||
|
||
interface KibanaDataView { | ||
/** Uniquely identifies a Kibana Data View */ | ||
id: string; | ||
/** list of active patterns that return data */ | ||
patternList: string[]; | ||
/** | ||
* title of Kibana Data View | ||
* title also serves as "all pattern list", including inactive | ||
* comma separated string | ||
*/ | ||
title: string; | ||
} | ||
|
||
const buildSourcererDataView = async ( | ||
dataView: DataView, | ||
dataView: DataView | DataViewListItem, | ||
clientAsCurrentUser: ElasticsearchClient | ||
) => { | ||
): Promise<KibanaDataView> => { | ||
const patternList = dataView.title.split(','); | ||
const activePatternBools: boolean[] = await findExistingIndices(patternList, clientAsCurrentUser); | ||
const activePatternLists: string[] = patternList.filter( | ||
(pattern, j, self) => self.indexOf(pattern) === j && activePatternBools[j] | ||
); | ||
return { ...dataView, patternList: activePatternLists }; | ||
return { id: dataView.id ?? '', title: dataView.title, patternList: activePatternLists }; | ||
}; |
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.
adding fields to mock response to ensure they are not returned