Issues (2)

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/MD5UrlSignerTest.php (2 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
namespace spec\Spatie\UrlSigner;
4
5
use DateTime;
6
use DateTimeZone;
7
use PHPUnit\Framework\TestCase;
8
use Spatie\UrlSigner\Exceptions\InvalidExpiration;
9
use Spatie\UrlSigner\Exceptions\InvalidSignatureKey;
10
use Spatie\UrlSigner\MD5UrlSigner;
11
12
class MD5UrlSignerTest extends TestCase
13
{
14
    /** @test */
15
    public function it_is_initialized()
16
    {
17
        $urlSigner = new MD5UrlSigner('random_monkey');
18
19
        $this->assertInstanceOf(MD5UrlSigner::class, $urlSigner);
20
    }
21
22
    /** @test */
23
    public function it_will_throw_an_exception_for_an_empty_signatureKey()
24
    {
25
        $this->expectException(InvalidSignatureKey::class);
26
27
        $urlSigner = new MD5UrlSigner('');
0 ignored issues
show
$urlSigner is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
    }
29
30
    /** @test */
31
    public function it_returns_false_when_validating_a_forged_url()
32
    {
33
        $signedUrl = 'http://myapp.com/somewhereelse/?expires=4594900544&signature=41d5c3a92c6ef94e73cb70c7dcda0859';
34
        $urlSigner = new MD5UrlSigner('random_monkey');
35
36
        $this->assertFalse($urlSigner->validate($signedUrl));
37
    }
38
39
    /** @test */
40
    public function it_returns_false_when_validating_an_expired_url()
41
    {
42
        $signedUrl = 'http://myapp.com/?expires=1123690544&signature=93e02326d7572632dd6edfa2665f2743';
43
        $urlSigner = new MD5UrlSigner('random_monkey');
44
45
        $this->assertFalse($urlSigner->validate($signedUrl));
46
    }
47
48
    /** @test */
49
    public function it_returns_true_when_validating_an_non_expired_url()
50
    {
51
        $url = 'http://myapp.com';
52
        $expiration = 10000;
53
        $urlSigner = new MD5UrlSigner('random_monkey');
54
        $signedUrl = $urlSigner->sign($url, $expiration);
55
56
        $this->assertTrue($urlSigner->validate($signedUrl));
57
    }
58
59
    public function unsignedUrlProvider()
60
    {
61
        return [
62
            ['http://myapp.com/?expires=4594900544'],
63
            ['http://myapp.com/?signature=41d5c3a92c6ef94e73cb70c7dcda0859'],
64
        ];
65
    }
66
67
    /**
68
     * @test
69
     * @dataProvider unsignedUrlProvider
70
     */
71
    public function it_returns_false_when_validating_an_unsigned_url($unsignedUrl)
72
    {
73
        $urlSigner = new MD5UrlSigner('random_monkey');
74
75
        $this->assertFalse($urlSigner->validate($unsignedUrl));
76
    }
77
78
    /** @test */
79
    public function it_does_a_strict_check_on_expirations()
80
    {
81
        $url = 'http://myapp.com';
82
        $expiration = '30';
83
        $urlSigner = new MD5UrlSigner('random_monkey');
84
85
        $this->expectException(InvalidExpiration::class);
86
87
        $urlSigner->sign($url, $expiration);
88
    }
89
90
    public function pastExpirationProvider()
91
    {
92
        return [
93
            [DateTime::createFromFormat('d/m/Y H:i:s', '10/08/2005 18:15:44')],
94
            [-10],
95
        ];
96
    }
97
98
    /**
99
     * @test
100
     * @dataProvider pastExpirationProvider
101
     */
102
    public function it_doesnt_allow_expirations_in_the_past($pastExpiration)
103
    {
104
        $url = 'http://myapp.com';
105
        $urlSigner = new MD5UrlSigner('random_monkey');
106
107
        $this->expectException(InvalidExpiration::class);
108
109
        $urlSigner->sign($url, $pastExpiration);
110
    }
111
112
    /** @test */
113
    public function it_keeps_the_urls_query_parameters_intact()
114
    {
115
        $url = 'http://myapp.com/?foo=bar&baz=qux';
116
        $expiration = DateTime::createFromFormat(
117
            'd/m/Y H:i:s',
118
            '10/08/2115 18:15:44',
119
            new DateTimeZone('Europe/Brussels')
120
        );
121
        $exepectedUrl = 'http://myapp.com/?foo=bar&baz=qux&expires=4594900544&signature=728971d9fd0682793d2a1e96b734d949';
122
123
        $urlSigner = new MD5UrlSigner('random_monkey');
124
        $signedUrl = $urlSigner->sign($url, $expiration);
0 ignored issues
show
It seems like $expiration defined by \DateTime::createFromFor...one('Europe/Brussels')) on line 116 can also be of type false; however, Spatie\UrlSigner\BaseUrlSigner::sign() does only seem to accept object<DateTime>|integer, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
125
126
        $this->assertSame($exepectedUrl, $signedUrl);
127
        $this->assertTrue($urlSigner->validate($signedUrl));
128
    }
129
}
130