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-connection-test.php (6 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
 * ConnectionTest
6
 *
7
 * A more intelligent check to see if we can connect to Splashbase or not.
8
 *
9
 * This class checks whether or not we can connect to the Internet, and
10
 * if we can, whether we can connect to Splashbase itself. This is used by
11
 * our admin notice function to check whether or not we should display a notice
12
 * to users warning them of issues with Splashbase.
13
 *
14
 * The purpose of this is to avoid useless bug-hunting when images don't work.
15
 *
16
 * @package    WordPress
17
 * @subpackage Evans
18
 * @author     Mike Selander
19
 */
20
class ConnectionTest {
21
22
	/**
23
	 * Run all of our connection tests.
24
	 *
25
	 * @see check_admin_page, check_airplane_mode, check_internet, check_splashbase
26
	 *
27
	 * @return boolean Status of connection to Internet/Splashbase.
0 ignored issues
show
Should the return type not be null|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
	 */
29
	public function test() {
30
31
		/*
32
		 * Make sure that we're looking at the correct admin page
33
		 */
34
		if ( ! $this->check_admin_page() ) {
35
			return;
36
		}
37
38
		/*
39
		 * Test #1 - Check for Airplane Mode plugin status
40
		 */
41
		if ( ! $this->check_airplane_mode() ) {
42
			return false;
43
		}
44
45
		/*
46
		 * Test #2 - Check Internet connection in general
47
		 */
48
		if ( ! $this->check_internet() ) {
49
			return false;
50
		}
51
52
		/*
53
		 * Test #3 - Check External URL itself (Splashbase here)
54
		 */
55
		if ( ! $this->check_external_url( 'http://www.splashbase.co/api/v1/images/' ) ) {
0 ignored issues
show
This if statement, and the following return statement can be replaced with return $this->check_exte...se.co/api/v1/images/');.
Loading history...
56
			return false;
57
		}
58
59
		// We've made it this far, looks like everything checks out OK!
60
		return true;
61
62
	}
63
64
65
	/**
66
	 * Check to make sure that we're only running this check in the correct place.
67
	 *
68
	 * We only want these (relatively)expensive checks to run on a single admin
69
	 * page, so we need to run some checks first and verify that we're on the
70
	 * right screen.
71
	 *
72
	 * @access private
73
	 *
74
	 * @global object $current_screen Current admin screen info.
75
	 *
76
	 * @return boolean Whether or not we're in the right place.
77
	 */
78
	private function check_admin_page() {
0 ignored issues
show
check_admin_page uses the super-global variable $_SERVER 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
		global $current_screen;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
80
81
		// Only run if we're in the admin page
82
		if ( ! is_admin() ) {
83
			return false;
84
		}
85
86
		// Get the current admin screen & verify that we're on the right one
87
		// before continuing.
88
		if ( isset ( $current_screen ) && 'tools_page_create-test-data' != $current_screen->base ) {
89
			return false;
90
		}
91
92
		$last_uri_bit = explode( '=', $_SERVER['REQUEST_URI'] );
93
		if ( 'create-test-data' != end( $last_uri_bit ) ) {
0 ignored issues
show
This if statement, and the following return statement can be replaced with return !('create-test-da...!= end($last_uri_bit));.
Loading history...
94
			return false;
95
		}
96
97
		return true;
98
99
	}
100
101
102
	/**
103
	 * Check if we have Airplane Mode and if it's turned on or not.
104
	 *
105
	 * @access private
106
	 *
107
	 * @see get_site_option
108
	 *
109
	 * @return boolean Connected or not.
110
	 */
111
	private function check_airplane_mode() {
112
113
		if ( class_exists( 'Airplane_Mode_Core' ) ) {
114
			// Is airplane mode active?
115
			$airplane_mode = get_site_option( 'airplane-mode' );
116
117
			if ( $airplane_mode === 'on' ) {
118
				return false;
119
			}
120
		}
121
122
		return true;
123
124
	}
125
126
127
	/**
128
	 * Attempt to open a socket to a popular, compact to check overall connectivity.
129
	 *
130
	 * @access private
131
	 *
132
	 * @see fsockopen, fsockclose
133
	 *
134
	 * @return boolean Connected or not.
135
	 */
136
	private function check_internet() {
137
138
		// Attempt to open a socket connection to Google
139
		$connected = @fsockopen( "www.google.com", 80 );
140
141
		if ( ! $connected ) {
142
			return false;
143
		}
144
145
		// Close out our 1st test
146
		fclose( $connected );
147
148
		return true;
149
150
	}
151
152
153
	/**
154
	 * Check an external API to see if it's reachable or not.
155
	 *
156
	 * @access private
157
	 *
158
	 * @see wp_remote_get
159
	 *
160
	 * @param string $url External URL to attempt to reach.
161
	 * @return boolean Connected or not.
162
	 */
163
	private function check_external_url( $url ) {
164
165
		$test_url = esc_url( $url );
166
		$response = wp_remote_get( $test_url );
167
168
		if ( ! is_array( $response ) ) {
0 ignored issues
show
This if statement, and the following return statement can be replaced with return is_array($response);.
Loading history...
169
			return false;
170
		}
171
172
		return true;
173
174
	}
175
176
}
177