Issues (311)

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/timber-user.php (2 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
/**
4
 * This is used in Timber to represent users retrived from WordPress. You can call `$my_user = new TimberUser(123);` directly, or access it through the `{{ post.author }}` method.
5
 * @example
6
 * ```php
7
 * $context['current_user'] = new TimberUser();
8
 * $context['post'] = new TimberPost();
9
 * Timber::render('single.twig', $context);
10
 * ```
11
 * ```twig
12
 * <p class="current-user-info">Your name is {{ current_user.name }}</p>
13
 * <p class="article-info">This article is called "{{ post.title }}" and it's by {{ post.author.name }}
14
 * ```
15
 * ```html
16
 * <p class="current-user-info">Your name is Jesse Eisenberg</p>
17
 * <p class="article-info">This article is called "Consider the Lobster" and it's by David Foster Wallace
18
 * ```
19
 */
20
class TimberUser extends TimberCore implements TimberCoreInterface {
21
22
	public $object_type = 'user';
23
	public static $representation = 'user';
24
25
	public $_link;
26
27
	/**
28
	 * @api
29
	 * @var string The description from WordPress
30
	 */
31
	public $description;
32
	public $display_name;
33
34
	/**
35
	 * @api
36
	 * @var  string The first name of the user
37
	 */
38
	public $first_name;
39
40
	/**
41
	 * @api
42
	 * @var  string The last name of the user
43
	 */
44
	public $last_name;
45
46
	/**
47
	 * @api
48
	 * @var int The ID from WordPress
49
	 */
50
	public $id;
51
	public $user_nicename;
52
53
	/**
54
	 * @param int|bool $uid
55
	 */
56
	function __construct($uid = false) {
57
		$this->init($uid);
58
	}
59
60
	/**
61
	 * @example
62
	 * ```twig
63
	 * This post is by {{ post.author }}
64
	 * ```
65
	 * ```html
66
	 * This post is by Jared Novack
67
	 * ```
68
	 *
69
	 * @return string a fallback for TimberUser::name()
70
	 */
71
	function __toString() {
72
		$name = $this->name();
73
		if ( strlen($name) ) {
74
			return $name;
75
		}
76
		if ( strlen($this->name) ) {
77
			return $this->name;
78
		}
79
		return '';
80
	}
81
82
	/**
83
	 * @internal
84
	 * @param string $field_name
85
	 * @return null
86
	 */
87
	function get_meta($field_name) {
88
		return $this->get_meta_field($field_name);
89
	}
90
91
	/**
92
	 * @internal
93
	 * @param string 	$field
94
	 * @param mixed 	$value
95
	 */
96
	function __set($field, $value) {
97
		if ( $field == 'name' ) {
98
			$this->display_name = $value;
99
		}
100
		$this->$field = $value;
101
	}
102
103
	/**
104
	 * @internal
105
	 * @param int|bool $uid The user ID to use
106
	 */
107
	protected function init($uid = false) {
108
		if ( $uid === false ) {
109
			$uid = get_current_user_id();
110
		}
111
		if ( is_object($uid) || is_array($uid) ) {
112
			$data = $uid;
113
			if ( is_array($uid) ) {
114
				$data = (object) $uid;
115
			}
116
			$uid = $data->ID;
117
		}
118
		if ( is_numeric($uid) ) {
119
			$data = get_userdata($uid);
120
		} else if ( is_string($uid) ) {
121
			$data = get_user_by('login', $uid);
122
		}
123
		if ( isset($data) && is_object($data) ) {
124
			if ( isset($data->data) ) {
125
				$this->import($data->data);
126
			} else {
127
				$this->import($data);
128
			}
129
		}
130
		$this->id = $this->ID;
131
		$this->name = $this->name();
132
		$custom = $this->get_custom();
133
		$this->import($custom);
134
	}
135
136
	/**
137
	 * @param string $field_name
138
	 * @return mixed
139
	 */
140 View Code Duplication
	function get_meta_field($field_name) {
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...
141
		$value = null;
142
		$value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this);
143
		if ( $value === null ) {
144
			$value = get_user_meta($this->ID, $field_name, true);
145
		}
146
		$value = apply_filters('timber_user_get_meta_field', $value, $this->ID, $field_name, $this);
147
		return $value;
148
	}
149
150
	/**
151
	 * @return array|null
152
	 */
153
	function get_custom() {
154
		if ( $this->ID ) {
155
			$um = array();
156
			$um = apply_filters('timber_user_get_meta_pre', $um, $this->ID, $this);
157
			if ( empty($um) ) {
158
				$um = get_user_meta($this->ID);
159
			}
160
			$custom = array();
161 View Code Duplication
			foreach ($um as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
162
				if ( is_array($value) && count($value) == 1 ) {
163
					$value = $value[0];
164
				}
165
				$custom[$key] = maybe_unserialize($value);
166
			}
167
			$custom = apply_filters('timber_user_get_meta', $custom, $this->ID, $this);
168
			return $custom;
169
		}
170
		return null;
171
	}
172
173
	/**
174
	 * @api
175
	 * @return string http://example.org/author/lincoln
176
	 */
177
	public function link() {
178
		if ( !$this->_link ) {
179
			$this->_link = untrailingslashit(get_author_posts_url($this->ID));
180
		}
181
		return $this->_link;
182
	}
183
184
	/**
185
	 * @api
186
	 * @return string the human-friendly name of the user (ex: "Buster Bluth")
187
	 */
188
	function name() {
189
		return $this->display_name;
190
	}
191
192
	/**
193
	 * @param string $field_name
194
	 * @return mixed
195
	 */
196
	function meta($field_name) {
197
		return $this->get_meta_field($field_name);
198
	}
199
200
	/**
201
	 * @api
202
	 * @return string ex: /author/lincoln
203
	 */
204
	public function path() {
205
		return TimberURLHelper::get_rel_url($this->get_link());
206
	}
207
208
	/**
209
	 * @api
210
	 * @return string ex baberaham-lincoln
211
	 */
212
	public function slug() {
213
		return $this->user_nicename;
214
	}
215
216
	/**
217
	 * @deprecated 0.21.9
218
	 * @return string The link to a user's profile page
219
	 */
220
	function get_link() {
221
		return $this->link();
222
	}
223
224
	/**
225
	 * @deprecated 0.21.8
226
	 * @return string ex: /author/lincoln
227
	 */
228
	function get_path() {
229
		return $this->path();
230
	}
231
232
	/**
233
	 * @deprecated 0.21.8
234
	 * @return string
235
	 */
236
	function get_permalink() {
237
		return $this->get_link();
238
	}
239
240
	/**
241
	 * @deprecated 0.21.8
242
	 * @return string
243
	 */
244
	function permalink() {
245
		return $this->get_permalink();
246
	}
247
248
}
249