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/abstracts/abstract-wc-rest-controller.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
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
/**
8
 * Abstract Rest Controler Class
9
 *
10
 * @author   WooThemes
11
 * @category API
12
 * @package  WooCommerce/Abstracts
13
 * @extends  WP_REST_Controller
14
 * @version  2.6.0
15
 */
16
abstract class WC_REST_Controller extends WP_REST_Controller {
17
18
	/**
19
	 * Endpoint namespace.
20
	 *
21
	 * @var string
22
	 */
23
	protected $namespace = 'wc/v1';
24
25
	/**
26
	 * Route base.
27
	 *
28
	 * @var string
29
	 */
30
	protected $rest_base = '';
31
32
	/**
33
	 * Add the schema from additional fields to an schema array.
34
	 *
35
	 * The type of object is inferred from the passed schema.
36
	 *
37
	 * @param array $schema Schema array.
38
	 */
39
	protected function add_additional_fields_schema( $schema ) {
40
		if ( empty( $schema['title'] ) ) {
41
			return $schema;
42
		}
43
44
		/**
45
		 * Can't use $this->get_object_type otherwise we cause an inf loop.
46
		 */
47
		$object_type = $schema['title'];
48
49
		$additional_fields = $this->get_additional_fields( $object_type );
50
51 View Code Duplication
		foreach ( $additional_fields as $field_name => $field_options ) {
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...
52
			if ( ! $field_options['schema'] ) {
53
				continue;
54
			}
55
56
			$schema['properties'][ $field_name ] = $field_options['schema'];
57
		}
58
59
		$schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] );
60
61
		return $schema;
62
	}
63
64
	/**
65
	 * Get normalized rest base.
66
	 *
67
	 * @return string
68
	 */
69
	protected function get_normalized_rest_base() {
70
		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
71
	}
72
73
	/**
74
	 * Check batch limit.
75
	 *
76
	 * @param array $items Request items.
77
	 * @return bool|WP_Error
78
	 */
79
	protected function check_batch_limit( $items ) {
80
		$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
81
		$total = 0;
82
83
		if ( ! empty( $items['create'] ) ) {
84
			$total += count( $items['create'] );
85
		}
86
87
		if ( ! empty( $items['update'] ) ) {
88
			$total += count( $items['update'] );
89
		}
90
91
		if ( ! empty( $items['delete'] ) ) {
92
			$total += count( $items['delete'] );
93
		}
94
95
		if ( $total > $limit ) {
96
			return new WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
97
		}
98
99
		return true;
100
	}
101
102
	/**
103
	 * Bulk create, update and delete items.
104
	 *
105
	 * @param WP_REST_Request $request Full details about the request.
106
	 * @return array Of WP_Error or WP_REST_Response.
107
	 */
108
	public function batch_items( $request ) {
109
		/** @var WP_REST_Server $wp_rest_server */
110
		global $wp_rest_server;
111
112
		// Get the request params.
113
		$items    = array_filter( $request->get_params() );
114
		$response = array();
115
116
		// Check batch limit.
117
		$limit = $this->check_batch_limit( $items );
118
		if ( is_wp_error( $limit ) ) {
119
			return $limit;
120
		}
121
122
		if ( ! empty( $items['create'] ) ) {
123
			foreach ( $items['create'] as $item ) {
124
				$_item = new WP_REST_Request( 'POST' );
125
126
				// Default parameters.
127
				$defaults = array();
128
				$schema   = $this->get_public_item_schema();
129
				foreach ( $schema['properties'] as $arg => $options ) {
130
					if ( isset( $options['default'] ) ) {
131
						$defaults[ $arg ] = $options['default'];
132
					}
133
				}
134
				$_item->set_default_params( $defaults );
135
136
				// Set request parameters.
137
				$_item->set_body_params( $item );
138
				$_response = $this->create_item( $_item );
139
140
				if ( is_wp_error( $_response ) ) {
141
					$response['create'][] = array(
142
						'id'    => 0,
143
						'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
144
					);
145
				} else {
146
					$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
147
				}
148
			}
149
		}
150
151 View Code Duplication
		if ( ! empty( $items['update'] ) ) {
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...
152
			foreach ( $items['update'] as $item ) {
153
				$_item = new WP_REST_Request( 'PUT' );
154
				$_item->set_body_params( $item );
155
				$_response = $this->update_item( $_item );
156
157
				if ( is_wp_error( $_response ) ) {
158
					$response['update'][] = array(
159
						'id'    => $item['id'],
160
						'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
161
					);
162
				} else {
163
					$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
164
				}
165
			}
166
		}
167
168 View Code Duplication
		if ( ! empty( $items['delete'] ) ) {
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...
169
			foreach ( $items['delete'] as $id ) {
170
				$_item = new WP_REST_Request( 'DELETE' );
171
				$_item->set_query_params( array( 'id' => $id, 'force' => true ) );
172
				$_response = $this->delete_item( $_item );
173
174
				if ( is_wp_error( $_response ) ) {
175
					$response['delete'][] = array(
176
						'id'    => $id,
177
						'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
178
					);
179
				} else {
180
					$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
181
				}
182
			}
183
		}
184
185
		return $response;
186
	}
187
188
	/**
189
	 * Get the batch schema, conforming to JSON Schema.
190
	 *
191
	 * @return array
192
	 */
193
	public function get_public_batch_schema() {
194
		$schema = array(
195
			'$schema'    => 'http://json-schema.org/draft-04/schema#',
196
			'title'      => 'batch',
197
			'type'       => 'object',
198
			'properties' => array(
199
				'create' => array(
200
					'description' => __( 'List of created resources.', 'woocommerce' ),
201
					'type'        => 'array',
202
					'context'     => array( 'view', 'edit' ),
203
				),
204
				'update' => array(
205
					'description' => __( 'List of updated resources.', 'woocommerce' ),
206
					'type'        => 'array',
207
					'context'     => array( 'view', 'edit' ),
208
				),
209
				'delete' => array(
210
					'description' => __( 'List of delete resources.', 'woocommerce' ),
211
					'type'        => 'array',
212
					'context'     => array( 'view', 'edit' ),
213
				),
214
			),
215
		);
216
217
		return $schema;
218
	}
219
}
220