GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (81)

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/libs/twitter-user.php (7 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
// Exit if accessed directly
4
if ( !defined( 'ABSPATH' ) ) {
5
	exit;
6
}
7
8
/**
9
 * Twitter Class
10
 *
11
 * Handles all twitter functions
12
 *
13
 */
14
if( !class_exists( 'PPP_Twitter_User' ) ) {
15
16
	class PPP_Twitter_User {
17
18
		public function __construct( $_user_id = 0 ) {
19
			ppp_maybe_start_session();
20
			$this->user_id = $_user_id;
0 ignored issues
show
The property user_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
22
			if ( ! empty( $this->user_id ) ) {
23
				$this->verify_credentials();
24
			}
25
		}
26
27
		/**
28
		 * Include Twitter Class
29
		 *
30
		 * Handles to load twitter class
31
		 */
32
		public function load() {
33
				if( !class_exists( 'TwitterOAuth' ) ) {
34
					require_once ( PPP_PATH . '/includes/libs/twitter/twitteroauth.php' );
35
				}
36
37
				ppp_set_social_tokens();
38
39
				if ( ! defined( 'PPP_TW_CONSUMER_KEY' ) || ! defined( 'PPP_TW_CONSUMER_SECRET' ) ) {
40
					return false;
41
				}
42
43
				$this->twitter = new TwitterOAuth( PPP_TW_CONSUMER_KEY, PPP_TW_CONSUMER_SECRET );
0 ignored issues
show
The property twitter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
45
				return true;
46
		}
47
48
		public function revoke_access() {
49
			delete_user_meta( $this->user_id, '_ppp_twitter_data' );
50
		}
51
52
		/**
53
		 * Initializes Twitter API
54
		 *
55
		 */
56
		public function init() {
57
58
			//when user is going to logged in in twitter and verified successfully session will create
59
			if ( isset( $_REQUEST['oauth_verifier'] ) ) {
60
61
				//load twitter class
62
				$twitter       = $this->load();
0 ignored issues
show
$twitter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
				$this->twitter = new TwitterOAuth( PPP_TW_CONSUMER_KEY, PPP_TW_CONSUMER_SECRET, $_SESSION['ppp_user_twt_oauth_token'], $_SESSION['ppp_user_twt_oauth_token_secret'] );
64
65
				// Request access tokens from twitter
66
				$ppp_tw_access_token = $this->twitter->getAccessToken( $_REQUEST['oauth_verifier'] );
67
68
				//session for verifier
69
				$verifier['oauth_verifier']       = $_REQUEST['oauth_verifier'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$verifier was never initialized. Although not strictly required by PHP, it is generally a good practice to add $verifier = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
70
				$_SESSION[ 'ppp_twt_user_cache' ] = $verifier;
71
72
				//getting user data from twitter
73
				$response = $this->twitter->get( 'account/verify_credentials' );
74
75
				//if user data get successfully
76
				if ( $response->id_str ) {
77
					$data['user'] = $response;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
78
					$data['user']->accessToken = $ppp_tw_access_token;
79
80
					update_user_meta( $this->user_id, '_ppp_twitter_data', $data );
81
				}
82
			}
83
		}
84
85
		public function verify_credentials() {
86
			$this->load();
87
88
			$user_settings = get_user_meta( $this->user_id, '_ppp_twitter_data', true );
89
			if ( ! empty( $user_settings ) ) {
90
91
				$this->twitter = new TwitterOAuth(
92
					PPP_TW_CONSUMER_KEY,
93
					PPP_TW_CONSUMER_SECRET,
94
					$user_settings['user']->accessToken['oauth_token'],
95
					$user_settings['user']->accessToken['oauth_token_secret']
96
				);
97
98
				$response = $this->twitter->get('account/verify_credentials');
99
				if ( is_object( $response ) && property_exists( $response, 'errors' ) && count( $response->errors ) > 0 ) {
100
					foreach ( $response->errors as $error ) {
101
						if ( $error->code == 89 ) { // Expired or revoked tokens
102
103
							$this->revoke_access();
104
105
							return array( 'error' => __( 'Post Promoter Pro has been removed from your Twitter account. Please reauthorize to continue promoting your content.', 'ppp-txt' ) );
106
						}
107
					}
108
				}
109
			}
110
111
			return true;
112
		}
113
114
		/**
115
		 * Get auth url for twitter
116
		 *
117
		 */
118
		public function get_auth_url ( $return_url = '' ) {
119
120
			if ( empty( $return_url ) ) {
121
				$return_url = admin_url( 'admin.php?page=ppp-social-settings' );
0 ignored issues
show
$return_url is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
122
			}
123
124
			//load twitter class
125
			$twitter       = $this->load();
0 ignored issues
show
$twitter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
126
			$request_token = $this->twitter->getRequestToken( 'oob' );
127
128
			// If last connection failed don't display authorization link.
129
			switch( $this->twitter->http_code ) {
130
				case 200:
131
					$_SESSION['ppp_user_twt_oauth_token']        = $request_token['oauth_token'];
132
					$_SESSION['ppp_user_twt_oauth_token_secret'] = $request_token['oauth_token_secret'];
133
134
					$token = $request_token['oauth_token'];
135
					$url = $this->twitter->getAuthorizeURL( $token, NULL );
136
				break;
137
				default:
138
					$url = '';
139
				break;
140
			}
141
142
			return $url;
143
		}
144
145
		public function send_tweet( $message = '', $media = null ) {
146
			if ( empty( $message ) ) {
147
				return false;
148
			}
149
150
			$verify = $this->verify_credentials();
151
			if ( $verify === true ) {
152
				$args = array();
153
				if ( ! empty( $media ) ) {
154
					$endpoint = 'statuses/update_with_media';
155
					$args['media[]'] = wp_remote_retrieve_body( wp_remote_get( $media ) );
156
				} else {
157
					$endpoint = 'statuses/update';
158
				}
159
				$args['status'] = $message;
160
161
				return $this->twitter->post( $endpoint, $args, true );
162
			} else {
163
				return false;
164
			}
165
		}
166
167
		public function retweet( $tweet_id ) {
168
			if ( empty( $tweet_id ) ) {
169
				return false;
170
			}
171
172
			$verify = $this->verify_credentials();
173
			if ( $verify === true ) {
174
				$endpoint = 'statuses/retweet/' . $tweet_id;
175
176
				return $this->twitter->post( $endpoint, array(), true );
177
			} else {
178
				return false;
179
			}
180
		}
181
182
	}
183
184
}
185