<?php namespace MailPoet\Form; if (!defined('ABSPATH')) exit; class ApiDataSanitizer { /** @var FormHtmlSanitizer */ private $htmlSanitizer; /** * List of blocks and their parameters that will be sanitized * @var string[][] */ private $htmlSanitizeConfig = [ 'paragraph' => [ 'content', ], 'heading' => [ 'content', ], 'image' => [ 'caption', ], 'checkbox' => [ 'values', ], ]; public function __construct( FormHtmlSanitizer $htmlSanitizer ) { $this->htmlSanitizer = $htmlSanitizer; } public function sanitizeBody(array $body): array { foreach ($body as $key => $block) { $sanitizedBlock = $this->sanitizeBlock($block); if (isset($sanitizedBlock['body']) && is_array($sanitizedBlock['body']) && !empty($sanitizedBlock['body'])) { $sanitizedBlock['body'] = $this->sanitizeBody($sanitizedBlock['body']); } $body[$key] = $sanitizedBlock; } return $body; } private function sanitizeBlock(array $block): array { if (!isset($this->htmlSanitizeConfig[$block['type']])) { return $block; } $params = $block['params'] ?? []; foreach ($this->htmlSanitizeConfig[$block['type']] as $parameter) { if (!isset($params[$parameter])) continue; if ($parameter === 'values' && is_array($params[$parameter])) { $params[$parameter] = $this->sanitizeValues($params[$parameter]); } else { $params[$parameter] = $this->htmlSanitizer->sanitize($params[$parameter]); } } $block['params'] = $params; return $block; } private function sanitizeValues(array $values) { foreach ($values as $key => $value) { if (!isset($value['value'])) continue; $values[$key]['value'] = $this->htmlSanitizer->sanitize($value['value']); } return $values; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Block | Folder | 0755 |
|
|
Listing | Folder | 0755 |
|
|
Templates | Folder | 0755 |
|
|
Util | Folder | 0755 |
|
|
ApiDataSanitizer.php | File | 1.82 KB | 0644 |
|
AssetsController.php | File | 3.38 KB | 0644 |
|
BlockStylesRenderer.php | File | 3.79 KB | 0644 |
|
BlockWrapperRenderer.php | File | 548 B | 0644 |
|
BlocksRenderer.php | File | 3.98 KB | 0644 |
|
DisplayFormInWPContent.php | File | 7.77 KB | 0644 |
|
FormFactory.php | File | 1.69 KB | 0644 |
|
FormHtmlSanitizer.php | File | 1.11 KB | 0644 |
|
FormMessageController.php | File | 1.61 KB | 0644 |
|
FormSaveController.php | File | 1021 B | 0644 |
|
FormsRepository.php | File | 2.52 KB | 0644 |
|
PreviewPage.php | File | 3.91 KB | 0644 |
|
PreviewWidget.php | File | 472 B | 0644 |
|
Renderer.php | File | 4.05 KB | 0644 |
|
Widget.php | File | 8.34 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|