Issues (53)

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.

lib/class-helpers.php (10 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Plugin Helpers.
4
 *
5
 * @package WP_To_Diaspora\Helpers
6
 * @since 1.3.0
7
 */
8
9
// Exit if accessed directly.
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Various helper methods.
14
 */
15
class WP2D_Helpers {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
17
	/**
18
	 * Debug text that get's accumulated before output.
19
	 *
20
	 * @var string
21
	 */
22
	private static $_debugging = '';
23
24
	/**
25
	 * Add a line to the debug output. Include the stack trace to see where it's coming from.
26
	 *
27
	 * @param string $text Text to add.
28
	 */
29
	public static function add_debugging( $text ) {
30
		// Make sure we're in debug mode.
31
		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
32
			$d = '';
33
			foreach ( debug_backtrace() as $dbt ) {
34
				extract( $dbt );
35
				// Only trace back as far as the plugin goes.
36
				if ( strstr( $file, plugin_dir_path( dirname( __FILE__ ) ) ) ) {
37
					$d = sprintf( "%s%s%s [%s:%s]\n", $class, $type, $function, basename( $file ), $line ) . $d;
38
				}
39
			}
40
41
			self::$_debugging .= sprintf( "%s\n%s\n", date( 'Y.m.d H:i:s' ), $d . $text );
42
43
			return true;
44
		}
45
		return false;
46
	}
47
48
	/**
49
	 * Return the debug output.
50
	 *
51
	 * @return string The debug output.
52
	 */
53
	public static function get_debugging() {
54
		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
55
			return self::$_debugging;
56
		}
57
		return false;
58
	}
59
60
	/**
61
	 * Convert a string with comma seperated values to an array.
62
	 *
63
	 * @todo Make $input by value.
64
	 *
65
	 * @param array|string $input The string to be converted.
66
	 * @return array The converted array.
67
	 */
68 View Code Duplication
	public static function str_to_arr( &$input ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
		if ( ! is_array( $input ) ) {
70
			// Explode string > Trim each entry > Remove blanks > Re-index array.
71
			$input = array_values( array_filter( array_map( 'trim', explode( ',', $input ) ) ) );
72
		} else {
73
			// If we're already an array, make sure we return it clean.
74
			self::arr_to_str( $input );
75
			self::str_to_arr( $input );
76
		}
77
		return $input;
78
	}
79
80
	/**
81
	 * Convert an array to a string with comma seperated values.
82
	 *
83
	 * @todo Make $input by value.
84
	 *
85
	 * @param array|string $input The array to be converted.
86
	 * @return string The converted string.
87
	 */
88 View Code Duplication
	public static function arr_to_str( &$input ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
		if ( is_array( $input ) ) {
90
			// Trim each entry > Remove blanks > Implode them together.
91
			$input = implode( ',', array_filter( array_map( 'trim', $input ) ) );
92
		} else {
93
			// If we're already a string, make sure we return it clean.
94
			self::str_to_arr( $input );
95
			self::arr_to_str( $input );
96
		}
97
		return $input;
98
	}
99
100
	/**
101
	 * Encrypt the passed string with the passed key.
102
	 *
103
	 * @param string $input String to be encrypted.
104
	 * @param string $key   The key used for the encryption.
105
	 * @return string The encrypted string.
106
	 */
107 View Code Duplication
	public static function encrypt( $input, $key = AUTH_KEY ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
		if ( is_null( $input ) || '' === $input ) {
109
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by WP2D_Helpers::encrypt of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
110
		}
111
		global $wpdb;
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...
112
		return $wpdb->get_var( $wpdb->prepare( 'SELECT HEX(AES_ENCRYPT(%s,%s))', $input, $key ) );
113
	}
114
115
	/**
116
	 * Decrypt the passed string with the passed key.
117
	 *
118
	 * @param string $input String to be decrypted.
119
	 * @param string $key   The key used for the decryption.
120
	 * @return string The decrypted string.
121
	 */
122 View Code Duplication
	public static function decrypt( $input, $key = AUTH_KEY ) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
		if ( is_null( $input ) || '' === $input ) {
124
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by WP2D_Helpers::decrypt of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
125
		}
126
		global $wpdb;
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...
127
		return $wpdb->get_var( $wpdb->prepare( 'SELECT AES_DECRYPT(UNHEX(%s),%s)', $input, $key ) );
128
	}
129
130
	/**
131
	 * Set up and return an API connection using the currently saved options..
132
	 *
133
	 * @return WP2D_API The API object.
134
	 */
135
	public static function api_quick_connect() {
136
		$options   = WP2D_Options::instance();
137
		$pod       = (string) $options->get_option( 'pod' );
138
		$is_secure = true;
139
		$username  = (string) $options->get_option( 'username' );
140
		$password  = WP2D_Helpers::decrypt( (string) $options->get_option( 'password' ) );
141
142
		$api = new WP2D_API( $pod, $is_secure );
143
144
		// This is necessary for correct error handling!
145
		if ( $api->init() ) {
146
			$api->login( $username, $password );
147
		}
148
149
		if ( $api->has_last_error() ) {
150
			self::add_debugging( $api->get_last_error() );
151
		}
152
153
		return $api;
154
	}
155
}
156