TestXssBlock.php

Same filename and directory in other branches
  1. 11.x core/modules/block/tests/modules/block_test/src/Plugin/Block/TestXssBlock.php

Namespace

Drupal\block_test\Plugin\Block

File

core/modules/block/tests/modules/block_test/src/Plugin/Block/TestXssBlock.php

View source
<?php

declare (strict_types=1);
namespace Drupal\block_test\Plugin\Block;

use Drupal\Component\Utility\Html;
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Render\Markup;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides a block containing an XSS payload.
 */
class TestXssBlock extends BlockBase {
  
  /**
   * {@inheritdoc}
   */
  public function build() : array {
    $payload = '<img src=x onerror="window.XSS = true;">';
    return [
      '#markup' => Markup::create('<input class="block-filter-text" data-element="' . Html::escape($payload) . '">'),
    ];
  }

}

Classes

Title Deprecated Summary
TestXssBlock Provides a block containing an XSS payload.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.