Issues (234)

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.

tests/Provider/BaseProviderTest.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Tests\Provider;
15
16
use Gaufrette\Adapter;
17
use Gaufrette\Filesystem;
18
use Sonata\AdminBundle\Form\FormMapper;
19
use Sonata\MediaBundle\CDN\CDNInterface;
20
use Sonata\MediaBundle\CDN\Server;
21
use Sonata\MediaBundle\Generator\IdGenerator;
22
use Sonata\MediaBundle\Model\MediaInterface;
23
use Sonata\MediaBundle\Provider\BaseProvider;
24
use Sonata\MediaBundle\Provider\MediaProviderInterface;
25
use Sonata\MediaBundle\Tests\Entity\Media;
26
use Sonata\MediaBundle\Thumbnail\ThumbnailInterface;
27
use Symfony\Component\Form\FormBuilder;
28
29
class BaseProviderTest extends AbstractProviderTest
30
{
31
    public function getProvider(): MediaProviderInterface
32
    {
33
        $adapter = $this->createMock(Adapter::class);
34
35
        $filesystem = $this->getMockBuilder(Filesystem::class)
36
            ->onlyMethods(['get'])
37
            ->setConstructorArgs([$adapter])
38
            ->getMock();
39
40
        $cdn = new Server('/uploads/media');
41
42
        $generator = new IdGenerator();
43
44
        $thumbnail = $this->createMock(ThumbnailInterface::class);
45
46
        $provider = new TestProvider('test', $filesystem, $cdn, $generator, $thumbnail);
47
        $this->assertInstanceOf(BaseProvider::class, $provider);
48
49
        return $provider;
50
    }
51
52
    public function testBaseProvider(): void
53
    {
54
        $provider = $this->getProvider();
55
        $provider->setTemplates([
56
            'edit' => 'edit.twig',
57
        ]);
58
59
        $this->assertIsArray($provider->getTemplates());
60
        $this->assertSame('edit.twig', $provider->getTemplate('edit'));
61
62
        $this->assertInstanceOf(CDNInterface::class, $provider->getCdn());
0 ignored issues
show
The method getCdn() does not exist on Sonata\MediaBundle\Provider\MediaProviderInterface. Did you maybe mean getCdnPath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
63
64
        $provider->addFormat('small', []);
65
66
        $this->assertIsArray($provider->getFormat('small'));
67
68
        $media = new Media();
69
        $media->setContext('test');
70
71
        $this->assertSame('admin', $provider->getFormatName($media, 'admin'));
72
        $this->assertSame('reference', $provider->getFormatName($media, 'reference'));
73
        $this->assertSame('test_small', $provider->getFormatName($media, 'small'));
74
        $this->assertSame('test_small', $provider->getFormatName($media, 'test_small'));
75
    }
76
77
    public function testGetCdnPath(): void
78
    {
79
        $provider = $this->getProvider();
80
        $this->assertSame('/uploads/media/my_file.txt', $provider->getCdnPath('my_file.txt', false));
81
    }
82
83
    public function testMetadata(): void
84
    {
85
        $provider = $this->getProvider();
86
87
        $this->assertSame('test', $provider->getProviderMetadata()->getTitle());
88
        $this->assertSame('test.description', $provider->getProviderMetadata()->getDescription());
89
        $this->assertNotNull($provider->getProviderMetadata()->getImage());
90
        $this->assertSame('fa fa-file', $provider->getProviderMetadata()->getOption('class'));
91
        $this->assertSame('SonataMediaBundle', $provider->getProviderMetadata()->getDomain());
92
    }
93
94
    public function testPostRemove(): void
95
    {
96
        $reflect = new \ReflectionClass(BaseProvider::class);
97
        $prop = $reflect->getProperty('clones');
98
        $prop->setAccessible(true);
99
100
        $provider = $this->getProvider();
101
        $media = new Media();
102
        $media->setId(1399);
103
        $media->setProviderReference('1f981a048e7d8b671415d17e9633abc0059df394.png');
104
        $hash = spl_object_hash($media);
105
106
        $provider->preRemove($media);
107
108
        $this->assertArrayHasKey($hash, $prop->getValue($provider));
109
110
        $media->setId(null); // Emulate an object detached from the EntityManager.
111
        $provider->postRemove($media);
112
113
        $this->assertArrayNotHasKey($hash, $prop->getValue($provider));
114
        $this->assertSame('/0001/02/1f981a048e7d8b671415d17e9633abc0059df394.png', $provider->prevReferenceImage);
0 ignored issues
show
Accessing prevReferenceImage on the interface Sonata\MediaBundle\Provider\MediaProviderInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
115
116
        $prop->setAccessible(false);
117
    }
118
}
119
120
class TestProvider extends BaseProvider
121
{
122
    /**
123
     * @var string
124
     */
125
    public $prevReferenceImage;
126
127
    public function getHelperProperties(MediaInterface $media, $format, $options = []): void
128
    {
129
        // TODO: Implement getHelperProperties() method.
130
    }
131
132
    public function postPersist(MediaInterface $media): void
133
    {
134
        // TODO: Implement postPersist() method.
135
    }
136
137
    public function buildEditForm(FormMapper $form): void
138
    {
139
        $form->add('foo');
140
    }
141
142
    public function buildCreateForm(FormMapper $form): void
143
    {
144
        $form->add('foo');
145
    }
146
147
    public function postUpdate(MediaInterface $media): void
148
    {
149
        // TODO: Implement postUpdate() method.
150
    }
151
152
    public function getAbsolutePath(MediaInterface $media): void
0 ignored issues
show
The parameter $media 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...
153
    {
154
        // TODO: Implement getAbsolutePath() method.
155
    }
156
157
    public function getReferenceImage(MediaInterface $media): string
158
    {
159
        // A copy of the code from \Sonata\MediaBundle\Provider\FileProvider::getReferenceImage()
160
        $this->prevReferenceImage = sprintf(
161
            '%s/%s',
162
            $this->generatePath($media),
163
            $media->getProviderReference()
164
        );
165
166
        return $this->prevReferenceImage;
167
    }
168
169
    public function generatePrivateUrl(MediaInterface $media, $format): void
170
    {
171
        // TODO: Implement generatePrivateUrl() method.
172
    }
173
174
    public function generatePublicUrl(MediaInterface $media, $format): void
175
    {
176
        // TODO: Implement generatePublicUrl() method.
177
    }
178
179
    public function getReferenceFile(MediaInterface $media): void
180
    {
181
        // TODO: Implement getReferenceFile() method.
182
    }
183
184
    public function preUpdate(MediaInterface $media): void
185
    {
186
        // TODO: Implement preUpdate() method.
187
    }
188
189
    public function prePersist(MediaInterface $media): void
190
    {
191
        // TODO: Implement prePersist() method.
192
    }
193
194
    public function getDownloadResponse(MediaInterface $media, $format, $mode, array $headers = []): void
195
    {
196
        // TODO: Implement getDownloadResponse() method.
197
    }
198
199
    public function buildMediaType(FormBuilder $formBuilder): void
200
    {
201
        $formBuilder->add('foo');
202
    }
203
204
    public function updateMetadata(MediaInterface $media, $force = false): void
205
    {
206
        // TODO: Implement updateMetadata() method.
207
    }
208
209
    protected function doTransform(MediaInterface $media): void
210
    {
211
        // TODO: Implement doTransform() method.
212
    }
213
}
214