Issues (5)

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.

tests/MultiDomainDomainTest.php (3 issues)

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
namespace SilverStripe\MultiDomain\Tests;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\MultiDomain\MultiDomain;
8
9
class MultiDomainDomainTest extends SapphireTest
10
{
11
    /**
12
     * Set up some test domain data for testing
13
     *
14
     * {@inheritDoc}
15
     */
16
    public function setUp()
17
    {
18
        parent::setUp();
19
        Config::nest();
20
21
        Config::inst()->remove(MultiDomain::class, 'domains');
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SilverStripe\Config\Coll...nfigCollectionInterface as the method remove() does only exist in the following implementations of said interface: SilverStripe\Config\Coll...s\DeltaConfigCollection, SilverStripe\Config\Coll...\MemoryConfigCollection.

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...
22
        Config::inst()->update(MultiDomain::class, 'domains', array(
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SilverStripe\Config\Coll...nfigCollectionInterface as the method update() does only exist in the following implementations of said interface: SilverStripe\Config\Coll...s\DeltaConfigCollection, SilverStripe\Config\Coll...\MemoryConfigCollection.

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...
23
            'primary' => array(
24
                'hostname' => 'example.com'
25
            ),
26
            'store' => array(
27
                'hostname' => 'example-store.com',
28
                'resolves_to' => 'shop/store',
29
                'allow' => array(
30
                    'admin/*',
31
                    'Security/*',
32
                    'my-custom-webhook/'
33
                )
34
            ),
35
            'configurable' => array(
36
                'hostname' => 'MY_CONSTANT_HOSTNAME'
37
            ),
38
            'forceful' => array(
39
                'hostname' => 'forced.com',
40
                'force' => array(
41
                    'buy-now/*'
42
                )
43
            )
44
        ));
45
    }
46
47
    /**
48
     * Test that a hostname defined in a constant will override the default configuration, otherwise the default
49
     * configuration for the domain is returned
50
     */
51
    public function testGetHostname()
52
    {
53
        $configurableDomain = MultiDomain::get_domain('configurable');
54
        define('MY_CONSTANT_HOSTNAME', 'I am a constant');
55
        $this->assertSame('I am a constant', $configurableDomain->getHostname());
56
57
        $storeDomain = MultiDomain::get_domain('store');
58
        $this->assertSame('example-store.com', $storeDomain->getHostname());
59
    }
60
61
    /**
62
     * Test that the domain's "resolves to" property is returned for the URL if it is defined, otherwise null
63
     */
64
    public function testGetUrl()
65
    {
66
        $primaryDomain = MultiDomain::get_domain('primary');
67
        $this->assertNull($primaryDomain->getURL());
68
69
        $storeDomain = MultiDomain::get_domain('store');
70
        $this->assertSame('shop/store', $storeDomain->getURL());
71
    }
72
73
    /**
74
     * Test that a domain can be identified as the primary domain or otherwise
75
     */
76
    public function testIsPrimary()
77
    {
78
        $this->assertTrue(MultiDomain::get_primary_domain()->isPrimary());
79
        $this->assertFalse(MultiDomain::get_domain('store')->isPrimary());
80
    }
81
82
    /**
83
     * When the request URI matches one of the allowed rules for a domain, the isActive method should return false
84
     */
85
    public function testIsActiveReturnsFalseWhenRequestUriIsAllowedPath()
86
    {
87
        $domain = MultiDomain::get_domain('store');
88
        $domain->setRequestUri('/Security/login');
89
        $this->assertFalse($domain->isActive());
90
    }
91
92
    /**
93
     * When a subdomain is "allowed" and is requested, subdomains should be allowed through "isActive" as well
94
     * as the primary domain
95
     */
96
    public function testSubdomainsAllowedInIsActiveWhenConfigured()
97
    {
98
        Config::inst()->update(MultiDomain::class, 'allow_subdomains', true);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SilverStripe\Config\Coll...nfigCollectionInterface as the method update() does only exist in the following implementations of said interface: SilverStripe\Config\Coll...s\DeltaConfigCollection, SilverStripe\Config\Coll...\MemoryConfigCollection.

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...
99
100
        $domain = MultiDomain::get_domain('store')
101
            ->setRequestUri('/some/page')
102
            ->setHttpHost('api.example-store.com');
103
104
        $this->assertTrue($domain->isActive());
105
    }
106
107
    /**
108
     * The default behaviour would be that if the current host from the request matchese that of the domain model
109
     * then isActive should be true
110
     */
111
    public function testReturnActiveIfCurrentHostMatchesDomainsHostname()
112
    {
113
        $domain = MultiDomain::get_domain('primary')
114
            ->setRequestUri('/another/page')
115
            ->setHttpHost('example.com');
116
117
        $this->assertTrue($domain->isActive());
118
    }
119
120
    /**
121
     * getNativeUrl should not be used on the primary domain
122
     *
123
     * @expectedException Exception
124
     * @expectedExceptionMessage Cannot convert a native URL on the primary domain
125
     */
126
    public function testGetNativeUrlThrowsExceptionOnPrimaryDomain()
127
    {
128
        MultiDomain::get_primary_domain()->getNativeUrl('foo');
129
    }
130
131
    /**
132
     * Test that a URL segment can be added to the domain's URL and returned as a "native URL"
133
     */
134
    public function testGetNativeUrl()
135
    {
136
        $domain = MultiDomain::get_domain('store');
137
        $this->assertSame('shop/store/foo/bar', $domain->getNativeUrl('foo/bar'));
138
    }
139
140
    /**
141
     * "Allowed" and "forced" URLs should just be returned from getNativeUrl as is
142
     */
143
    public function testGetNativeUrlReturnsInputWhenUrlIsAllowedOrForced()
144
    {
145
        $domain = MultiDomain::get_domain('store');
146
        $this->assertSame('my-custom-webhook/', $domain->getNativeUrl('my-custom-webhook/'));
147
148
        $domain = MultiDomain::get_domain('forceful');
149
        $this->assertSame('buy-now/whatever', $domain->getNativeUrl('buy-now/whatever'));
150
    }
151
152
    /**
153
     * The primary domain and "allowed" route matches should be returned as it
154
     */
155
    public function testGetVanityUrlReturnsInputWhenUrlIsAllowedOrIsPrimaryDomain()
156
    {
157
        $this->assertSame('/pages/info', MultiDomain::get_primary_domain()->getVanityUrl('/pages/info'));
158
        $this->assertSame('/Security/login', MultiDomain::get_domain('store')->getVanityUrl('/Security/login'));
159
    }
160
161
    /**
162
     * Non-primary domains and un-allowed route matches should be returned without their URL for vanity
163
     */
164
    public function testGetVanityUrl()
165
    {
166
        $this->assertSame('partners/', MultiDomain::get_domain('store')->getVanityUrl('shop/store/partners/'));
167
        $this->assertSame('foo/bar', MultiDomain::get_domain('store')->getVanityUrl('shop/store/foo/bar'));
168
    }
169
170
    public function tearDown()
171
    {
172
        Config::unnest();
173
        parent::tearDown();
174
    }
175
}
176