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.

src/wp-trackback.php (5 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
 * Handle Trackbacks and Pingbacks Sent to WordPress
4
 *
5
 * @since 0.71
6
 *
7
 * @package WordPress
8
 * @subpackage Trackbacks
9
 */
10
11
if (empty($wp)) {
12
	require_once( dirname( __FILE__ ) . '/wp-load.php' );
13
	wp( array( 'tb' => '1' ) );
14
}
15
16
/**
17
 * Response to a trackback.
18
 *
19
 * Responds with an error or success XML message.
20
 *
21
 * @since 0.71
22
 *
23
 * @param mixed  $error         Whether there was an error.
0 ignored issues
show
Consider making the type for parameter $error a bit more specific; maybe use integer.
Loading history...
24
 *                              Default '0'. Accepts '0' or '1', true or false.
25
 * @param string $error_message Error message if an error occurred.
26
 */
27
function trackback_response($error = 0, $error_message = '') {
28
	header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
29
	if ($error) {
30
		echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
31
		echo "<response>\n";
32
		echo "<error>1</error>\n";
33
		echo "<message>$error_message</message>\n";
34
		echo "</response>";
35
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The function trackback_response() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
36
	} else {
37
		echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
38
		echo "<response>\n";
39
		echo "<error>0</error>\n";
40
		echo "</response>";
41
	}
42
}
43
44
// Trackback is done by a POST.
45
$request_array = 'HTTP_POST_VARS';
46
47
if ( !isset($_GET['tb_id']) || !$_GET['tb_id'] ) {
48
	$tb_id = explode('/', $_SERVER['REQUEST_URI']);
49
	$tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
50
}
51
52
$tb_url  = isset($_POST['url'])     ? $_POST['url']     : '';
53
$charset = isset($_POST['charset']) ? $_POST['charset'] : '';
54
55
// These three are stripslashed here so they can be properly escaped after mb_convert_encoding().
56
$title     = isset($_POST['title'])     ? wp_unslash($_POST['title'])      : '';
57
$excerpt   = isset($_POST['excerpt'])   ? wp_unslash($_POST['excerpt'])    : '';
58
$blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name'])  : '';
59
60
if ($charset)
61
	$charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) );
62
else
63
	$charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
64
65
// No valid uses for UTF-7.
66
if ( false !== strpos($charset, 'UTF-7') )
67
	die;
68
69
// For international trackbacks.
70
if ( function_exists('mb_convert_encoding') ) {
71
	$title     = mb_convert_encoding($title, get_option('blog_charset'), $charset);
72
	$excerpt   = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
73
	$blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
74
}
75
76
// Now that mb_convert_encoding() has been given a swing, we need to escape these three.
77
$title     = wp_slash($title);
78
$excerpt   = wp_slash($excerpt);
79
$blog_name = wp_slash($blog_name);
80
81
if ( is_single() || is_page() )
82
	$tb_id = $posts[0]->ID;
83
84
if ( !isset($tb_id) || !intval( $tb_id ) )
85
	trackback_response( 1, __( 'I really need an ID for this to work.' ) );
86
87
if (empty($title) && empty($tb_url) && empty($blog_name)) {
88
	// If it doesn't look like a trackback at all.
89
	wp_redirect(get_permalink($tb_id));
0 ignored issues
show
It seems like get_permalink($tb_id) targeting get_permalink() can also be of type false; however, wp_redirect() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
90
	exit;
91
}
92
93
if ( !empty($tb_url) && !empty($title) ) {
94
	/**
95
	* Fires before the trackback is added to a post.
96
	*
97
	* @since 4.7.0
98
	*
99
	* @param int    $tb_id     Post ID related to the trackback.
100
	* @param string $tb_url    Trackback URL.
101
	* @param string $charset   Character Set.
102
	* @param string $title     Trackback Title.
103
	* @param string $excerpt   Trackback Excerpt.
104
	* @param string $blog_name Blog Name.
105
	*/
106
	do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name );
107
108
	header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
109
110
	if ( !pings_open($tb_id) )
111
		trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
112
113
	$title =  wp_html_excerpt( $title, 250, '&#8230;' );
0 ignored issues
show
It seems like $title can also be of type array; however, wp_html_excerpt() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
114
	$excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
0 ignored issues
show
It seems like $excerpt can also be of type array; however, wp_html_excerpt() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
115
116
	$comment_post_ID = (int) $tb_id;
117
	$comment_author = $blog_name;
118
	$comment_author_email = '';
119
	$comment_author_url = $tb_url;
120
	$comment_content = "<strong>$title</strong>\n\n$excerpt";
121
	$comment_type = 'trackback';
122
123
	$dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) );
124
	if ( $dupe )
125
		trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) );
126
127
	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
128
129
	wp_new_comment($commentdata);
130
	$trackback_id = $wpdb->insert_id;
131
132
	/**
133
	 * Fires after a trackback is added to a post.
134
	 *
135
	 * @since 1.2.0
136
	 *
137
	 * @param int $trackback_id Trackback ID.
138
	 */
139
	do_action( 'trackback_post', $trackback_id );
140
	trackback_response( 0 );
141
}
142