Issues (124)

Security Analysis    not enabled

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.

lib/WebDriver/WebDriver.php (3 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 Magium\WebDriver;
4
5
use Facebook\WebDriver\Exception\WebDriverException;
6
use Facebook\WebDriver\Remote\DriverCommand;
7
use Facebook\WebDriver\Remote\HttpCommandExecutor;
8
use Facebook\WebDriver\Remote\RemoteWebDriver;
9
use Facebook\WebDriver\Remote\WebDriverCommand;
10
use Facebook\WebDriver\WebDriverBy;
11
use Facebook\WebDriver\WebDriverCommandExecutor;
12
use Facebook\WebDriver\WebDriverElement;
13
use Magium\Util\Log\LoggerAware;
14
use Magium\Util\Log\LoggerInterface;
15
16
17
class WebDriver extends RemoteWebDriver implements LoggerAware
18
{
19
    const INSTRUCTION_MOUSE_MOVETO = 'mouseMoveTo';
20
    const INSTRUCTION_MOUSE_CLICK  = 'mouseClick';
21
22
    const BY_XPATH = 'byXpath';
23
    const BY_ID    = 'byId';
24
    const BY_CSS_SELECTOR = 'byCssSelector';
25
26
    /**
27
     * @var \Magium\Util\Log\LoggerInterface
28
     */
29
30
    protected $logger;
31
32
    protected $browser;
33
    protected $platform;
34
35
    /**
36
     * @return mixed
37
     */
38
    public function getBrowser()
39
    {
40
        return $this->browser;
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46
    public function getPlatform()
47
    {
48
        return $this->platform;
49
    }
50
51
    public function setCommandExecutor(WebDriverCommandExecutor $executor)
52
    {
53
        $command = new WebDriverCommand($this->getSessionID(), DriverCommand::GET_CAPABILITIES, []);
54
        $result = $executor->execute($command);
55
        $values = $result->getValue();
56
        $this->browser = $values['browserName'];
57
        $this->platform = $values['platform'];
58
        return parent::setCommandExecutor($executor);
0 ignored issues
show
Deprecated Code introduced by
The method Facebook\WebDriver\Remot...r::setCommandExecutor() has been deprecated with message: To be removed in the future. Executor should be passed in the constructor.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
59
    }
60
61
62
    public function logFind($by, $selector)
63
    {
64
        if ($this->logger instanceof \Magium\Util\Log\LoggerInterface) {
65
            $this->logger->debug(
66
                sprintf(
67
                    'By: %s %s',
68
                    $by,
69
                    $selector
70
                ),
71
                [
72
                    'type' => 'webdriver-activity',
73
                    'activity'  => 'select',
74
                    'by'        => $by,
75
                    'selector'  => $selector
76
                ]
77
            );
78
        }
79
    }
80
81
    public function logElement(WebDriverElement $element)
82
    {
83
        if ($this->logger instanceof LoggerInterface) {
84
            $this->logger->debug(
85
                sprintf(
86
                    'Returned element: %s ID: %s',
87
                    get_class($element),
88
                    $element->getID()
89
                ),
90
                [
91
                    'type'      => 'webdriver-activity',
92
                    'activity'  => 'element-return',
93
                    'class'      => get_class($element),
94
                    'id'        => $element->getID()
95
                ]
96
            );
97
        }
98
    }
99
100
    public function setRemoteExecuteMethod(LoggingRemoteExecuteMethod $method)
101
    {
102
        $this->executeMethod = $method;
103
    }
104
105
    public function setLogger(LoggerInterface $logger)
106
    {
107
        $this->logger = $logger;
108
    }
109
110
    /**
111
     * @param WebDriverBy $by
112
     * @return \Facebook\WebDriver\Remote\RemoteWebElement[]
113
     */
114
115 View Code Duplication
    public function findElements(WebDriverBy $by)
0 ignored issues
show
This method seems to be duplicated in 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...
116
    {
117
        $this->logFind($by->getMechanism(), $by->getValue());
118
        $elements = parent::findElements($by);
119
        foreach ($elements as $element) {
120
            $this->logElement($element);
121
        }
122
        return $elements;
123
    }
124
125
    /**
126
     * @param WebDriverBy $by
127
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
128
     */
129
130 View Code Duplication
    public function findElement(WebDriverBy $by)
0 ignored issues
show
This method seems to be duplicated in 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...
131
    {
132
        $this->logFind($by->getMechanism(), $by->getValue());
133
        $element = parent::findElement($by);
134
        $this->logElement($element);
135
        return $element;
136
    }
137
138
    public function elementExists($selector, $by = 'byId')
139
    {
140
        try {
141
            $this->$by($selector);
142
            return true;
143
        } catch (\Exception $e) {
144
            return false;
145
        }
146
    }
147
148
    public function elementAttached(WebDriverElement $element)
149
    {
150
        try {
151
            $element->isDisplayed();
152
            return true;
153
        } catch (\Exception $e) {
154
            return false;
155
        }
156
    }
157
158
    public function elementDisplayed($selector, $by = 'byId')
159
    {
160
        try {
161
            $element = $this->$by($selector);
162
            return $element->isDisplayed();
163
        } catch (\Exception $e) {
164
            return false;
165
        }
166
    }
167
168
    /**
169
     * 
170
     * @param string $xpath
171
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
172
     */
173
    
174
    public function byXpath($xpath)
175
    {
176
        return $this->findElement(WebDriverBy::xpath($xpath));
177
    }
178
    
179
    /**
180
     * 
181
     * @param string $id
182
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
183
     */
184
    
185
    public function byId($id)
186
    {
187
        return $this->findElement(WebDriverBy::id($id));
188
    }
189
    
190
    /**
191
     * 
192
     * @param string $selector
193
     * @return \Facebook\WebDriver\Remote\RemoteWebElement
194
     */
195
    
196
    public function byCssSelector($selector)
197
    {
198
        return $this->findElement(WebDriverBy::cssSelector($selector));
199
    }
200
    
201
    public function __destruct()
202
    {
203
        try {
204
            if ($this->getCommandExecutor() instanceof HttpCommandExecutor) {
205
                $this->quit();
206
            }
207
        } catch (WebDriverException $e) {
208
            // Not a problem.  It just means that the WebDriver session was closed somewhere else
209
        }
210
    }
211
212
}
213