Issues (65)

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.

DependencyInjection/MesCryptoExtensionTest.php (6 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
/*
4
 * This file is part of the MesCryptoBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mes\Security\CryptoBundle\Tests\DependencyInjection;
13
14
use Mes\Security\CryptoBundle\DependencyInjection\MesCryptoExtension;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\Yaml\Parser;
17
18
/**
19
 * Class MesCryptoExtensionTest.
20
 */
21
class MesCryptoExtensionTest extends \PHPUnit_Framework_TestCase
22
{
23
    /** @var ContainerBuilder */
24
    private $configuration;
25
26
    protected function setup()
27
    {
28
        $this->configuration = new ContainerBuilder();
29
        $this->configuration->setParameter('kernel.root_dir', dirname(dirname(__DIR__)));
30
    }
31
32
    protected function tearDown()
33
    {
34
        unset($this->configuration);
35
    }
36
37 View Code Duplication
    public function testContainerWithDefaultValues()
0 ignored issues
show
This method seems to be duplicated in 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...
38
    {
39
        $loader = new MesCryptoExtension();
40
        $config = $this->getEmptyConfig();
41
        $loader->load(array($config), $this->configuration);
42
43
        $this->assertHasDefinition('mes_crypto.raw_key');
44
        $this->assertSame('Defuse\Crypto\Key', $this->configuration->findDefinition('mes_crypto.raw_key')
45
                                                                   ->getClass(), 'Defuse\Crypto\Key class is correct');
46
47
        $this->assertNotHasDefinition('mes_crypto.loader');
48
    }
49
50 View Code Duplication
    public function testContainerWithRandomKeyAndSecret()
0 ignored issues
show
This method seems to be duplicated in 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...
51
    {
52
        $loader = new MesCryptoExtension();
53
        $config = $this->getConfigWithRandomKeyAndSecret();
54
        $loader->load(array($config), $this->configuration);
55
56
        $this->assertHasDefinition('mes_crypto.raw_key');
57
        $this->assertSame('Defuse\Crypto\KeyProtectedByPassword', $this->configuration->findDefinition('mes_crypto.raw_key')
58
                                                                                      ->getClass(), 'KeyProtectedByPassword class is correct');
59
60
        $this->assertNotHasDefinition('mes_crypto.loader');
61
    }
62
63 View Code Duplication
    public function testContainerWithInternalKeyAndSecret()
0 ignored issues
show
This method seems to be duplicated in 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...
64
    {
65
        $loader = new MesCryptoExtension();
66
        $config = $this->getConfigWithInternalKeyAndSecret();
67
        $loader->load(array($config), $this->configuration);
68
69
        $this->assertHasDefinition('mes_crypto.raw_key');
70
        $this->assertSame('Defuse\Crypto\KeyProtectedByPassword', $this->configuration->findDefinition('mes_crypto.raw_key')
71
                                                                                      ->getClass(), 'Defuse\Crypto\KeyProtectedByPassword class is correct');
72
        $this->assertNotHasDefinition('mes_crypto.loader');
73
    }
74
75 View Code Duplication
    public function testContainerWithExternalKeyAndSecret()
0 ignored issues
show
This method seems to be duplicated in 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...
76
    {
77
        $loader = new MesCryptoExtension();
78
        $config = $this->getConfigWithExternalKey();
79
        $loader->load(array($config), $this->configuration);
80
81
        $this->assertHasDefinition('mes_crypto.raw_key');
82
        $this->assertSame('Defuse\Crypto\KeyProtectedByPassword', $this->configuration->findDefinition('mes_crypto.raw_key')
83
                                                                                      ->getClass(), 'Defuse\Crypto\KeyProtectedByPassword class is correct');
84
        $this->assertHasDefinition('mes_crypto.loader');
85
    }
86
87
    public function testContainerWithFullConfigWithExternalKey()
88
    {
89
        $loader = new MesCryptoExtension();
90
        $config = $this->getFullConfigWithExternalKey();
91
        $loader->load(array($config), $this->configuration);
92
93
        $this->assertHasDefinition('mes_crypto.raw_key');
94
        $this->assertSame('Defuse\Crypto\KeyProtectedByPassword', $this->configuration->findDefinition('mes_crypto.raw_key')
95
                                                                                      ->getClass(), 'Defuse\Crypto\KeyProtectedByPassword class is correct');
96
        $this->assertHasDefinition('mes_crypto.loader');
97
98
        $this->assertSame('custom_key_storage_service', (string) $this->configuration->getAlias('mes_crypto.key_storage'), 'custom_key_storage_service is correct alias');
99
        $this->assertSame('custom_key_generator_service', (string) $this->configuration->getAlias('mes_crypto.key_generator'), 'custom_key_generator_service is correct alias');
100
        $this->assertSame('custom_encryption_service', (string) $this->configuration->getAlias('mes_crypto.encryption'), 'custom_encryption_service is correct alias');
101
    }
102
103
    /**
104
     * @return array
105
     */
106
    private function getEmptyConfig()
107
    {
108
        return array();
109
    }
110
111
    /**
112
     * @return mixed
113
     */
114
    private function getConfigWithRandomKeyAndSecret()
115
    {
116
        $yaml = <<<'EOF'
117
secret: "ThisIsASecret"
118
EOF;
119
120
        $parser = new Parser();
121
122
        return $parser->parse($yaml);
123
    }
124
125
    /**
126
     * @return mixed
127
     */
128
    private function getConfigWithInternalKeyAndSecret()
129
    {
130
        $yaml = <<<'EOF'
131
key: "ThisIsEncodedKey"
132
secret: "ThisIsASecret"
133
EOF;
134
135
        $parser = new Parser();
136
137
        return $parser->parse($yaml);
138
    }
139
140
    /**
141
     * @return mixed
142
     */
143 View Code Duplication
    private function getConfigWithExternalKey()
0 ignored issues
show
This method seems to be duplicated in 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...
144
    {
145
        $cryptoFile = dirname(__DIR__).'/key.crypto';
146
        $yaml = <<<EOF
147
key: $cryptoFile
148
external_secret: true
149
EOF;
150
151
        $parser = new Parser();
152
153
        return $parser->parse($yaml);
154
    }
155
156
    /**
157
     * @return mixed
158
     */
159 View Code Duplication
    private function getFullConfigWithExternalKey()
0 ignored issues
show
This method seems to be duplicated in 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...
160
    {
161
        $cryptoFile = dirname(__DIR__).'/key.crypto';
162
        $yaml = <<<EOF
163
key: $cryptoFile
164
external_secret: true
165
key_storage: custom_key_storage_service
166
key_generator: custom_key_generator_service
167
encryption: custom_encryption_service
168
EOF;
169
170
        $parser = new Parser();
171
172
        return $parser->parse($yaml);
173
    }
174
175
    /**
176
     * @return mixed
177
     */
178
    private function getConfigWithExternalLoader()
179
    {
180
        $yaml = <<<'EOF'
181
loader:
182
    enabled; true
183
EOF;
184
185
        $parser = new Parser();
186
187
        return $parser->parse($yaml);
188
    }
189
190
    /**
191
     * @param string $id
192
     */
193
    private function assertHasDefinition($id)
194
    {
195
        $this->assertTrue(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id)));
196
    }
197
198
    /**
199
     * @param string $id
200
     */
201
    private function assertNotHasDefinition($id)
202
    {
203
        $this->assertFalse(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id)));
204
    }
205
}
206