Issues (1182)

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/wc-notice-functions.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
 * WooCommerce Message Functions
4
 *
5
 * Functions for error/message handling and display.
6
 *
7
 * @author 		WooThemes
8
 * @category 	Core
9
 * @package 	WooCommerce/Functions
10
 * @version     2.1.0
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit; // Exit if accessed directly
15
}
16
17
/**
18
 * Get the count of notices added, either for all notices (default) or for one.
19
 * particular notice type specified by $notice_type.
20
 *
21
 * @since 2.1
22
 * @param string $notice_type The name of the notice type - either error, success or notice. [optional]
23
 * @return int
24
 */
25
function wc_notice_count( $notice_type = '' ) {
26
	if ( ! did_action( 'woocommerce_init' ) ) {
27
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
28
		return;
29
	}
30
31
	$notice_count = 0;
32
	$all_notices  = WC()->session->get( 'wc_notices', array() );
33
34
	if ( isset( $all_notices[$notice_type] ) ) {
35
36
		$notice_count = absint( sizeof( $all_notices[$notice_type] ) );
37
38
	} elseif ( empty( $notice_type ) ) {
39
40
		foreach ( $all_notices as $notices ) {
0 ignored issues
show
The expression $all_notices of type array|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
41
			$notice_count += absint( sizeof( $all_notices ) );
42
		}
43
44
	}
45
46
	return $notice_count;
47
}
48
49
/**
50
 * Check if a notice has already been added.
51
 *
52
 * @since 2.1
53
 * @param string $message The text to display in the notice.
54
 * @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
55
 * @return bool
56
 */
57
function wc_has_notice( $message, $notice_type = 'success' ) {
58
	if ( ! did_action( 'woocommerce_init' ) ) {
59
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
60
		return false;
61
	}
62
63
	$notices = WC()->session->get( 'wc_notices', array() );
64
	$notices = isset( $notices[ $notice_type ] ) ? $notices[ $notice_type ] : array();
65
	return array_search( $message, $notices ) !== false;
66
}
67
68
/**
69
 * Add and store a notice.
70
 *
71
 * @since 2.1
72
 * @param string $message The text to display in the notice.
73
 * @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
74
 */
75
function wc_add_notice( $message, $notice_type = 'success' ) {
76
	if ( ! did_action( 'woocommerce_init' ) ) {
77
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
78
		return;
79
	}
80
81
	$notices = WC()->session->get( 'wc_notices', array() );
82
83
	// Backward compatibility
84
	if ( 'success' === $notice_type ) {
85
		$message = apply_filters( 'woocommerce_add_message', $message );
86
	}
87
88
	$notices[$notice_type][] = apply_filters( 'woocommerce_add_' . $notice_type, $message );
89
90
	WC()->session->set( 'wc_notices', $notices );
91
}
92
93
/**
94
 * Unset all notices.
95
 *
96
 * @since 2.1
97
 */
98 View Code Duplication
function wc_clear_notices() {
0 ignored issues
show
This function 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...
99
	if ( ! did_action( 'woocommerce_init' ) ) {
100
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
101
		return;
102
	}
103
	WC()->session->set( 'wc_notices', null );
104
}
105
106
/**
107
 * Prints messages and errors which are stored in the session, then clears them.
108
 *
109
 * @since 2.1
110
 */
111
function wc_print_notices() {
112
	if ( ! did_action( 'woocommerce_init' ) ) {
113
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
114
		return;
115
	}
116
117
	$all_notices  = WC()->session->get( 'wc_notices', array() );
118
	$notice_types = apply_filters( 'woocommerce_notice_types', array( 'error', 'success', 'notice' ) );
119
120
	foreach ( $notice_types as $notice_type ) {
121
		if ( wc_notice_count( $notice_type ) > 0 ) {
122
			wc_get_template( "notices/{$notice_type}.php", array(
123
				'messages' => array_filter( $all_notices[ $notice_type ] )
124
			) );
125
		}
126
	}
127
128
	wc_clear_notices();
129
}
130
add_action( 'woocommerce_shortcode_before_product_cat_loop', 'wc_print_notices', 10 );
131
add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
132
add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
133
134
/**
135
 * Print a single notice immediately.
136
 *
137
 * @since 2.1
138
 * @param string $message The text to display in the notice.
139
 * @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
140
 */
141
function wc_print_notice( $message, $notice_type = 'success' ) {
142
	if ( 'success' === $notice_type ) {
143
		$message = apply_filters( 'woocommerce_add_message', $message );
144
	}
145
146
	wc_get_template( "notices/{$notice_type}.php", array(
147
		'messages' => array( apply_filters( 'woocommerce_add_' . $notice_type, $message ) )
148
	) );
149
}
150
151
/**
152
 * Returns all queued notices, optionally filtered by a notice type.
153
 *
154
 * @since 2.1
155
 * @param string $notice_type The singular name of the notice type - either error, success or notice. [optional]
156
 * @return array|mixed
157
 */
158
function wc_get_notices( $notice_type = '' ) {
159
	if ( ! did_action( 'woocommerce_init' ) ) {
160
		_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
161
		return;
162
	}
163
164
	$all_notices = WC()->session->get( 'wc_notices', array() );
165
166
	if ( empty ( $notice_type ) ) {
167
		$notices = $all_notices;
168
	} elseif ( isset( $all_notices[$notice_type] ) ) {
169
		$notices = $all_notices[$notice_type];
170
	} else {
171
		$notices = array();
172
	}
173
174
	return $notices;
175
}
176
177
/**
178
 * Add notices for WP Errors.
179
 * @param  WP_Error $errors
180
 */
181
function wc_add_wp_error_notices( $errors ) {
182
	if ( is_wp_error( $errors ) && $errors->get_error_messages() ) {
183
		foreach ( $errors->get_error_messages() as $error ) {
184
			wc_add_notice( $error, 'error');
185
		}
186
	}
187
}
188