NodeTitleXSSTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/NodeTitleXSSTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Component\Utility\Html;
class NodeTitleXSSTest extends NodeTestBase {
protected $defaultTheme = 'stark';
public function testNodeTitleXSS() {
$web_user = $this
->drupalCreateUser([
'create page content',
'edit any page content',
]);
$this
->drupalLogin($web_user);
$xss = '<script>alert("xss")</script>';
$title = $xss . $this
->randomMachineName();
$edit = [];
$edit['title[0][value]'] = $title;
$this
->drupalGet('node/add/page');
$this
->submitForm($edit, 'Preview');
$this
->assertSession()
->responseNotContains($xss);
$settings = [
'title' => $title,
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains('<title>' . Html::escape($title) . ' | Drupal</title>');
$this
->assertSession()
->responseNotContains($xss);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->responseNotContains($xss);
}
}
Classes
Name |
Description |
NodeTitleXSSTest |
Create a node with dangerous tags in its title and test that they are
escaped. |