Issues (115)

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.

Initializer/SilverStripeAwareInitializer.php (8 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 SilverStripe\BehatExtension\Context\Initializer;
4
5
use Behat\Behat\Context\Initializer\InitializerInterface;
6
use Behat\Behat\Context\ContextInterface;
7
8
use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface;
9
10
/*
11
 * This file is part of the Behat/SilverStripeExtension
12
 *
13
 * (c) MichaƂ Ochman <[email protected]>
14
 *
15
 * For the full copyright and license information, please view the LICENSE
16
 * file that was distributed with this source code.
17
 */
18
19
/**
20
 * SilverStripe aware contexts initializer.
21
 * Sets SilverStripe instance to the SilverStripeAware contexts.
22
 *
23
 * @author MichaƂ Ochman <[email protected]>
24
 */
25
class SilverStripeAwareInitializer implements InitializerInterface
26
{
27
    
28
    private $databaseName;
29
    
30
    /**
31
     * @var Array
32
     */
33
    protected $ajaxSteps;
34
35
    /**
36
     * @var Int Timeout in milliseconds
37
     */
38
    protected $ajaxTimeout;
39
40
    /**
41
     * @var String {@link see SilverStripeContext}
42
     */
43
    protected $adminUrl;
44
45
    /**
46
     * @var String {@link see SilverStripeContext}
47
     */
48
    protected $loginUrl;
49
50
    /**
51
     * @var String {@link see SilverStripeContext}
52
     */
53
    protected $screenshotPath;
54
55
    /**
56
     * @var object {@link TestSessionEnvironment}
57
     */
58
    protected $testSessionEnvironment;
59
60
    /**
61
     * Initializes initializer.
62
     */
63
    public function __construct($frameworkPath)
64
    {
65
        $this->bootstrap($frameworkPath);
66
67
        file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
68
69
        $testEnv = \Injector::inst()->get('TestSessionEnvironment');
70
        $testEnv->startTestSession(array(
71
            'createDatabase' => true
72
        ));
73
74
        $state = $testEnv->getState();
75
76
        $this->databaseName = $state->database;
77
        $this->testSessionEnvironment = $testEnv;
78
79
        file_put_contents('php://stdout', "Temp Database: $this->databaseName" . PHP_EOL . PHP_EOL);
80
81
        register_shutdown_function(array($this, '__destruct'));
82
    }
83
84
    public function __destruct()
85
    {
86
        // Add condition here as register_shutdown_function() also calls this in __construct()
87
        if ($this->testSessionEnvironment) {
88
            file_put_contents('php://stdout', "Killing test session environment...");
89
            $this->testSessionEnvironment->endTestSession();
90
            $this->testSessionEnvironment = null;
91
            file_put_contents('php://stdout', " done!" . PHP_EOL);
92
        }
93
    }
94
95
    /**
96
     * Checks if initializer supports provided context.
97
     *
98
     * @param ContextInterface $context
99
     *
100
     * @return Boolean
101
     */
102
    public function supports(ContextInterface $context)
103
    {
104
        return $context instanceof SilverStripeAwareContextInterface;
105
    }
106
107
    /**
108
     * Initializes provided context.
109
     *
110
     * @param ContextInterface $context
111
     */
112
    public function initialize(ContextInterface $context)
113
    {
114
        $context->setDatabase($this->databaseName);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setDatabase() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
115
        $context->setAjaxSteps($this->ajaxSteps);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setAjaxSteps() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
116
        $context->setAjaxTimeout($this->ajaxTimeout);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setAjaxTimeout() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
117
        $context->setScreenshotPath($this->screenshotPath);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setScreenshotPath() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
118
        $context->setRegionMap($this->regionMap);
0 ignored issues
show
The property regionMap 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...
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setRegionMap() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
119
        $context->setAdminUrl($this->adminUrl);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setAdminUrl() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
120
        $context->setLoginUrl($this->loginUrl);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Behat\Behat\Context\ContextInterface as the method setLoginUrl() does only exist in the following implementations of said interface: SilverStripe\BehatExtens...ext\SilverStripeContext.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
121
    }
122
123
    public function setAjaxSteps($ajaxSteps)
124
    {
125
        if ($ajaxSteps) {
126
            $this->ajaxSteps = $ajaxSteps;
127
        }
128
    }
129
130
    public function getAjaxSteps()
131
    {
132
        return $this->ajaxSteps;
133
    }
134
135
    public function setAjaxTimeout($ajaxTimeout)
136
    {
137
        $this->ajaxTimeout = $ajaxTimeout;
138
    }
139
140
    public function getAjaxTimeout()
141
    {
142
        return $this->ajaxTimeout;
143
    }
144
145
    public function setAdminUrl($adminUrl)
146
    {
147
        $this->adminUrl = $adminUrl;
148
    }
149
150
    public function getAdminUrl()
151
    {
152
        return $this->adminUrl;
153
    }
154
155
    public function setLoginUrl($loginUrl)
156
    {
157
        $this->loginUrl = $loginUrl;
158
    }
159
160
    public function getLoginUrl()
161
    {
162
        return $this->loginUrl;
163
    }
164
165
    public function setScreenshotPath($screenshotPath)
166
    {
167
        $this->screenshotPath = $screenshotPath;
168
    }
169
170
    public function getScreenshotPath()
171
    {
172
        return $this->screenshotPath;
173
    }
174
175
    public function getRegionMap()
176
    {
177
        return $this->regionMap;
178
    }
179
180
    public function setRegionMap($regionMap)
181
    {
182
        $this->regionMap = $regionMap;
183
    }
184
185
    /**
186
     * @param String Absolute path to 'framework' module
187
     */
188
    protected function bootstrap($frameworkPath)
189
    {
190
        file_put_contents('php://stdout', 'Bootstrapping' . PHP_EOL);
191
192
        // Connect to database and build manifest
193
        $_GET['flush'] = 1;
194
        require_once $frameworkPath . '/core/Core.php';
195
        unset($_GET['flush']);
196
197
        // Remove the error handler so that PHPUnit can add its own
198
        restore_error_handler();
199
    }
200
}
201