Issues (6)

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/MiddlewareTest.php (2 issues)

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 ChadicusTest\Psr\Http\ServerMiddleware;
4
5
use ArrayObject;
6
use Chadicus\Psr\Http\ServerMiddleware\AuthenticationException;
7
use Chadicus\Psr\Http\ServerMiddleware\Middleware;
8
use Chadicus\Psr\Http\ServerMiddleware\Token;
9
use Chadicus\Psr\Http\ServerMiddleware;
10
use Zend\Diactoros\Response;
11
use Zend\Diactoros\ServerRequest;
12
13
/**
14
 * @coversDefaultClass \Chadicus\Psr\Http\ServerMiddleware\Middleware
15
 * @covers ::__construct
16
 */
17
final class MiddlewareTest extends \PHPUnit\Framework\TestCase
18
{
19
    /**
20
     * Verify basic behavior of __invoke().
21
     *
22
     * @test
23
     * @covers ::__invoke
24
     *
25
     * @return void
26
     */
27
    public function invoke()
28
    {
29
        $privateKey = md5(microtime(true));
30
        $publicKey = md5(microtime());
31
        $nonce = rand();
32
        $time = time();
33
        $signature = md5("{$privateKey}{$nonce}{$time}{$publicKey}");
34
35
        $token = new Token($publicKey, $signature, $nonce, $time);
36
37
        $provider = $this->getMockBuilder('\\Chadicus\\Psr\\Http\\ServerMiddleware\\KeyProviderInterface')->getMock();
38
        $provider->method('findPrivateKey')->willReturn($privateKey);
39
40
        $extractor = $this->getMockBuilder(
41
            '\\Chadicus\\Psr\\Http\\ServerMiddleware\\TokenExtractorInterface'
42
        )->getMock();
43
        $extractor->method('extract')->willReturn($token);
44
45
        $validator = $this->getMockBuilder(
46
            '\\Chadicus\\Psr\\Http\\ServerMiddleware\\TokenValidatorInterface'
47
        )->getMock();
48
        $validator->method('validate')->willReturn(true);
49
50
        $container = new ArrayObject();
51
52
        $middleware = new Middleware($provider, $extractor, $validator, $container);
53
54
        $headers = [
55
            'X-Hmac-Auth' => ["{$publicKey}:{$signature}:{$nonce}:{$time}"],
56
        ];
57
58
        $next = function ($request, $response) {
59
            return $response;
60
        };
61
62
        $psr7Request = new ServerRequest([], [], 'http://localhost', 'GET', 'php://input', $headers);
63
64
        $middleware($psr7Request, new Response(), $next);
65
66
        $this->assertSame($privateKey, $container['privateKey']);
67
    }
68
69
    /**
70
     * Verify behavior of __invoke() when AuthenticationException is thrown.
71
     *
72
     * @test
73
     * @covers ::__invoke
74
     *
75
     * @return void
76
     *
77
     * @throws \Exception Thrown if the $next callable passed to the middleware is called.
78
     */
79
    public function invokeExceptionThrown()
80
    {
81
        $privateKey = md5(microtime(true));
82
        $publicKey = md5(microtime());
83
        $nonce = rand();
84
        $time = time();
85
        $signature = md5("{$privateKey}{$nonce}{$time}{$publicKey}");
86
87
        $token = new Token($publicKey, $signature, $nonce, $time);
88
89
        $provider = $this->getMockBuilder('\\Chadicus\\Psr\\Http\\ServerMiddleware\\KeyProviderInterface')->getMock();
90
        $provider->method('findPrivateKey')->willReturn($privateKey);
91
92
        $extractor = $this->getMockBuilder(
93
            '\\Chadicus\\Psr\\Http\\ServerMiddleware\\TokenExtractorInterface'
94
        )->getMock();
95
        $extractor->method('extract')->willReturn($token);
96
97
        $exception = new AuthenticationException(400, 'Bad Request');
98
99
        $validator = $this->getMockBuilder(
100
            '\\Chadicus\\Psr\\Http\\ServerMiddleware\\TokenValidatorInterface'
101
        )->getMock();
102
        $validator->method('validate')->will($this->throwException($exception));
103
104
        $container = new ArrayObject();
105
106
        $middleware = new Middleware($provider, $extractor, $validator, $container);
107
108
        $headers = [
109
            'X-Hmac-Auth' => ["{$publicKey}:{$signature}:{$nonce}:{$time}"],
110
        ];
111
112
        $next = function ($request, $response) {
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
113
            throw new \Exception('This should not have been called!!');
114
        };
115
116
        $psr7Request = new ServerRequest([], [], 'http://localhost', 'GET', 'php://input', $headers);
117
118
        $response = $middleware($psr7Request, new Response(), $next);
119
120
        $this->assertFalse(isset($container['privateKey']));
121
122
        $this->assertSame(400, $response->getStatusCode());
123
        $this->assertSame('Bad Request', $response->getReasonPhrase());
124
    }
125
}
126