Issues (39)

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/FormManipulationTrait.php (14 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 Zumba\Mink\Driver;
4
5
use Behat\Mink\Exception\DriverException;
6
7
/**
8
 * Trait FormManipulationTrait
9
 * @package Zumba\Mink\Driver
10
 */
11
trait FormManipulationTrait {
12
13
14
  /**
15
   * Returns the value of a given xpath element
16
   * @param string $xpath
17
   * @return string
18
   * @throws DriverException
19
   */
20
  public function getValue($xpath) {
21
    $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
22
    $javascript = $this->javascriptTemplateRender("get_value.js.twig", array("xpath" => $xpath));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
23
    return $this->browser->evaluate($javascript);
0 ignored issues
show
The property browser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
  }
25
26
  /**
27
   * @param string $xpath
28
   * @param string $value
29
   * @throws DriverException
30
   */
31
  public function setValue($xpath, $value) {
32
    $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
    //This stuff is BECAUSE the way the driver works for setting values when being checkboxes, radios, etc.
34
    if (is_bool($value)) {
35
      $value = $this->boolToString($value);
36
    } elseif (is_numeric($value)) {
37
      $value = (string) $value;
38
    }
39
40
    $javascript = $this->javascriptTemplateRender("set_value.js.twig", array("xpath" => $xpath, "value" => json_encode($value)));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
41
    $this->browser->evaluate($javascript);
42
  }
43
44
45
  /**
46
   * Submits a form given an xpath selector
47
   * @param string $xpath
48
   * @throws DriverException
49
   */
50
  public function submitForm($xpath) {
51
    $element = $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
    $tagName = $this->browser->tagName($element["page_id"], $element["ids"][0]);
53
    if (strcmp(strtolower($tagName), "form") !== 0) {
54
      throw new DriverException("Can not submit something that is not a form");
55
    }
56
    $this->browser->trigger($element["page_id"], $element["ids"][0], "submit");
57
  }
58
59
  /**
60
   * Helper method needed for twig and javascript stuff
61
   * @param $boolValue
62
   * @return string
63
   */
64
  protected function boolToString($boolValue) {
65
    if ($boolValue === true) {
66
      return "1";
67
    }
68
    return "0";
69
  }
70
71
  /**
72
   * Selects an option
73
   * @param string $xpath
74
   * @param string $value
75
   * @param bool   $multiple
76
   * @return bool
77
   * @throws DriverException
78
   */
79
  public function selectOption($xpath, $value, $multiple = false) {
80
    $element = $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
81
    $tagName = strtolower($this->browser->tagName($element["page_id"], $element["ids"][0]));
82
    $attributes = $this->browser->attributes($element["page_id"], $element["ids"][0]);
83
84
    if (!in_array($tagName, array("input", "select"))) {
85
      throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
86
    }
87
88
    if ($tagName === "input" && $attributes["type"] != "radio") {
89
      throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
90
    }
91
92
    return $this->browser->selectOption($element["page_id"], $element["ids"][0], $value, $multiple);
93
  }
94
95
  /**
96
   * Check control over an input element of radio or checkbox type
97
   * @param $xpath
98
   * @return bool
99
   * @throws DriverException
100
   */
101
  protected function inputCheckableControl($xpath) {
102
    $element = $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
103
    $tagName = strtolower($this->browser->tagName($element["page_id"], $element["ids"][0]));
104
    $attributes = $this->browser->attributes($element["page_id"], $element["ids"][0]);
105
    if ($tagName != "input") {
106
      throw new DriverException("Can not check when the element is not of the input type");
107
    }
108
    if (!in_array($attributes["type"], array("checkbox", "radio"))) {
109
      throw new DriverException("Can not check when the element is not checkbox or radio");
110
    }
111
    return true;
112
  }
113
114
  /**
115
   * We click on the checkbox or radio when possible and needed
116
   * @param string $xpath
117
   * @throws DriverException
118
   */
119
  public function check($xpath) {
120
    $this->inputCheckableControl($xpath);
121
    $javascript = $this->javascriptTemplateRender("check_element.js.twig", array("xpath" => $xpath, "check" => "true"));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
122
    $this->browser->evaluate($javascript);
123
  }
124
125
  /**
126
   * We click on the checkbox or radio when possible and needed
127
   * @param string $xpath
128
   * @throws DriverException
129
   */
130
  public function uncheck($xpath) {
131
    $this->inputCheckableControl($xpath);
132
    $javascript = $this->javascriptTemplateRender("check_element.js.twig", array("xpath" => $xpath, "check" => "false"));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
133
    $this->browser->evaluate($javascript);
134
  }
135
136
  /**
137
   * Checks if the radio or checkbox is checked
138
   * @param string $xpath
139
   * @return bool
140
   * @throws DriverException
141
   */
142
  public function isChecked($xpath) {
143
    $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
144
    $javascript = $this->javascriptTemplateRender("is_checked.js.twig", array("xpath" => $xpath));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
145
    $checked = $this->browser->evaluate($javascript);
146
147
    if ($checked === null) {
148
      throw new DriverException("Can not check when the element is not checkbox or radio");
149
    }
150
151
    return $checked;
152
  }
153
154
  /**
155
   * Checks if the option is selected or not
156
   * @param string $xpath
157
   * @return bool
158
   * @throws DriverException
159
   */
160
  public function isSelected($xpath) {
161
    $elements = $this->findElement($xpath, 1);
0 ignored issues
show
It seems like findElement() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
162
    $javascript = $this->javascriptTemplateRender("is_selected.js.twig", array("xpath" => $xpath));
0 ignored issues
show
It seems like javascriptTemplateRender() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
163
    $tagName = $this->browser->tagName($elements["page_id"], $elements["ids"][0]);
164
    if (strcmp(strtolower($tagName), "option") !== 0) {
165
      throw new DriverException("Can not assert on element that is not an option");
166
    }
167
168
    return $this->browser->evaluate($javascript);
169
  }
170
}
171