Issues (30)

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/SystemContext.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 Behatch\Context;
4
5
use Behat\Behat\Context\Context;
6
use Behat\Gherkin\Node\PyStringNode;
7
8
class SystemContext implements Context
9
{
10
    private $root;
11
    private $output;
12
    private $lastExecutionTime;
13
    private $lastReturnCode;
14
    private $createdFiles = [];
15
16
    public function __construct($root = '.')
17
    {
18
        $this->root = $root;
19
    }
20
21
    public static function getTranslationResources()
22
    {
23
        return glob(__DIR__ . '/../../i18n/*.xliff');
24
    }
25
26
    /**
27
     * Execute a command
28
     *
29
     * @Given (I )execute :command
30
     */
31
    public function iExecute($cmd)
32
    {
33
        $start = microtime(true);
34
35
        exec($cmd, $this->output, $this->lastReturnCode);
36
37
        $this->lastExecutionTime = microtime(true) - $start;
38
    }
39
40
    /**
41
     * Execute a command from project root
42
     *
43
     * @Given (I )execute :command from project root
44
     */
45
    public function iExecuteFromProjectRoot($cmd)
46
    {
47
        $cmd = $this->root . DIRECTORY_SEPARATOR . $cmd;
48
        $this->iExecute($cmd);
49
    }
50
51
    /**
52
     * Display the last command output
53
     *
54
     * @Then (I )display the last command output
55
     */
56
    public function iDumpCommandOutput()
57
    {
58
        echo implode(PHP_EOL, $this->output);
59
    }
60
61
    /**
62
     * Command should succeed
63
     *
64
     * @Then command should succeed
65
     */
66
    public function commandShouldSucceed() {
67
        if ($this->lastReturnCode !== 0) {
68
            throw new \Exception(sprintf("Command should succeed %b", $this->lastReturnCode));
69
        };
70
    }
71
72
    /**
73
     * Command should fail
74
     *
75
     * @Then command should fail
76
     */
77
    public function commandShouldFail() {
78
        if ($this->lastReturnCode === 0) {
79
            throw new \Exception(sprintf("Command should fail %b", $this->lastReturnCode));
80
        };
81
    }
82
83
    /**
84
     * Command should last less than
85
     *
86
     * @Then command should last less than :seconds seconds
87
     */
88
    public function commandShouldLastLessThan($seconds)
89
    {
90
        if ($this->lastExecutionTime > $seconds) {
91
            throw new \Exception(sprintf("Last command last %s which is more than %s seconds", $this->lastExecutionTime, $seconds));
92
        }
93
    }
94
95
    /**
96
     * Command should last more than
97
     *
98
     * @Then command should last more than :seconds seconds
99
     */
100
    public function commandShouldMoreLessThan($seconds)
101
    {
102
        if ($this->lastExecutionTime < $seconds) {
103
            throw new \Exception(sprintf("Last command last %s which is less than %s seconds", $this->lastExecutionTime, $seconds));
104
        }
105
    }
106
107
    /**
108
     * Checks, that output contains specified text.
109
     *
110
     * @Then output should contain :text
111
     */
112
    public function outputShouldContain($text)
113
    {
114
        $regex = '~'.$text.'~ui';
115
116
        $check = false;
117
        foreach ($this->output as $line) {
118
            if (preg_match($regex, $line) === 1) {
119
                $check = true;
120
                break;
121
            }
122
        }
123
124
        if ($check === false) {
125
            throw new \Exception(sprintf("The text '%s' was not found anywhere on output of command.\n%s", $text, implode("\n", $this->output)));
126
        }
127
    }
128
129
    /**
130
     * Checks, that output not contains specified text.
131
     *
132
     * @Then output should not contain :text
133
     */
134
    public function outputShouldNotContain($text)
135
    {
136
        $regex = '~'.$text.'~ui';
137
138 View Code Duplication
        foreach ($this->output as $line) {
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...
139
            if (preg_match($regex, $line) === 1) {
140
                throw new \Exception(sprintf("The text '%s' was found somewhere on output of command.\n%s", $text, implode("\n", $this->output)));
141
            }
142
        }
143
    }
144
145
    /**
146
     * @Given output should be:
147
     */
148
    public function outputShouldBe(PyStringNode $string)
149
    {
150
        $expected = $string->getStrings();
151 View Code Duplication
        foreach ($this->output as $index => $line) {
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...
152
            if ($line !== $expected[$index]) {
153
                throw new \Exception(sprintf("instead of\n%s", implode("\n", $this->output)));
154
            }
155
        }
156
    }
157
158
    /**
159
     * @Given output should not be:
160
     */
161
    public function outputShouldNotBe(PyStringNode $string)
162
    {
163
        $expected = $string->getStrings();
164
165
        $check = false;
166
        foreach ($this->output as $index => $line) {
167
            if ($line !== $expected[$index]) {
168
                $check = true;
169
                break;
170
            }
171
        }
172
173
        if ($check === false) {
174
            throw new \Exception("Output should not be");
175
        }
176
    }
177
178
    /**
179
     * @Given (I )create the file :filename containing:
180
     * @Given (I )create the file :filename contening:
181
     */
182
    public function iCreateTheFileContaining($filename, PyStringNode $string)
183
    {
184
        if (!is_file($filename)) {
185
            file_put_contents($filename, $string);
186
            $this->createdFiles[] = $filename;
187
        }
188
        else {
189
            throw new \RuntimeException("'$filename' already exists.");
190
        }
191
    }
192
193
    /**
194
     * @Then print the content of :filename file
195
     */
196
    public function printTheContentOfFile($filename)
197
    {
198
        if (is_file($filename)) {
199
            echo file_get_contents($filename);
200
        }
201
        else {
202
            throw new \RuntimeException("'$filename' doesn't exists.");
203
        }
204
    }
205
206
    /**
207
     * @AfterScenario
208
     */
209
    public function after()
210
    {
211
        foreach ($this->createdFiles as $filename) {
212
            unlink($filename);
213
        }
214
    }
215
}
216