diff --git a/projects/js-packages/components/components/threats-modal/threat-fix-confirmation.tsx b/projects/js-packages/components/components/threats-modal/threat-fix-confirmation.tsx index 1d2dc0ff7287c..dc17b211f0a45 100644 --- a/projects/js-packages/components/components/threats-modal/threat-fix-confirmation.tsx +++ b/projects/js-packages/components/components/threats-modal/threat-fix-confirmation.tsx @@ -1,4 +1,4 @@ -import { getThreatType, type Threat, THREAT_ICONS } from '@automattic/jetpack-scan'; +import { getLabel, getThreatType, type Threat, THREAT_ICONS } from '@automattic/jetpack-scan'; import { __ } from '@wordpress/i18n'; import { Icon } from '@wordpress/icons'; import { useContext, useState, useCallback, useMemo } from 'react'; @@ -56,7 +56,7 @@ const ThreatFixConfirmation = () => { ) }
- { threat.title } + { getLabel( threat ) }
@@ -74,7 +74,7 @@ const ThreatFixConfirmation = () => {
- { threat.title } + { getLabel( threat ) } { !! threat.severity && }
diff --git a/projects/js-packages/scan/src/types/threats.ts b/projects/js-packages/scan/src/types/threats.ts index 22f6b06477163..9eb732e80a98c 100644 --- a/projects/js-packages/scan/src/types/threats.ts +++ b/projects/js-packages/scan/src/types/threats.ts @@ -75,4 +75,7 @@ export type Threat = { /** The affected extension. */ extension?: Extension; + + /** The affected version */ + version?: string; }; diff --git a/projects/js-packages/scan/src/utils/index.ts b/projects/js-packages/scan/src/utils/index.ts index 30a96cbd132d5..1704481053581 100644 --- a/projects/js-packages/scan/src/utils/index.ts +++ b/projects/js-packages/scan/src/utils/index.ts @@ -156,7 +156,7 @@ export const getFixerDescription = ( threat: Threat ) => { if ( threat.fixedIn && threat.extension?.name ) { return sprintf( /* translators: Translates to Updates to version. %1$s: Name. %2$s: Fixed version */ - __( 'Update %1$s to version %2$s', 'jetpack-scan' ), + __( 'Update %1$s to version %2$s.', 'jetpack-scan' ), threat.extension.name, threat.fixedIn ); @@ -187,3 +187,20 @@ export const getFixerDescription = ( threat: Threat ) => { return __( 'Jetpack will auto-fix the threat.', 'jetpack-scan' ); } }; + +export const getLabel = ( threat: Threat ) => { + if ( threat.signature === 'Vulnerable.WP.Core' ) { + // Core threat i.e. "WordPress (5.8)" + return `WordPress (${ threat.version })`; + } + + if ( threat.extension?.name && threat.extension?.version ) { + // Extension threat i.e. "Woocommerce (3.0.0)" + return `${ threat.extension.name } (${ threat.extension.version })`; + } + + if ( threat.filename ) { + // File threat i.e. "index.php" + return threat.filename.split( '/' ).pop(); + } +};