Issues (942)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugin-updates/class-wc-updates-screen-updates.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Manages WooCommerce plugin updating on the Updates screen.
4
 *
5
 * @package     WooCommerce/Admin
6
 * @version     3.2.0
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
14
	include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php';
15
}
16
17
/**
18
 * Class WC_Updates_Screen_Updates
19
 */
20
class WC_Updates_Screen_Updates extends WC_Plugin_Updates {
21
22
	/**
23
	 * Constructor.
24
	 */
25
	public function __construct() {
26
		add_action( 'admin_print_footer_scripts', array( $this, 'update_screen_modal' ) );
27
	}
28
29
	/**
30
	 * Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins.
31
	 */
32
	public function update_screen_modal() {
33
		$updateable_plugins = get_plugin_updates();
34
		if ( empty( $updateable_plugins['woocommerce/woocommerce.php'] )
35
			|| empty( $updateable_plugins['woocommerce/woocommerce.php']->update )
36
			|| empty( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ) ) {
37
			return;
38
		}
39
40
		$this->new_version            = wc_clean( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version );
0 ignored issues
show
Documentation Bug introduced by
It seems like wc_clean($updateable_plu...]->update->new_version) can also be of type array. However, the property $new_version is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
41
		$this->major_untested_plugins = $this->get_untested_plugins( $this->new_version, 'major' );
0 ignored issues
show
It seems like $this->new_version can also be of type array; however, WC_Plugin_Updates::get_untested_plugins() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
42
43
		if ( ! empty( $this->major_untested_plugins ) ) {
44
			echo $this->get_extensions_modal_warning(); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
45
			$this->update_screen_modal_js();
0 ignored issues
show
The call to the method WC_Updates_Screen_Update...pdate_screen_modal_js() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
46
		}
47
	}
48
49
	/**
50
	 * JS for the modal window on the updates screen.
51
	 */
52
	protected function update_screen_modal_js() {
53
		?>
54
		<script>
55
			( function( $ ) {
56
				var modal_dismissed = false;
57
58
				// Show the modal if the WC upgrade checkbox is checked.
59
				var show_modal_if_checked = function() {
60
					if ( modal_dismissed ) {
61
						return;
62
					}
63
					var $checkbox = $( 'input[value="woocommerce/woocommerce.php"]' );
64
					if ( $checkbox.prop( 'checked' ) ) {
65
						$( '#wc-upgrade-warning' ).click();
66
					}
67
				}
68
69
				$( '#plugins-select-all, input[value="woocommerce/woocommerce.php"]' ).on( 'change', function() {
70
					show_modal_if_checked();
71
				} );
72
73
				// Add a hidden thickbox link to use for bringing up the modal.
74
				$('body').append( '<a href="#TB_inline?height=600&width=550&inlineId=wc_untested_extensions_modal" class="wc-thickbox" id="wc-upgrade-warning" style="display:none"></a>' );
75
76
				// Don't show the modal again once it's been accepted.
77
				$( '#wc_untested_extensions_modal .accept' ).on( 'click', function( evt ) {
78
					evt.preventDefault();
79
					modal_dismissed = true;
80
					tb_remove();
81
				});
82
83
				// Uncheck the WC update checkbox if the modal is canceled.
84
				$( '#wc_untested_extensions_modal .cancel' ).on( 'click', function( evt ) {
85
					evt.preventDefault();
86
					$( 'input[value="woocommerce/woocommerce.php"]' ).prop( 'checked', false );
87
					tb_remove();
88
				});
89
			})( jQuery );
90
		</script>
91
		<?php
92
		$this->generic_modal_js();
0 ignored issues
show
The call to the method WC_Updates_Screen_Updates::generic_modal_js() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
93
	}
94
}
95
new WC_Updates_Screen_Updates();
96