Issues (31)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Tests/EntityEmbedDialogTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Drupal\entity_embed\Tests;
4
5
use Drupal\editor\Entity\Editor;
6
7
/**
8
 * Tests the entity_embed dialog controller and route.
9
 *
10
 * @group entity_embed
11
 */
12
class EntityEmbedDialogTest extends EntityEmbedTestBase {
13
14
  /**
15
   * Modules to enable.
16
   *
17
   * @var array
18
   */
19
  public static $modules = ['image'];
20
21
  /**
22
   * Tests the entity embed dialog.
23
   */
24
  public function testEntityEmbedDialog() {
25
    // Ensure that the route is not accessible without specifying all the
26
    // parameters.
27
    $this->getEmbedDialog();
28
    $this->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');
29
    $this->getEmbedDialog('custom_format');
30
    $this->assertResponse(404, 'Embed dialog is not accessible without specifying embed button.');
31
32
    // Ensure that the route is not accessible with an invalid embed button.
33
    $this->getEmbedDialog('custom_format', 'invalid_button');
34
    $this->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');
35
36
    // Ensure that the route is not accessible with text format without the
37
    // button configured.
38
    $this->getEmbedDialog('plain_text', 'node');
39
    $this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');
40
41
    // Add an empty configuration for the plain_text editor configuration.
42
    $editor = Editor::create([
43
      'format' => 'plain_text',
44
      'editor' => 'ckeditor',
45
    ]);
46
    $editor->save();
47
    $this->getEmbedDialog('plain_text', 'node');
48
    $this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');
49
50
    // Ensure that the route is accessible with a valid embed button.
51
    // 'Node' embed button is provided by default by the module and hence the
52
    // request must be successful.
53
    $this->getEmbedDialog('custom_format', 'node');
54
    $this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
55
56
    // Ensure form structure of the 'select' step and submit form.
57
    $this->assertFieldByName('entity_id', '', 'Entity ID/UUID field is present.');
58
59
    // $edit = ['attributes[data-entity-id]' => $this->node->id()];
60
    // $this->drupalPostAjaxForm(NULL, $edit, 'op');
61
    // Ensure form structure of the 'embed' step and submit form.
62
    // $this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');.
63
  }
64
65
  /**
66
   * Tests the entity embed button markup.
67
   */
68
  public function testEntityEmbedButtonMarkup() {
69
    // Ensure that the route is not accessible with text format without the
70
    // button configured.
71
    $this->getEmbedDialog('plain_text', 'node');
72
    $this->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');
73
74
    // Add an empty configuration for the plain_text editor configuration.
75
    $editor = Editor::create([
76
      'format' => 'plain_text',
77
      'editor' => 'ckeditor',
78
    ]);
79
    $editor->save();
80
    $this->getEmbedDialog('plain_text', 'node');
81
    $this->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');
82
83
    // Ensure that the route is accessible with a valid embed button.
84
    // 'Node' embed button is provided by default by the module and hence the
85
    // request must be successful.
86
    $this->getEmbedDialog('custom_format', 'node');
87
    $this->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
88
89
    // Ensure form structure of the 'select' step and submit form.
90
    $this->assertFieldByName('entity_id', '', 'Entity ID/UUID field is present.');
91
92
    // Check that 'Next' is a primary button.
93
    $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Next', 'Next is a primary button');
94
95
    $title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
96
    $edit = ['entity_id' => $title];
97
    $response = $this->drupalPostAjaxForm(NULL, $edit, 'op');
98
    $plugins = [
99
      'entity_reference:entity_reference_label',
100
      'entity_reference:entity_reference_entity_id',
101
      'view_mode:node.full',
102
      'view_mode:node.rss',
103
      'view_mode:node.search_index',
104
      'view_mode:node.search_result',
105
      'view_mode:node.teaser',
106
    ];
107 View Code Duplication
    foreach ($plugins as $plugin) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
      $this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.');
109
    }
110
111
    $this->container->get('config.factory')->getEditable('entity_embed.settings')
112
      ->set('rendered_entity_mode', TRUE)->save();
113
    $this->container->get('plugin.manager.entity_embed.display')->clearCachedDefinitions();
114
115
    $this->getEmbedDialog('custom_format', 'node');
116
    $title = $this->node->getTitle() . ' (' . $this->node->id() . ')';
117
    $edit = ['entity_id' => $title];
118
    $response = $this->drupalPostAjaxForm(NULL, $edit, 'op');
119
120
    $plugins = [
121
      'entity_reference:entity_reference_label',
122
      'entity_reference:entity_reference_entity_id',
123
      'entity_reference:entity_reference_entity_view',
124
    ];
125 View Code Duplication
    foreach ($plugins as $plugin) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
      $this->assertTrue(strpos($response[2]['data'], $plugin), 'Plugin ' . $plugin . ' is available in selection.');
127
    }
128
    /*$this->drupalPostForm(NULL, $edit, 'Next');
129
    // Ensure form structure of the 'embed' step and submit form.
130
    $this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');
131
132
    // Check that 'Embed' is a primary button.
133
    $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/
134
  }
135
136
  /**
137
   * Tests entity embed functionality.
138
   */
139
  public function testEntityEmbedFunctionality() {
140
    $edit = [
141
      'entity_id' => $this->node->getTitle() . ' (' . $this->node->id() . ')',
142
    ];
143
    $this->getEmbedDialog('custom_format', 'node');
144
    $this->drupalPostForm(NULL, $edit, t('Next'));
145
    // Tests that the embed dialog doesn't trow a fatal in
146
    // ImageFieldFormatter::isValidImage()
147
    $this->assertResponse(200);
148
  }
149
150
  /**
151
   * Retrieves an embed dialog based on given parameters.
152
   *
153
   * @param string $filter_format_id
154
   *   ID of the filter format.
155
   * @param string $embed_button_id
156
   *   ID of the embed button.
157
   *
158
   * @return string
159
   *   The retrieved HTML string.
160
   */
161
  public function getEmbedDialog($filter_format_id = NULL, $embed_button_id = NULL) {
162
    $url = 'entity-embed/dialog';
163
    if (!empty($filter_format_id)) {
164
      $url .= '/' . $filter_format_id;
165
      if (!empty($embed_button_id)) {
166
        $url .= '/' . $embed_button_id;
167
      }
168
    }
169
    return $this->drupalGet($url);
170
  }
171
172
}
173