Issues (20)

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/Context/RawPageContext.php (1 issue)

Labels
Severity

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
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Context;
6
7
// Contexts.
8
use Drupal\DrupalExtension\Context\RawDrupalContext;
9
// Exceptions.
10
use WebDriver\Exception\NoSuchElement;
11
// Helpers.
12
use Behat\Mink\Element\NodeElement;
13
// Utils.
14
use Drupal\TqExtension\Utils\XPath;
15
16
class RawPageContext extends RawDrupalContext
17
{
18
    /**
19
     * @var NodeElement
20
     */
21
    private static $workingElement;
22
23
    /**
24
     * @return NodeElement
25
     */
26
    public function getWorkingElement()
27
    {
28
        if (null === self::$workingElement) {
29
            $this->setWorkingElement($this->getBodyElement());
0 ignored issues
show
It seems like $this->getBodyElement() can be null; however, setWorkingElement() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
30
        }
31
32
        return self::$workingElement;
33
    }
34
35
    /**
36
     * @param NodeElement $element
37
     */
38
    public function setWorkingElement(NodeElement $element)
39
    {
40
        self::$workingElement = $element;
41
    }
42
43
    public function unsetWorkingElement()
44
    {
45
        self::$workingElement = null;
46
    }
47
48
    /**
49
     * @param string $selector
50
     *
51
     * @return NodeElement
52
     */
53
    public function findByCss($selector)
54
    {
55
        return $this->getWorkingElement()
56
            ->find(empty($this->getDrupalParameter('region_map')[$selector]) ? 'css' : 'region', $selector);
57
    }
58
59
    /**
60
     * @param string $selector
61
     *
62
     * @return NodeElement|null
63
     */
64
    public function findField($selector)
65
    {
66
        $selector = ltrim($selector, '#');
67
        $element = $this->getWorkingElement();
68
69
        foreach ($this->findLabels($selector) as $forAttribute => $label) {
70
            // We trying to find an ID with "-upload" suffix, because some
71
            // image inputs in Drupal are suffixed by it.
72
            foreach ([$forAttribute, "$forAttribute-upload"] as $elementID) {
73
                $field = $element->findById($elementID);
74
75
                if (null !== $field) {
76
                    return $field;
77
                }
78
            }
79
        }
80
81
        return $element->findField($selector);
82
    }
83
84
    /**
85
     * @param string $selector
86
     *
87
     * @return NodeElement
88
     */
89
    public function findButton($selector)
90
    {
91
        $element = $this->getWorkingElement();
92
93
        // Search inside of: "id", "name", "title", "alt" and "value" attributes.
94
        return $element->findButton($selector)
95
            ?: (new XPath\InaccurateText('//button', $element))->text($selector)->find();
96
    }
97
98
    /**
99
     * @param string $text
100
     *
101
     * @return NodeElement|null
102
     */
103
    public function findByText($text)
104
    {
105
        return (new XPath\InaccurateText('//*', $this->getWorkingElement()))->text($text)->find();
106
    }
107
108
    /**
109
     * @param string $locator
110
     *   Element locator. Can be inaccurate text, inaccurate field label, CSS selector or region name.
111
     *
112
     * @throws NoSuchElement
113
     *
114
     * @return NodeElement
115
     */
116
    public function findElement($locator)
117
    {
118
        return $this->findByCss($locator)
119
            ?: $this->findField($locator)
120
                ?: $this->findButton($locator)
121
                    ?: $this->findByText($locator);
122
    }
123
124
    /**
125
     * Find all field labels by text.
126
     *
127
     * @param string $text
128
     *   Label text.
129
     *
130
     * @return NodeElement[]
131
     */
132
    public function findLabels($text)
133
    {
134
        $xpath = new XPath\InaccurateText('//label[@for]', $this->getWorkingElement());
135
        $labels = [];
136
137
        foreach ($xpath->text($text)->findAll() as $label) {
138
            $labels[$label->getAttribute('for')] = $label;
139
        }
140
141
        return $labels;
142
    }
143
144
    /**
145
     * @return NodeElement
146
     */
147
    public function getBodyElement()
148
    {
149
        return $this->getSession()->getPage()->find('css', 'body');
150
    }
151
152
    /**
153
     * @param string $selector
154
     *   Element selector.
155
     * @param mixed $element
156
     *   Existing element or null.
157
     *
158
     * @throws NoSuchElement
159
     */
160
    public function throwNoSuchElementException($selector, $element)
161
    {
162
        if (null === $element) {
163
            throw new NoSuchElement(sprintf('Cannot find an element by "%s" selector.', $selector));
164
        }
165
    }
166
167
    /**
168
     * @param string $locator
169
     * @param string $selector
170
     *
171
     * @throws \RuntimeException
172
     * @throws NoSuchElement
173
     *
174
     * @return NodeElement
175
     */
176
    public function element($locator, $selector)
177
    {
178
        $map = [
179
            'button' => 'Button',
180
            'field' => 'Field',
181
            'text' => 'ByText',
182
            'css' => 'ByCss',
183
            '*' => 'Element',
184
        ];
185
186
        if (!isset($map[$locator])) {
187
            throw new \RuntimeException(sprintf('Locator "%s" was not specified.'));
188
        }
189
190
        $selector = t($selector);
191
        $element = $this->{'find' . $map[$locator]}($selector);
192
        $this->throwNoSuchElementException($selector, $element);
193
194
        return $element;
195
    }
196
}
197