Issues (36)

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/Integration/SecurityTest.php (1 issue)

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 League\Tactician\Bundle\Tests\Integration;
4
5
use League\Tactician\Bundle\Tests\Fake\FakeCommand;
6
use stdClass;
7
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
8
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
9
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
10
use Symfony\Component\Security\Core\Role\Role;
11
12
/**
13
 * Integration test for security middleware.
14
 *
15
 * @author Ron Rademaker
16
 *
17
 * @runTestsInSeparateProcesses
18
 */
19
class SecurityTest extends IntegrationTest
20
{
21
    public function testCanBootKernelWithSecurityMiddleware()
22
    {
23
        $this->loadSecurityConfiguration();
24
25
        $this->givenConfig('tactician', <<<'EOF'
26
commandbus:
27
    default:
28
        middleware:
29
            - tactician.middleware.security
30
EOF
31
        );
32
        static::$kernel->boot();
33
        $this->assertTrue(true);
34
    }
35
36
    public function testCanNotBootKernelIfLoadingSecurityMiddlewareWithoutSecurityBeingTurnedOn()
37
    {
38
        $this->expectException(ServiceNotFoundException::class);
39
        $this->givenConfig('tactician', <<<'EOF'
40
commandbus:
41
    default:
42
        middleware:
43
            - tactician.middleware.security
44
EOF
45
        );
46
        static::$kernel->boot();
47
    }
48
49
    public function testCanBootKernelWithoutSecurityOrSecurityMiddleware()
50
    {
51
        $this->givenConfig('tactician', <<<'EOF'
52
commandbus:
53
    default:
54
        middleware:
55
            - tactician.middleware.command_handler
56
EOF
57
        );
58
        static::$kernel->boot();
59
        $this->assertTrue(true);
60
    }
61
62
    /**
63
     * @dataProvider provideTestData
64
     */
65
    public function testSecurityMiddleware($command, string $role, string $expectedExceptionClassName = null)
66
    {
67
        if ($expectedExceptionClassName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $expectedExceptionClassName of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
68
            $this->expectException($expectedExceptionClassName);
69
        }
70
71
        $this->loadSecurityConfiguration();
72
        $this->givenConfig('tactician', <<<'EOF'
73
commandbus:
74
    default:
75
        middleware:
76
            - tactician.middleware.security
77
security:
78
    League\Tactician\Bundle\Tests\Fake\FakeCommand:
79
        - 'ROLE_ADMIN'
80
EOF
81
        );
82
83
        static::$kernel->boot();
84
        $this->setUserRole($role);
85
86
        static::$kernel->getContainer()->get('tactician.commandbus.default')->handle($command);
87
    }
88
89
    /**
90
     * Gets test data for security middleware integration test.
91
     *
92
     * @return array
93
     */
94
    public function provideTestData(): array
95
    {
96
        return [
97
            'Role may handle the command' => [new FakeCommand(), 'ROLE_ADMIN'],
98
            'Test role hierarchy' => [new FakeCommand(), 'ROLE_SUPER_ADMIN'],
99
            'Role may not handle the command' => [new FakeCommand(), 'ROLE_USER', AccessDeniedException::class],
100
            'Deny access if command is not in the mapping' => [new stdClass(), 'ROLE_SUPER_ADMIN', AccessDeniedException::class],
101
        ];
102
    }
103
104
    /**
105
     * Security configuration.
106
     */
107
    private function loadSecurityConfiguration()
108
    {
109
        $this->givenConfig('security', <<< 'EOF'
110
access_denied_url: /
111
112
role_hierarchy:
113
    ROLE_ADMIN:       ROLE_USER
114
    ROLE_SUPER_ADMIN: ROLE_ADMIN
115
116
providers:
117
    my_in_memory_provider:
118
        memory:
119
120
firewalls:
121
    main:
122
        anonymous: ~
123
        http_basic: ~
124
EOF
125
        );
126
    }
127
128
    /**
129
     * @param string $role
130
     */
131
    protected function setUserRole(string $role)
132
    {
133
        static::$kernel->getContainer()
134
            ->get('security.token_storage')
135
            ->setToken(
136
                new AnonymousToken('test', 'anon', [$role])
137
            );
138
    }
139
}
140