updated plugin Jetpack Protect version 4.0.0
This commit is contained in:
@ -36,6 +36,8 @@ class Extension_Model {
|
||||
/**
|
||||
* A collection of threats related to this version of the extension.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Use Threat_Model::$extension instead.
|
||||
*
|
||||
* @var array<Threat_Model>
|
||||
*/
|
||||
public $threats = array();
|
||||
@ -81,10 +83,13 @@ class Extension_Model {
|
||||
/**
|
||||
* Set Threats
|
||||
*
|
||||
* @deprecated 0.4.0 This method is deprecated. Use Threat_Model::$extension instead.
|
||||
*
|
||||
* @param array<Threat_Model|array|object> $threats An array of threat data to add to the extension.
|
||||
*/
|
||||
public function set_threats( $threats ) {
|
||||
if ( ! is_array( $threats ) ) {
|
||||
// @phan-suppress-next-line PhanDeprecatedProperty -- Maintaining backwards compatibility.
|
||||
$this->threats = array();
|
||||
return;
|
||||
}
|
||||
@ -105,6 +110,7 @@ class Extension_Model {
|
||||
$threats
|
||||
);
|
||||
|
||||
// @phan-suppress-next-line PhanDeprecatedProperty -- Maintaining backwards compatibility.
|
||||
$this->threats = $threats;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,67 +19,13 @@ class History_Model {
|
||||
public $last_checked;
|
||||
|
||||
/**
|
||||
* The number of threats.
|
||||
* Threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_threats;
|
||||
|
||||
/**
|
||||
* The number of core threats.
|
||||
* @since 0.4.0
|
||||
*
|
||||
* @var int
|
||||
* @var array<Threat_Model>
|
||||
*/
|
||||
public $num_core_threats;
|
||||
|
||||
/**
|
||||
* The number of plugin threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_plugins_threats;
|
||||
|
||||
/**
|
||||
* The number of theme threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_themes_threats;
|
||||
|
||||
/**
|
||||
* WordPress core.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $core = array();
|
||||
|
||||
/**
|
||||
* Status themes.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $themes = array();
|
||||
|
||||
/**
|
||||
* Status plugins.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $plugins = array();
|
||||
|
||||
/**
|
||||
* File threats.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $files = array();
|
||||
|
||||
/**
|
||||
* Database threats.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $database = array();
|
||||
public $threats = array();
|
||||
|
||||
/**
|
||||
* Whether there was an error loading the history.
|
||||
@ -102,6 +48,87 @@ class History_Model {
|
||||
*/
|
||||
public $error_message;
|
||||
|
||||
/**
|
||||
* The number of threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Count History_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_threats;
|
||||
|
||||
/**
|
||||
* The number of core threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and count History_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_core_threats;
|
||||
|
||||
/**
|
||||
* The number of plugin threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and count History_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_plugins_threats;
|
||||
|
||||
/**
|
||||
* The number of theme threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and count History_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_themes_threats;
|
||||
|
||||
/**
|
||||
* WordPress core.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Use History_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $core = array();
|
||||
|
||||
/**
|
||||
* Status themes.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use History_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $themes = array();
|
||||
|
||||
/**
|
||||
* Status plugins.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use History_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $plugins = array();
|
||||
|
||||
/**
|
||||
* File threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use History_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $files = array();
|
||||
|
||||
/**
|
||||
* Database threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use History_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $database = array();
|
||||
|
||||
/**
|
||||
* Status constructor.
|
||||
*
|
||||
|
||||
@ -12,5 +12,5 @@ namespace Automattic\Jetpack;
|
||||
*/
|
||||
class Protect_Models {
|
||||
|
||||
const PACKAGE_VERSION = '0.2.1';
|
||||
const PACKAGE_VERSION = '0.5.4';
|
||||
}
|
||||
|
||||
@ -25,27 +25,6 @@ class Status_Model {
|
||||
*/
|
||||
public $last_checked;
|
||||
|
||||
/**
|
||||
* The number of threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_threats;
|
||||
|
||||
/**
|
||||
* The number of plugin threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_plugins_threats;
|
||||
|
||||
/**
|
||||
* The number of theme threats.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_themes_threats;
|
||||
|
||||
/**
|
||||
* The current report status.
|
||||
*
|
||||
@ -54,39 +33,20 @@ class Status_Model {
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* WordPress core status.
|
||||
* The current reported security threats.
|
||||
*
|
||||
* @var object
|
||||
* @since 0.4.0
|
||||
*
|
||||
* @var array<Threat_Model>
|
||||
*/
|
||||
public $core;
|
||||
public $threats = array();
|
||||
|
||||
/**
|
||||
* Status themes.
|
||||
* List of fixable threat IDs.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
* @var string[]
|
||||
*/
|
||||
public $themes = array();
|
||||
|
||||
/**
|
||||
* Status plugins.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $plugins = array();
|
||||
|
||||
/**
|
||||
* File threats.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $files = array();
|
||||
|
||||
/**
|
||||
* Database threats.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $database = array();
|
||||
public $fixable_threat_ids = array();
|
||||
|
||||
/**
|
||||
* Whether the site includes items that have not been checked.
|
||||
@ -123,6 +83,78 @@ class Status_Model {
|
||||
*/
|
||||
public $error_message;
|
||||
|
||||
/**
|
||||
* The number of threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Count Status_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_threats;
|
||||
|
||||
/**
|
||||
* The number of plugin threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and count Status_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_plugins_threats;
|
||||
|
||||
/**
|
||||
* The number of theme threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and count Status_Model::$threats instead.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_themes_threats;
|
||||
|
||||
/**
|
||||
* WordPress core status.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use Status_Model::$threats instead.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $core;
|
||||
|
||||
/**
|
||||
* Status themes.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use Status_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $themes = array();
|
||||
|
||||
/**
|
||||
* Status plugins.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use Status_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $plugins = array();
|
||||
|
||||
/**
|
||||
* File threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use Status_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $files = array();
|
||||
|
||||
/**
|
||||
* Database threats.
|
||||
*
|
||||
* @deprecated 0.4.0 This property is deprecated. Filter and use Status_Model::$threats instead.
|
||||
*
|
||||
* @var array<Extension_Model>
|
||||
*/
|
||||
public $database = array();
|
||||
|
||||
/**
|
||||
* Status constructor.
|
||||
*
|
||||
@ -130,6 +162,7 @@ class Status_Model {
|
||||
*/
|
||||
public function __construct( $status = array() ) {
|
||||
// set status defaults
|
||||
// @phan-suppress-next-line PhanDeprecatedProperty -- Maintaining backwards compatibility.
|
||||
$this->core = new \stdClass();
|
||||
|
||||
foreach ( $status as $property => $value ) {
|
||||
|
||||
@ -96,6 +96,13 @@ class Threat_Model {
|
||||
*/
|
||||
public $context;
|
||||
|
||||
/**
|
||||
* The database table of the threat.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $table;
|
||||
|
||||
/**
|
||||
* The source URL of the threat.
|
||||
*
|
||||
@ -103,6 +110,24 @@ class Threat_Model {
|
||||
*/
|
||||
public $source;
|
||||
|
||||
/**
|
||||
* The threat's extension information.
|
||||
*
|
||||
* @since 0.4.0
|
||||
*
|
||||
* @var null|Extension_Model
|
||||
*/
|
||||
public $extension;
|
||||
|
||||
/**
|
||||
* The threat's related vulnerabilities.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @var null|Vulnerability_Model[]
|
||||
*/
|
||||
public $vulnerabilities;
|
||||
|
||||
/**
|
||||
* Threat Constructor
|
||||
*
|
||||
@ -114,9 +139,127 @@ class Threat_Model {
|
||||
}
|
||||
|
||||
foreach ( $threat as $property => $value ) {
|
||||
if ( 'extension' === $property && ! empty( $value ) ) {
|
||||
$this->extension = new Extension_Model( $value );
|
||||
continue;
|
||||
}
|
||||
if ( property_exists( $this, $property ) ) {
|
||||
$this->$property = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID value of the threat based on its related extension and vulnerabilities.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @param Extension_Model $extension The extension to get the ID from.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_id_from_vulnerable_extension( Extension_Model $extension ) {
|
||||
return "$extension->type-$extension->slug-$extension->version";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title from a vulnerable extension.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @param Extension_Model $extension The extension to get the title from.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private static function get_title_from_vulnerable_extension( Extension_Model $extension ) {
|
||||
$titles = array(
|
||||
'plugins' => sprintf(
|
||||
/* translators: placeholders are the theme name and version number. Example: "Vulnerable theme: Jetpack (version 1.2.3)" */
|
||||
__( 'Vulnerable plugin: %1$s (version %2$s)', 'jetpack-protect-models' ),
|
||||
$extension->name,
|
||||
$extension->version
|
||||
),
|
||||
'themes' => sprintf(
|
||||
/* translators: placeholders are the theme name and version number. Example: "Vulnerable theme: Jetpack (version 1.2.3)" */
|
||||
__( 'Vulnerable theme: %1$s (version %2$s)', 'jetpack-protect-models' ),
|
||||
$extension->name,
|
||||
$extension->version
|
||||
),
|
||||
'core' => sprintf(
|
||||
/* translators: placeholder is the version number. Example: "Vulnerable WordPress (version 1.2.3)" */
|
||||
__( 'Vulnerable WordPress (version %s)', 'jetpack-protect-models' ),
|
||||
$extension->version
|
||||
),
|
||||
);
|
||||
|
||||
return $titles[ $extension->type ] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description from a vulnerable extension.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @param Extension_Model $extension The extension to get the description from.
|
||||
* @param array $vulnerabilities The vulnerabilities to get the description from.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_description_from_vulnerable_extension( Extension_Model $extension, array $vulnerabilities ) {
|
||||
return sprintf(
|
||||
/* translators: placeholders are the theme name and version number. Example: "The installed version of Jetpack (1.2.3) has a known security vulnerability." */
|
||||
_n( 'The installed version of %1$s (%2$s) has a known security vulnerability.', 'The installed version of %1$s (%2$s) has known security vulnerabilities.', count( $vulnerabilities ), 'jetpack-protect-models' ),
|
||||
$extension->name,
|
||||
$extension->version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest fixed_in version from a list of vulnerabilities.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @param array $vulnerabilities The vulnerabilities to get the fixed_in version from.
|
||||
*
|
||||
* @return string|bool|null The latest fixed_in version, or false if any of the vulnerabilities are not fixed.
|
||||
*/
|
||||
private static function get_fixed_in_from_vulnerabilities( array $vulnerabilities ) {
|
||||
$fixed_in = null;
|
||||
|
||||
foreach ( $vulnerabilities as $vulnerability ) {
|
||||
// If any of the vulnerabilities are not fixed, the threat is not fixed.
|
||||
if ( ! $vulnerability->fixed_in ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Use the latest available fixed_in version.
|
||||
if ( ! $fixed_in || ( $fixed_in && version_compare( $vulnerability->fixed_in, $fixed_in, '>' ) ) ) {
|
||||
$fixed_in = $vulnerability->fixed_in;
|
||||
}
|
||||
}
|
||||
|
||||
return $fixed_in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a threat from extension vulnerabilities.
|
||||
*
|
||||
* @since 0.5.0
|
||||
*
|
||||
* @param Extension_Model $extension The extension to generate the threat for.
|
||||
* @param Vulnerability_Model[] $vulnerabilities The vulnerabilities to generate the threat from.
|
||||
*
|
||||
* @return Threat_Model
|
||||
*/
|
||||
public static function generate_from_extension_vulnerabilities( Extension_Model $extension, array $vulnerabilities ) {
|
||||
return new Threat_Model(
|
||||
array(
|
||||
'id' => self::get_id_from_vulnerable_extension( $extension ),
|
||||
'title' => self::get_title_from_vulnerable_extension( $extension ),
|
||||
'description' => self::get_description_from_vulnerable_extension( $extension, $vulnerabilities ),
|
||||
'fixed_in' => self::get_fixed_in_from_vulnerabilities( $vulnerabilities ),
|
||||
'vulnerabilities' => $vulnerabilities,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Model class for vulnerability data.
|
||||
*
|
||||
* @package automattic/jetpack-protect-models
|
||||
*/
|
||||
|
||||
namespace Automattic\Jetpack\Protect_Models;
|
||||
|
||||
use Automattic\Jetpack\Redirect;
|
||||
|
||||
/**
|
||||
* Model class for vulnerability data.
|
||||
*/
|
||||
class Vulnerability_Model {
|
||||
/**
|
||||
* Vulnerability ID.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* Vulnerability Title.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Vulnerability Description.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* The version the vulnerability is fixed in.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $fixed_in;
|
||||
|
||||
/**
|
||||
* The version the vulnerability was introduced.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $introduced_in;
|
||||
|
||||
/**
|
||||
* The type of vulnerability.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* The source URL for the vulnerability.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $source;
|
||||
|
||||
/**
|
||||
* Vulnerability Constructor
|
||||
*
|
||||
* @param array|object $vulnerability Vulnerability data to load into the class instance.
|
||||
*/
|
||||
public function __construct( $vulnerability ) {
|
||||
// Initialize the vulnerability data.
|
||||
foreach ( $vulnerability as $property => $value ) {
|
||||
if ( property_exists( $this, $property ) ) {
|
||||
$this->$property = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the source URL is set.
|
||||
$this->get_source();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source URL for the vulnerability.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_source() {
|
||||
if ( empty( $this->source ) && $this->id ) {
|
||||
$this->source = Redirect::get_url( 'jetpack-protect-vul-info', array( 'path' => $this->id ) );
|
||||
}
|
||||
|
||||
return $this->source;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user