Issues (87)

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.

includes/class-ajax.php (3 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
namespace DummyPress;
3
4
/**
5
 * Handling Ajax return and data
6
 *
7
 * @package    WordPress
8
 * @subpackage Evans
9
 * @author     Mike Selander
10
 */
11
class Ajax {
12
13
	/**
14
	 * reporting
15
	 * Reporting class instance.
16
	 *
17
	 * @var object
18
	 * @access private
19
	 */
20
	private $reporting;
21
22
	/**
23
	 * plugin
24
	 * Plugin class instance.
25
	 *
26
	 * @var object
27
	 */
28
	private $plugin;
29
30
	/**
31
	 * action
32
	 * Name of the action we want to use in our AJAX calls
33
	 *
34
	 * @var string
35
	 */
36
	private $action;
37
38
39
	/**
40
	 * Instantiate any WP hooks that need to be fired.
41
	 */
42
	public function hooks() {
43
44
		$this->reporting    = new Reporting;
45
		$this->action       = 'handle_test_data';
46
47
		add_action( "wp_ajax_{$this->action}", array( $this, 'handle_ajax' ) );
48
		add_filter( 'option_active_plugins', array( $this, 'ajax_exclude_plugins' ) );
49
50
	}
51
52
53
	/**
54
	 * Set a reference to the main plugin instance.
55
	 *
56
	 * @param $plugin Plugin instance.
57
	 * @return Ajax instance
58
	 */
59
	public function set_plugin( $plugin ) {
60
61
		$this->plugin = $plugin;
62
		return $this;
63
64
	}
65
66
67
	/**
68
	 * Turn outside plugins off during our AJAX calls to speed everything up.
69
	 *
70
	 * Having a lot of plugins running slows down an AJAX request, this function
71
	 * turns all other plugins off temporarliy while the AJAX requests is running.
72
	 *
73
	 * https://deliciousbrains.com/excluding-wordpress-plugins-loading-specific-ajax-requests/
74
	 *
75
	 * @param array $plugins All active plugins.
76
	 * @return array Whitelisted plugins.
77
	 */
78
	public function ajax_exclude_plugins( $plugins ) {
0 ignored issues
show
ajax_exclude_plugins uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
79
80
		if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || ! isset( $_POST['action'] ) || false === strpos( $_POST['action'], $this->action ) ) {
81
			return $plugins;
82
		}
83
84
		foreach( $plugins as $key => $plugin ) {
85
86
			if ( false !== strpos( $plugin, $this->plugin->definitions->slug ) ) {
87
				continue;
88
			}
89
90
			unset( $plugins[$key] );
91
		}
92
93
		return $plugins;
94
95
	}
96
97
98
	/**
99
	 * Ajax callback function for triggering the creation & deletion of test data.
100
	 *
101
	 * @see wp_ajax filter, $this->add_menu_item, $this->creation_routing
102
	 */
103
	public function handle_ajax() {
0 ignored issues
show
handle_ajax uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
104
105
		$action		= $_REQUEST['todo'];
106
		$nonce		= $_REQUEST['nonce'];
107
108
		// Verify that we have a proper logged in user and it's the right person
109
		if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ) {
110
			return;
111
		}
112
113
		if ( $action == 'delete' ) {
114
115
			$this->deletion_routing( $_REQUEST );
116
117
		} elseif ( $action == 'create' ) {
118
119
			$this->creation_routing( $_REQUEST );
120
121
		}
122
123
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle_ajax() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
124
125
	}
126
127
128
	/**
129
	 * Choose which type of creation needs to be accomplished and route through
130
	 * the correct class.
131
	 */
132
	private function creation_routing( $data ) {
133
134
		$type = 'DummyPress\Types\\' . ucwords( $data['type'] );
135
		$object = new $type();
136
		$return = $object->create_objects( $data['slug'], $data['connection'], true, 1 );
137
138
		$clean = $this->reporting->create_report( $return );
139
140
		echo $clean;
141
142
	}
143
144
145
	/**
146
	 * Choose which type of deletion needs to be accomplished and route through
147
	 * the correct method of Delete.
148
	 */
149
	private function deletion_routing( $data ) {
150
151
		$delete_content = new Delete;
152
153
		if ( $data['type'] == 'all' ) {
154
155
			$return = $delete_content->delete_all_test_data();
156
157
		} else {
158
159
			$return = $delete_content->delete_objects( $data );
160
161
		}
162
163
		$clean = $this->reporting->create_report( $return );
164
165
		echo $clean;
166
167
	}
168
169
170
}
171