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-admin/revision.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
 * Revisions administration panel
4
 *
5
 * Requires wp-admin/includes/revision.php.
6
 *
7
 * @package WordPress
8
 * @subpackage Administration
9
 * @since 2.6.0
10
 *
11
 * @param int    revision Optional. The revision ID.
12
 * @param string action   The action to take.
13
 *                        Accepts 'restore', 'view' or 'edit'.
14
 * @param int    from     The revision to compare from.
15
 * @param int    to       Optional, required if revision missing. The revision to compare to.
16
 */
17
18
/** WordPress Administration Bootstrap */
19
require_once( dirname( __FILE__ ) . '/admin.php' );
20
21
require ABSPATH . 'wp-admin/includes/revision.php';
22
23
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
24
25
$revision_id = absint( $revision );
26
27
$from = is_numeric( $from ) ? absint( $from ) : null;
28
if ( ! $revision_id )
29
	$revision_id = absint( $to );
30
$redirect = 'edit.php';
31
32
switch ( $action ) {
33
case 'restore' :
34
	if ( ! $revision = wp_get_post_revision( $revision_id ) )
35
		break;
36
37
	if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
38
		break;
39
40
	if ( ! $post = get_post( $revision->post_parent ) )
41
		break;
42
43
	// Restore if revisions are enabled or this is an autosave.
44 View Code Duplication
	if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
45
		$redirect = 'edit.php?post_type=' . $post->post_type;
46
		break;
47
	}
48
49
	// Don't allow revision restore when post is locked
50
	if ( wp_check_post_lock( $post->ID ) )
51
		break;
52
53
	check_admin_referer( "restore-post_{$revision->ID}" );
54
55
	wp_restore_post_revision( $revision->ID );
56
	$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
57
	break;
58
case 'view' :
59
case 'edit' :
60
default :
61
	if ( ! $revision = wp_get_post_revision( $revision_id ) )
62
		break;
63
	if ( ! $post = get_post( $revision->post_parent ) )
64
		break;
65
66
	if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) )
67
		break;
68
69
	// Revisions disabled and we're not looking at an autosave
70 View Code Duplication
	if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
71
		$redirect = 'edit.php?post_type=' . $post->post_type;
72
		break;
73
	}
74
75
	$post_edit_link = get_edit_post_link();
76
	$post_title     = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
77
	/* translators: 1: Post title */
78
	$h1             = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
79
	$return_to_post = '<a href="' . $post_edit_link . '">' . __( '&larr; Return to editor' ) . '</a>';
80
	$title          = __( 'Revisions' );
81
82
	$redirect = false;
83
	break;
84
}
85
86
// Empty post_type means either malformed object found, or no valid parent was found.
87
if ( ! $redirect && empty( $post->post_type ) )
0 ignored issues
show
Bug Best Practice introduced by
The expression $redirect of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
88
	$redirect = 'edit.php';
89
90
if ( ! empty( $redirect ) ) {
91
	wp_redirect( $redirect );
92
	exit;
93
}
94
95
// This is so that the correct "Edit" menu item is selected.
96
if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
97
	$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
98
else
99
	$parent_file = $submenu_file = 'edit.php';
100
101
wp_enqueue_script( 'revisions' );
102
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
0 ignored issues
show
It seems like $post can also be of type array; however, wp_prepare_revisions_for_js() does only seem to accept object|integer, 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...
It seems like $revision_id can also be of type object<WP_Post>; however, wp_prepare_revisions_for_js() does only seem to accept integer, 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...
103
104
/* Revisions Help Tab */
105
106
$revisions_overview  = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
107
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
108
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
109
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
110
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.' ) . '</li>';
111
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
112
113
get_current_screen()->add_help_tab( array(
114
	'id'      => 'revisions-overview',
115
	'title'   => __( 'Overview' ),
116
	'content' => $revisions_overview
117
) );
118
119
$revisions_sidebar  = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
120
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
121
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>';
122
123
get_current_screen()->set_help_sidebar( $revisions_sidebar );
124
125
require_once( ABSPATH . 'wp-admin/admin-header.php' );
126
127
?>
128
129
<div class="wrap">
130
	<h1 class="long-header"><?php echo $h1; ?></h1>
131
	<?php echo $return_to_post; ?>
132
</div>
133
<?php
134
wp_print_revision_templates();
135
136
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
137