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

Fixes redirects to specific techniques #6882

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Improvement of the filter management system by implementing new standard modules [#6534](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6534) [#6772](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6772) [#6873](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6873)
- Changed permalink field in the Events tab table in Virustotal to show an external link [#6839](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6839)
- Changed the logging system to use the provided by the platform [#6161](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6161)
- Change the internal control from Mitre > intelligence > Table to a control via url. [#6882](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6882)
- Changed the display of rule details flyout to be based on URL [#6886](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6886)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ const getVisStateAgentTopOrganizationsByAlertCount = (
addTooltip: true,
addLegend: true,
legendPosition: 'right',
isDonut: false,
isDonut: true,
labels: {
show: false,
values: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ jest.mock('react', () => ({
}));

jest.mock('../../../../react-services/navigation-service', () => ({
getInstance() {},
getInstance() {
return {
getLocation: () => {
return { search: '?tabRedirect=groups' };
},
getParams: () => {
return {
has: () => 'groups',
};
},
};
},
}));

const mockStore = configureMockStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import { EuiPanel } from '@elastic/eui';
import { MitreAttackResources } from './resources';
import { ModuleMitreAttackIntelligenceLeftPanel } from './intelligence_left_panel';
import { ModuleMitreAttackIntelligenceRightPanel } from './intelligence_right_panel';
import { useAsyncAction } from '../../../common/hooks';
import { useAsyncAction, useRouterSearch } from '../../../common/hooks';
import { WzRequest } from '../../../../react-services';
import { PanelSplit } from '../../../common/panels';
import { withUserAuthorizationPrompt } from '../../../common/hocs';
import { compose } from 'redux';
import NavigationService from '../../../../react-services/navigation-service';

export const ModuleMitreAttackIntelligence = compose(
withUserAuthorizationPrompt([{ action: 'mitre:read', resource: '*:*:*' }]),
)(() => {
const paramTabRedirect = useRouterSearch().tabRedirect;
const [selectedResource, setSelectedResource] = useState(
MitreAttackResources[0].id,
paramTabRedirect || MitreAttackResources[0].id,
);
const [searchTermAllResources, setSearchTermAllResources] = useState('');
const searchTermAllResourcesLastSearch = useRef('');
Expand All @@ -50,8 +52,8 @@ export const ModuleMitreAttackIntelligence = compose(
params: {
...(searchTerm
? {
q: fields.map(key => `${key}~${searchTerm}`).join(','),
}
q: fields.map(key => `${key}~${searchTerm}`).join(','),
}
: {}),
limit: limitResults,
},
Expand All @@ -70,13 +72,13 @@ export const ModuleMitreAttackIntelligence = compose(
setResourceFilters({
...(searchTermAllResourcesLastSearch.current
? {
q: fields
.map(
key =>
`${key}~${searchTermAllResourcesLastSearch.current}`,
)
.join(','),
}
q: fields
.map(
key =>
`${key}~${searchTermAllResourcesLastSearch.current}`,
)
.join(','),
}
: {}),
});
setSelectedResource(resource.id);
Expand All @@ -93,19 +95,23 @@ export const ModuleMitreAttackIntelligence = compose(
);

useEffect(() => {
const urlParams = new URLSearchParams(location.href);
const redirectTab = urlParams.get('tabRedirect');
if (redirectTab) {
setSelectedResource(redirectTab);
if (!paramTabRedirect) {
NavigationService.getInstance().updateAndNavigateSearchParams({
tabRedirect: selectedResource,
});
}
}, []);
setSelectedResource(paramTabRedirect);
}, [paramTabRedirect]);

const onSelectResource = useCallback(
resourceID => {
NavigationService.getInstance().updateAndNavigateSearchParams({
tabRedirect: resourceID,
});
setResourceFilters({});
setSelectedResource(prevSelectedResource =>
prevSelectedResource === resourceID &&
searchTermAllResourcesUsed.current
searchTermAllResourcesUsed.current
? null
: resourceID,
);
Expand All @@ -118,7 +124,12 @@ export const ModuleMitreAttackIntelligence = compose(
}, []);

return (
<EuiPanel paddingSize='s' hasShadow={false} hasBorder={false} color="transparent">
<EuiPanel
paddingSize='s'
hasShadow={false}
hasBorder={false}
color='transparent'
>
<PanelSplit
side={
<ModuleMitreAttackIntelligenceLeftPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UI_LOGGER_LEVELS } from '../../../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../../../react-services/common-services';
import NavigationService from '../../../../react-services/navigation-service';
import { Route, Switch } from '../../../router-search';

export const ModuleMitreAttackIntelligenceResource = ({
label,
Expand All @@ -40,12 +41,11 @@ export const ModuleMitreAttackIntelligenceResource = ({
const idToRedirect = urlParams.get('idToRedirect');
const endpoint = `/mitre/${redirectTab}?q=external_id=${idToRedirect}`;
getMitreItemToRedirect(endpoint);
NavigationService.getInstance().updateAndNavigateSearchParams({
tabRedirect: null,
idToRedirect: null,
});
}
}, []);
}, [
navigationService.getParams().has('tabRedirect'),
navigationService.getParams().has('idToRedirect'),
]);

const getMitreItemToRedirect = async endpoint => {
try {
Expand All @@ -69,10 +69,13 @@ export const ModuleMitreAttackIntelligenceResource = ({
}
};

const tableColumns = useMemo(() => tableColumnsCreator(setDetails), []);
const tableColumns = useMemo(() => tableColumnsCreator(), []);

const closeFlyout = useCallback(() => {
setDetails(null);
NavigationService.getInstance().updateAndNavigateSearchParams({
idToRedirect: null,
});
}, []);

return (
Expand All @@ -91,11 +94,18 @@ export const ModuleMitreAttackIntelligenceResource = ({
}}
/>
{details && (
<ModuleMitreAttackIntelligenceFlyout
details={details}
closeFlyout={() => closeFlyout()}
onSelectResource={setDetails}
/>
<Switch>
<Route
path='?tabRedirect=:tabRedirect&idToRedirect=:idToRedirect'
render={() => (
<ModuleMitreAttackIntelligenceFlyout
details={details}
closeFlyout={() => closeFlyout()}
onSelectResource={setDetails}
/>
)}
/>
</Switch>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const ModuleMitreAttackIntelligenceFlyout = ({
<ReferencesTable
referencesName={item.id}
referencesArray={details[item.id]}
columns={item.tableColumnsCreator(onSelectResource)}
columns={item.tableColumnsCreator()}
backToTop={() => {
startReference.current?.scrollIntoView();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { WzRequest } from '../../../../react-services';
import { Markdown } from '../../../common/util';
import { formatUIDate } from '../../../../react-services';
import React from 'react';
import { EuiLink } from '@elastic/eui';
import {
SEARCH_BAR_WQL_VALUE_SUGGESTIONS_COUNT,
UI_LOGGER_LEVELS,
} from '../../../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../../../react-services/common-services';
import { mitreAttack } from '../../../../utils/applications';
import { WzLink } from '../../../wz-link/wz-link';

const getMitreAttackIntelligenceSuggestions = async (
endpoint: string,
Expand Down Expand Up @@ -98,13 +99,18 @@ function buildResource(label: string) {
apiEndpoint: endpoint,
fieldName: 'name',
initialSortingField: 'name',
tableColumnsCreator: openResourceDetails => [
tableColumnsCreator: () => [
yenienserrano marked this conversation as resolved.
Show resolved Hide resolved
{
field: 'external_id',
name: 'ID',
width: '12%',
render: (value, item) => (
<EuiLink onClick={() => openResourceDetails(item)}>{value}</EuiLink>
render: value => (
<WzLink
appId={mitreAttack.id}
path={`/overview?tab=mitre&tabView=intelligence&tabRedirect=${id}&idToRedirect=${value}`}
>
{value}
</WzLink>
),
},
{
Expand All @@ -113,7 +119,12 @@ function buildResource(label: string) {
sortable: true,
width: '30%',
render: (value, item) => (
<EuiLink onClick={() => openResourceDetails(item)}>{value}</EuiLink>
<WzLink
appId={mitreAttack.id}
path={`/overview?tab=mitre&tabView=intelligence&tabRedirect=${id}&idToRedirect=${item.external_id}`}
>
{value}
</WzLink>
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const getVisStateOfficeTopsEventsPie = (indexPatternId: string) => {
addTooltip: true,
addLegend: true,
legendPosition: 'right',
isDonut: false,
isDonut: true,
labels: {
show: false,
values: true,
Expand Down
Loading