Issues (234)

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/admin/notices.php (4 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
 * Admin notices
4
 *
5
 * @package SimpleCalendar/Admin
6
 */
7
namespace SimpleCalendar\Admin;
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
/**
14
 * Admin notices class.
15
 *
16
 * Handles and displays notices in admin dashboard pages.
17
 *
18
 * @since 3.0.0
19
 */
20
class Notices {
21
22
	/**
23
	 * Get notices.
24
	 *
25
	 * @since 3.0.0
26
	 */
27
	public function __construct() {
28
		add_action( 'admin_init', array( $this, 'remove_notice' ), 10 );
29
		add_action( 'admin_init', array( $this, 'process_notices' ), 40 );
30
	}
31
32
	/**
33
	 * Process notices.
34
	 *
35
	 * @since 3.0.0
36
	 */
37
	public function process_notices() {
0 ignored issues
show
process_notices uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
38
39
		$notices = $this->get_notices();
40
41
		if ( ! empty( $notices ) && is_array( $notices ) ) {
42
43
			foreach ( $notices as $group ) {
44
				foreach ( $group as $notice ) {
45
46
					if ( $notice instanceof Notice ) {
47
48
						if ( $notice->visible === false ) {
49
							continue;
50
						}
51
52
						if ( ! empty( $notice->capability ) ) {
53
							if ( ! current_user_can( $notice->capability ) ) {
54
								continue;
55
							}
56
						}
57
58
						if ( ! empty( $notice->screen ) && is_array( $notice->screen ) && function_exists( 'get_current_screen' ) ) {
59
							$screen = get_current_screen();
60
							if ( isset( $screen->id ) ) {
61
								if ( ! in_array( $screen->id, $notice->screen ) ) {
62
									continue;
63
								}
64
							}
65
						}
66
67
						if ( ! empty( $notice->post ) && is_array( $notice->post ) ) {
68
							if ( isset( $_GET['post'] ) ) {
69
								if ( ! in_array( intval( $_GET['post'] ), $notice->post ) ) {
70
									continue;
71
								}
72
							} else {
73
								continue;
74
							}
75
						}
76
77
						$this->add_notice( $notice );
78
					}
79
				}
80
			}
81
		}
82
	}
83
84
	/**
85
	 * Add notice.
86
	 *
87
	 * @TODO Improve notice dismissal with ajax.
88
	 *
89
	 * @since  3.0.0
90
	 *
91
	 * @param  Notice $notice
92
	 *
93
	 * @return void
94
	 */
95
	public function add_notice( $notice ) {
96
97
		if ( $notice instanceof Notice ) {
98
99
			add_action( 'admin_notices', $print_notice = function() use ( $notice ) {
100
101
				$name         = is_array( $notice->id ) ? key( $notice->id ) : $notice->id;
102
				$url          = add_query_arg( array( 'dismiss_simcal_notice' => $name ) );
103
				$dismiss_link = $notice->dismissible === true
104
					? sprintf( '<a class="dashicons-before dashicons-dismiss simcal-dismiss-notice" href="%1$s"></a>', $url )
105
					: '';
106
107
				echo '<div class="' . $notice->type . ' ' . $notice->class . ' simcal-admin-notice" data-notice-id="' . $name . '">' . $dismiss_link . $notice->content . '</div>';
108
			} );
109
110
		}
111
	}
112
113
	/**
114
	 * Dismiss a notice.
115
	 *
116
	 * @TODO  Improve notice dismissal with ajax.
117
	 *
118
	 * @since  3.0.0
119
	 *
120
	 * @param  string $notice (optional) The notice id.
121
	 *
122
	 * @return void
123
	 */
124
	public function remove_notice( $notice = '' ) {
0 ignored issues
show
remove_notice uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
125
126
		$notices = $this->get_notices();
127
		$update = false;
128
129
		if ( ! empty( $notice ) ) {
130
			if ( isset( $notices[ $notice ] ) ) {
131
				unset( $notices[ $notice ] );
132
				$update = true;
133
			}
134
		}
135
136
		if ( isset( $_GET['dismiss_simcal_notice'] ) ) {
137
			if ( isset( $notices[ $_GET['dismiss_simcal_notice'] ] ) ) {
138
				unset( $notices[ esc_attr( $_GET['dismiss_simcal_notice'] ) ] );
139
				$update = true;
140
			}
141
		}
142
143
		if ( $update === true ) {
144
			update_option( 'simple-calendar_admin_notices', $notices );
145
		}
146
	}
147
148
	/**
149
	 * Show a notice.
150
	 *
151
	 * @since 3.0.0
152
	 *
153
	 * @param  string $notice
154
	 *
155
	 * @return void
156
	 */
157 View Code Duplication
	public function show_notice( $notice ) {
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...
158
159
		$notices = $this->get_notices();
160
161
		if ( isset( $notices[ $notice ]->visible ) ) {
162
			$notices[ $notice ]->visible = true;
163
			update_option( 'simple-calendar_admin_notices', $notices );
164
		}
165
	}
166
167
	/**
168
	 * Hide a notice.
169
	 *
170
	 * @since  3.0.0
171
	 *
172
	 * @param  string $notice
173
	 *
174
	 * @return void
175
	 */
176 View Code Duplication
	public function hide_notice( $notice ) {
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...
177
178
		$notices = $this->get_notices();
179
180
		if ( isset( $notices[ $notice ]->visible ) ) {
181
			$notices[ $notice ]->visible = false;
182
			update_option( 'simple-calendar_admin_notices', $notices );
183
		}
184
	}
185
186
	/**
187
	 * Get current notices.
188
	 *
189
	 * @since  3.0.0
190
	 *
191
	 * @return array
192
	 */
193
	public function get_notices() {
194
		return apply_filters(
195
			'simcal_admin_notices',
196
			get_option( 'simple-calendar_admin_notices', array() )
197
		);
198
	}
199
200
}
201