Issues (3099)

Security Analysis    not enabled

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.

unit/Validator/Constraints/MediaValidatorTest.php (3 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 Kunstmaan\MediaBundle\Tests\Validator\Constraints;
4
5
use Kunstmaan\MediaBundle\Entity\Media as MediaObject;
6
use Kunstmaan\MediaBundle\Validator\Constraints\Media;
7
use Kunstmaan\MediaBundle\Validator\Constraints\MediaValidator;
8
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
9
use Symfony\Component\Validator\Validation;
10
11
class MediaValidatorTest extends ConstraintValidatorTestCase
12
{
13
    protected function createValidator()
14
    {
15
        return new MediaValidator();
16
    }
17
18
    public function testMimeTypeIsIgnoredWhenNotSpecified()
19
    {
20
        $constraint = new Media();
21
        $media = new MediaObject();
22
23
        $this->validator->validate($media, $constraint);
24
25
        $this->assertNoViolation();
26
    }
27
28
    /**
29
     * @param $contentType
30
     * @param $allowed
31
     * @param $message
32
     * @param $parameters
33
     * @param $code
34
     *
35
     * @dataProvider dataMimeTypes
36
     */
37
    public function testMimeTypeMatches($contentType, $allowed, $message = null, array $parameters = [], $code = null)
38
    {
39
        $constraint = new Media(['mimeTypes' => $allowed]);
40
        $media = (new MediaObject())->setContentType($contentType);
41
42
        $this->validator->validate($media, $constraint);
43
44
        if ($message && $code) {
45
            $this->buildViolation($message)
46
                ->setCode($code)
47
                ->setParameters($parameters)
48
                ->assertRaised();
49
        } else {
50
            $this->assertNoViolation();
51
        }
52
    }
53
54
    public function testSvgIsNotTestedForDimensions()
55
    {
56
        $constraint = new Media(['minHeight' => 100]);
57
        $media = (new MediaObject())->setContentType('image/svg+xml');
58
59
        $this->validator->validate($media, $constraint);
60
61
        $this->assertNoViolation();
62
    }
63
64
    /**
65
     * @param string $dimension
66
     * @param int    $value
67
     * @param string $message
68
     * @param array  $parameters
69
     * @param int    $code
70
     *
71
     * @dataProvider dataDimensions
72
     */
73
    public function testDimensionsAreChecked($dimension, $value, $message = null, array $parameters = [], $code = null)
74
    {
75
        $constraint = new Media([$dimension => $value]);
76
        $media = (new MediaObject())
77
            ->setMetadataValue('original_width', 100)
78
            ->setMetadataValue('original_height', 100)
79
            ->setContentType('image/png');
80
81
        $this->validator->validate($media, $constraint);
82
83
        if ($message && $code) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $message of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $code of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
84
            $this->buildViolation($message)
85
                ->setCode($code)
86
                ->setParameters($parameters)
87
                ->assertRaised();
88
        } else {
89
            $this->assertNoViolation();
90
        }
91
    }
92
93
    public function dataMimeTypes()
94
    {
95
        return [
96
            ['image/png', ['image/png']],
97
            ['image/png', ['image/jpg', 'image/png']],
98
            ['image/png', ['image/*']],
99
            ['image/PNG', ['image/png']],
100
            ['image/png', ['image/PNG']],
101
            ['image/png', ['image/jpg'], 'The type of the file is invalid ({{ type }}). Allowed types are {{ types }}.', ['{{ type }}' => '"image/png"', '{{ types }}' => '"image/jpg"'], Media::INVALID_MIME_TYPE_ERROR],
102
            ['image/png', ['application/*'], 'The type of the file is invalid ({{ type }}). Allowed types are {{ types }}.', ['{{ type }}' => '"image/png"', '{{ types }}' => '"application/*"'], Media::INVALID_MIME_TYPE_ERROR],
103
        ];
104
    }
105
106
    public function dataDimensions()
107
    {
108
        // image size is 100x100
109
        return [
110
            ['minHeight', 100],
111
            ['maxHeight', 100],
112
            ['minWidth', 100],
113
            ['maxWidth', 100],
114
            ['minWidth', 200, 'The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.', ['{{ width }}' => 100, '{{ min_width }}' => 200], Media::TOO_NARROW_ERROR],
115
            ['maxWidth', 50, 'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.', ['{{ width }}' => 100, '{{ max_width }}' => 50], Media::TOO_WIDE_ERROR],
116
            ['minHeight', 200, 'The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.', ['{{ height }}' => 100, '{{ min_height }}' => 200], Media::TOO_LOW_ERROR],
117
            ['maxHeight', 50, 'The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.', ['{{ height }}' => 100, '{{ max_height }}' => 50], Media::TOO_HIGH_ERROR],
118
        ];
119
    }
120
121
    protected function getApiVersion()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
122
    {
123
        return Validation::API_VERSION_2_5;
124
    }
125
}
126