Issues (20)

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.

Session/ExtractUniqueKeyFromSessionTest.php (5 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
declare(strict_types=1);
4
5
namespace PSR7CsrfTest\HttpMethod;
6
7
use PHPUnit\Framework\TestCase;
8
use PSR7Csrf\Session\ExtractUniqueKeyFromSession;
9
use PSR7Sessions\Storageless\Session\SessionInterface;
10
11
/**
12
 * @covers \PSR7Csrf\Session\ExtractUniqueKeyFromSession
13
 */
14
final class ExtractUniqueKeyFromSessionTest extends TestCase
15
{
16
    /**
17
     * @dataProvider keysProvider
18
     *
19
     * @param string $key
20
     */
21
    public function testExtractionWithExistingKey(string $key)
22
    {
23
        /* @var $session SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
24
        $session     = $this->createMock(SessionInterface::class);
25
        $superSecret = uniqid('', true);
26
27
        $session->expects(self::any())->method('get')->with($key, '')->willReturn($superSecret);
28
        $session->expects(self::never())->method('set');
29
30
        self::assertSame($superSecret, (new ExtractUniqueKeyFromSession($key))->__invoke($session));
0 ignored issues
show
It seems like $session defined by $this->createMock(\PSR7S...essionInterface::class) on line 24 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\Session\Extract...FromSession::__invoke() does only seem to accept object<PSR7Sessions\Stor...ssion\SessionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31
    }
32
33
    /**
34
     * @dataProvider keysProvider
35
     *
36
     * @param string $key
37
     */
38
    public function testExtractionWithEmptyExistingKey(string $key)
39
    {
40
        $extractKey = new ExtractUniqueKeyFromSession($key);
41
42
        /* @var $session SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
43
        $session = $this->createMock(SessionInterface::class);
44
45
        $session->expects(self::any())->method('get')->with($key, '')->willReturn('');
46
        $session->expects(self::exactly(2))->method('set')->with(
47
            $key,
48
            self::callback(function (string $secret) {
49
                self::assertNotEmpty($secret);
50
51
                return true;
52
            })
53
        );
54
55
        $secretUniqueKey = $extractKey->__invoke($session);
0 ignored issues
show
It seems like $session defined by $this->createMock(\PSR7S...essionInterface::class) on line 43 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\Session\Extract...FromSession::__invoke() does only seem to accept object<PSR7Sessions\Stor...ssion\SessionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56
57
        self::assertInternalType('string', $secretUniqueKey);
58
        self::assertNotEmpty($secretUniqueKey);
59
60
        $anotherSecretKey = $extractKey->__invoke($session);
0 ignored issues
show
It seems like $session defined by $this->createMock(\PSR7S...essionInterface::class) on line 43 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\Session\Extract...FromSession::__invoke() does only seem to accept object<PSR7Sessions\Stor...ssion\SessionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
62
        self::assertInternalType('string', $anotherSecretKey);
63
        self::assertNotEmpty($anotherSecretKey);
64
        self::assertNotEquals($secretUniqueKey, $anotherSecretKey);
65
    }
66
67
    /**
68
     * @dataProvider keysProvider
69
     *
70
     * @param string $key
71
     */
72
    public function testExtractionWithNonStringExistingKey(string $key)
73
    {
74
        $extractKey = new ExtractUniqueKeyFromSession($key);
75
76
        /* @var $session SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
77
        $session = $this->createMock(SessionInterface::class);
78
79
        $session->expects(self::any())->method('get')->with($key, '')->willReturn(123);
80
        $session->expects(self::exactly(2))->method('set')->with(
81
            $key,
82
            self::callback(function (string $secret) {
83
                self::assertNotEmpty($secret);
84
85
                return true;
86
            })
87
        );
88
89
        $secretUniqueKey = $extractKey->__invoke($session);
0 ignored issues
show
It seems like $session defined by $this->createMock(\PSR7S...essionInterface::class) on line 77 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\Session\Extract...FromSession::__invoke() does only seem to accept object<PSR7Sessions\Stor...ssion\SessionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
90
91
        self::assertInternalType('string', $secretUniqueKey);
92
        self::assertNotEmpty($secretUniqueKey);
93
94
        $anotherSecretKey = $extractKey->__invoke($session);
0 ignored issues
show
It seems like $session defined by $this->createMock(\PSR7S...essionInterface::class) on line 77 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PSR7Csrf\Session\Extract...FromSession::__invoke() does only seem to accept object<PSR7Sessions\Stor...ssion\SessionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
95
96
        self::assertInternalType('string', $anotherSecretKey);
97
        self::assertNotEmpty($anotherSecretKey);
98
        self::assertNotEquals($secretUniqueKey, $anotherSecretKey);
99
    }
100
101
    public function keysProvider() : array
102
    {
103
        return [
104
            [''],
105
            ['key'],
106
            ['123'],
107
            ['123 456'],
108
        ];
109
    }
110
}
111