Issues (4967)

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.

wp-includes/class-wp-user-meta-session-tokens.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
/**
3
 * Session API: WP_User_Meta_Session_Tokens class
4
 *
5
 * @package WordPress
6
 * @subpackage Session
7
 * @since 4.7.0
8
 */
9
10
/**
11
 * Meta-based user sessions token manager.
12
 *
13
 * @since 4.0.0
14
 */
15
class WP_User_Meta_Session_Tokens extends WP_Session_Tokens {
16
17
	/**
18
	 * Get all sessions of a user.
19
	 *
20
	 * @since 4.0.0
21
	 * @access protected
22
	 *
23
	 * @return array Sessions of a user.
24
	 */
25
	protected function get_sessions() {
26
		$sessions = get_user_meta( $this->user_id, 'session_tokens', true );
27
28
		if ( ! is_array( $sessions ) ) {
29
			return array();
30
		}
31
32
		$sessions = array_map( array( $this, 'prepare_session' ), $sessions );
33
		return array_filter( $sessions, array( $this, 'is_still_valid' ) );
34
	}
35
36
	/**
37
	 * Converts an expiration to an array of session information.
38
	 *
39
	 * @param mixed $session Session or expiration.
40
	 * @return array Session.
0 ignored issues
show
Should the return type not be object|double|string|null|array|boolean? Also, consider making the array more specific, something like array<String>, or String[].

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.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
41
	 */
42
	protected function prepare_session( $session ) {
43
		if ( is_int( $session ) ) {
44
			return array( 'expiration' => $session );
45
		}
46
47
		return $session;
48
	}
49
50
	/**
51
	 * Retrieve a session by its verifier (token hash).
52
	 *
53
	 * @since 4.0.0
54
	 * @access protected
55
	 *
56
	 * @param string $verifier Verifier of the session to retrieve.
57
	 * @return array|null The session, or null if it does not exist
58
	 */
59
	protected function get_session( $verifier ) {
60
		$sessions = $this->get_sessions();
61
62
		if ( isset( $sessions[ $verifier ] ) ) {
63
			return $sessions[ $verifier ];
64
		}
65
66
		return null;
67
	}
68
69
	/**
70
	 * Update a session by its verifier.
71
	 *
72
	 * @since 4.0.0
73
	 * @access protected
74
	 *
75
	 * @param string $verifier Verifier of the session to update.
76
	 * @param array  $session  Optional. Session. Omitting this argument destroys the session.
0 ignored issues
show
Should the type for parameter $session not be array|null? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
77
	 */
78
	protected function update_session( $verifier, $session = null ) {
79
		$sessions = $this->get_sessions();
80
81
		if ( $session ) {
82
			$sessions[ $verifier ] = $session;
83
		} else {
84
			unset( $sessions[ $verifier ] );
85
		}
86
87
		$this->update_sessions( $sessions );
88
	}
89
90
	/**
91
	 * Update a user's sessions in the usermeta table.
92
	 *
93
	 * @since 4.0.0
94
	 * @access protected
95
	 *
96
	 * @param array $sessions Sessions.
97
	 */
98
	protected function update_sessions( $sessions ) {
99
		if ( $sessions ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sessions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
100
			update_user_meta( $this->user_id, 'session_tokens', $sessions );
101
		} else {
102
			delete_user_meta( $this->user_id, 'session_tokens' );
103
		}
104
	}
105
106
	/**
107
	 * Destroy all session tokens for a user, except a single session passed.
108
	 *
109
	 * @since 4.0.0
110
	 * @access protected
111
	 *
112
	 * @param string $verifier Verifier of the session to keep.
113
	 */
114
	protected function destroy_other_sessions( $verifier ) {
115
		$session = $this->get_session( $verifier );
116
		$this->update_sessions( array( $verifier => $session ) );
117
	}
118
119
	/**
120
	 * Destroy all session tokens for a user.
121
	 *
122
	 * @since 4.0.0
123
	 * @access protected
124
	 */
125
	protected function destroy_all_sessions() {
126
		$this->update_sessions( array() );
127
	}
128
129
	/**
130
	 * Destroy all session tokens for all users.
131
	 *
132
	 * @since 4.0.0
133
	 * @access public
134
	 * @static
135
	 */
136
	public static function drop_sessions() {
137
		delete_metadata( 'user', 0, 'session_tokens', false, true );
138
	}
139
}
140