Skip to content

Commit

Permalink
[Security Solution][Endpoint] Fix error while checking `agent.version…
Browse files Browse the repository at this point in the history
…` compatibility for host Isolation that causes Security Solution app to crash (#131272)

* Only parse version for Endpoint Alerts
* isVersionSupported(): catch exceptions, log it and return false if version checking fails
  • Loading branch information
paul-tavares authored Apr 29, 2022
1 parent b66ffe5 commit 578364c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { isVersionSupported, isOsSupported, isIsolationSupported } from './utils';

describe('Host Isolation utils isVersionSupported', () => {
// NOTE: the `7.15.0.8295.0` and the text current versions are invalid.
test.each`
currentVersion | minVersionRequired | expected
${'8.14.0'} | ${'7.13.0'} | ${true}
Expand All @@ -22,6 +23,8 @@ describe('Host Isolation utils isVersionSupported', () => {
${'7.14.0-alpha'} | ${'7.14.0'} | ${true}
${'8.0.0-SNAPSHOT'} | ${'7.14.0'} | ${true}
${'8.0.0'} | ${'7.14.0'} | ${true}
${'7.15.0.8295.0'} | ${'7.14.0'} | ${false}
${'NOT_SEMVER'} | ${'7.14.0'} | ${false}
`(
'should validate that version $a is compatible($expected) to $b',
({ currentVersion, minVersionRequired, expected }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ export const isVersionSupported = ({
currentVersion: string;
minVersionRequired?: string;
}) => {
const parsedCurrentVersion = parseSemver(currentVersion);
return semverLte(minVersionRequired, parsedCurrentVersion);
// `parseSemver()` will throw if the version provided is not a valid semver value.
// If that happens, then just return false from this function
try {
const parsedCurrentVersion = parseSemver(currentVersion);
return semverLte(minVersionRequired, parsedCurrentVersion);
} catch (e) {
// If running in the browser, log to console
if (window && window.console) {
window.console.warn(
`SecuritySolution: isVersionSupported(): Unable to determine if current version [${currentVersion}] meets minimum version [${minVersionRequired}]. Error: ${e.message}`
);
}
return false;
}
};

export const isOsSupported = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ export const useHostIsolationAction = ({
agentId,
});

const isolationSupported = isIsolationSupported({
osName: hostOsFamily,
version: agentVersion,
capabilities,
});
const isolationSupported = useMemo(() => {
return isEndpointAlert
? isIsolationSupported({
osName: hostOsFamily,
version: agentVersion,
capabilities,
})
: false;
}, [agentVersion, capabilities, hostOsFamily, isEndpointAlert]);

const isIsolationAllowed = useUserPrivileges().endpointPrivileges.canIsolateHost;

Expand Down

0 comments on commit 578364c

Please sign in to comment.