PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Http / Requests / BulkUpdateVariantRequest.php

BulkUpdateVariantRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Http/Requests/BulkUpdateVariantRequest.php

51 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Requests;
4
5 use FluentCart\Framework\Foundation\RequestGuard;
6
7 class BulkUpdateVariantRequest extends RequestGuard
8 {
9 /**
10 * Hard cap on the number of variant rows a single bulk-update call may
11 * modify. Matches AdvancedVariationService::DEFAULT_MAX_COMBINATIONS so a
12 * caller cannot use the bulk endpoint to write more rows than the editor
13 * can generate in the first place. Without this, an unauthenticated-yet-
14 * capability-holding attacker could POST a 100K-element array and burn
15 * memory + CPU even when every row eventually fails per-row sanitization.
16 */
17 const MAX_UPDATES_PER_REQUEST = 500;
18
19 public function rules()
20 {
21 return [
22 'updates' => 'required|array',
23 ];
24 }
25
26 public function messages()
27 {
28 return [
29 'updates.required' => esc_html__('At least one variant update is required.', 'fluent-cart'),
30 'updates.array' => esc_html__('Updates payload must be an array.', 'fluent-cart'),
31 ];
32 }
33
34 public function sanitize()
35 {
36 return [
37 // Per-row sanitization (id cast, price->cents, allowlist statuses) lives
38 // in ProductVariationController::bulkUpdate where the conditional shape
39 // logic belongs. This sanitize() only caps the outer array size — the
40 // hard guard against the attack surface where a caller floods the
41 // endpoint with millions of rows before any per-row check fires.
42 'updates' => function ($value) {
43 if (!is_array($value)) {
44 return [];
45 }
46 return array_slice($value, 0, self::MAX_UPDATES_PER_REQUEST);
47 },
48 ];
49 }
50 }
51