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.

Tests/Loader/CryptoLoaderTest.php (4 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\Loader;
13
14
use Mes\Security\CryptoBundle\KeyGenerator\KeyGenerator;
15
use Mes\Security\CryptoBundle\Loader\CryptoLoader;
16
17
/**
18
 * Class CryptoLoaderTest.
19
 */
20
class CryptoLoaderTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var CryptoLoader
24
     */
25
    private $loader;
26
27
    /**
28
     * @var KeyGenerator
29
     */
30
    private $keyGenerator;
31
32
    private $tempCryptoFile;
33
34
    protected function setUp()
35
    {
36
        $this->loader = new CryptoLoader();
37
        $this->loader->setResource(__DIR__.'/../key.crypto');
38
        $this->keyGenerator = new KeyGenerator();
39
    }
40
41
    protected function tearDown()
42
    {
43
        $this->loader = null;
44
        $this->keyGenerator = null;
45
        @unlink($this->tempCryptoFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
46
    }
47
48
    public function testLoadKeyLoadsEncodedKey()
49
    {
50
        $encodedKey = $this->loader->loadKey();
51
52
        $key = $this->keyGenerator->generateFromAscii($encodedKey, $this->loader->loadSecret());
53
54
        $this->assertInstanceOf('Mes\\Security\\CryptoBundle\\Model\\KeyInterface', $key);
55
        $this->assertTrue(ctype_print($encodedKey), ' is printable');
56
    }
57
58
    /**
59
     * @expectedException \UnexpectedValueException
60
     */
61 View Code Duplication
    public function testLoadKeyThrowsExceptionBecauseKeyIsMissing()
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...
62
    {
63
        $this->tempCryptoFile = __DIR__.'/../invalid_key.crypto';
64
65
        $handle = fopen($this->tempCryptoFile, 'w+');
66
        fwrite($handle, <<<'EOF'
67
secret=ThisIsASecret
68
EOF
69
        );
70
        fclose($handle);
71
72
        $loader = new CryptoLoader();
73
        $loader->setResource($this->tempCryptoFile);
74
        $loader->loadKey();
75
    }
76
77
    /**
78
     * @expectedException \UnexpectedValueException
79
     */
80 View Code Duplication
    public function testLoadKeyThrowsExceptionBecauseSecretIsMissing()
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...
81
    {
82
        $this->tempCryptoFile = __DIR__.'/../invalid_key.crypto';
83
84
        $handle = fopen($this->tempCryptoFile, 'w+');
85
        fwrite($handle, <<<'EOF'
86
key=ThisIsAnEncodedKey
87
EOF
88
        );
89
        fclose($handle);
90
91
        $loader = new CryptoLoader();
92
        $loader->setResource($this->tempCryptoFile);
93
        $loader->loadSecret();
94
    }
95
96
    public function testLoadSecretLoadsSecret()
97
    {
98
        $secret = $this->loader->loadSecret();
99
100
        $this->assertSame('ThisIsASecret', $secret);
101
    }
102
103
    /**
104
     * @expectedException \InvalidArgumentException
105
     */
106
    public function test__ConstructFailsBecauseResourceNotExists()
107
    {
108
        $fakeFile = '/var/www/fake';
109
110
        $loader = new CryptoLoader();
111
        $loader->setResource($fakeFile);
112
    }
113
114
    /**
115
     * @expectedException \RuntimeException
116
     */
117 View Code Duplication
    public function test__ConstructFailsBecauseResourceIsBadFormatted()
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...
118
    {
119
        $this->tempCryptoFile = __DIR__.'/../invalid_key.crypto';
120
121
        $handle = fopen($this->tempCryptoFile, 'w+');
122
        fwrite($handle, <<<'EOF'
123
key:ThisIsAKey
124
secret:ThisIsASecret
125
EOF
126
        );
127
        fclose($handle);
128
129
        $loader = new CryptoLoader();
130
        $loader->setResource($this->tempCryptoFile);
131
    }
132
}
133