Skip to content
Snippets Groups Projects

Issue #3391461: Harden the use of unserialize in InlineBlock via allowed classes

Open Issue #3391461: Harden the use of unserialize in InlineBlock via allowed classes
2 unresolved threads
Open Lee Rowlands requested to merge issue/drupal-3391461:3391461-harden-the-use into 11.x
2 unresolved threads
Files
2
@@ -4,6 +4,7 @@
@@ -4,6 +4,7 @@
use Drupal\block_content\Access\RefinableDependentAccessInterface;
use Drupal\block_content\Access\RefinableDependentAccessInterface;
use Drupal\block_content\Access\RefinableDependentAccessTrait;
use Drupal\block_content\Access\RefinableDependentAccessTrait;
 
use Drupal\Component\Plugin\PluginBase;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockBase;
@@ -219,6 +220,20 @@ public function build() {
@@ -219,6 +220,20 @@ public function build() {
return $this->entityTypeManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
return $this->entityTypeManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
}
}
 
/**
 
* Return the unserialized version of the block_serialized configuration.
 
*
 
* @return mixed
 
* Result of unserialize() function.
 
*/
 
protected function getUnserializedBlock(): mixed {
 
$base_class = $this->entityTypeManager->getDefinition('block_content')->getClass();
 
[, $bundle] = explode(PluginBase::DERIVATIVE_SEPARATOR, $this->getPluginId());
 
$bundle_class = $this->entityTypeManager->getStorage('block_content')->getEntityClass($bundle);
 
 
return unserialize($this->configuration['block_serialized'], ['allowed_classes' => [$base_class, $bundle_class]]);
 
}
 
/**
/**
* Loads or creates the block content entity of the block.
* Loads or creates the block content entity of the block.
*
*
@@ -228,7 +243,7 @@ public function build() {
@@ -228,7 +243,7 @@ public function build() {
protected function getEntity() {
protected function getEntity() {
if (!isset($this->blockContent)) {
if (!isset($this->blockContent)) {
if (!empty($this->configuration['block_serialized'])) {
if (!empty($this->configuration['block_serialized'])) {
$this->blockContent = unserialize($this->configuration['block_serialized']);
$this->blockContent = $this->getUnserializedBlock();
}
}
elseif (!empty($this->configuration['block_revision_id'])) {
elseif (!empty($this->configuration['block_revision_id'])) {
$entity = $this->entityTypeManager->getStorage('block_content')->loadRevision($this->configuration['block_revision_id']);
$entity = $this->entityTypeManager->getStorage('block_content')->loadRevision($this->configuration['block_revision_id']);
@@ -272,7 +287,7 @@ public function saveBlockContent($new_revision = FALSE, $duplicate_block = FALSE
@@ -272,7 +287,7 @@ public function saveBlockContent($new_revision = FALSE, $duplicate_block = FALSE
/** @var \Drupal\block_content\BlockContentInterface $block */
/** @var \Drupal\block_content\BlockContentInterface $block */
$block = NULL;
$block = NULL;
if (!empty($this->configuration['block_serialized'])) {
if (!empty($this->configuration['block_serialized'])) {
$block = unserialize($this->configuration['block_serialized']);
$block = $this->getUnserializedBlock();
}
}
if ($duplicate_block) {
if ($duplicate_block) {
if (empty($block) && !empty($this->configuration['block_revision_id'])) {
if (empty($block) && !empty($this->configuration['block_revision_id'])) {
Loading