Issues (1704)

Branch: master

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.

Bundle/MediaBundle/Controller/MediaController.php (4 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 Victoire\Bundle\MediaBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Victoire\Bundle\CoreBundle\Controller\VictoireAlertifyControllerTrait;
13
use Victoire\Bundle\MediaBundle\Entity\Folder;
14
use Victoire\Bundle\MediaBundle\Entity\Media;
15
use Victoire\Bundle\MediaBundle\Form\BulkUploadType;
16
use Victoire\Bundle\MediaBundle\Helper\BulkUploadHelper;
17
18
/**
19
 * MediaController.
20
 *
21
 * @Route("/victoire-media/media")
22
 */
23
class MediaController extends Controller
24
{
25
    use VictoireAlertifyControllerTrait;
26
27
    /**
28
     * @param Request $request
29
     * @param int     $mediaId
30
     *
31
     * @throws \Doctrine\ORM\EntityNotFoundException
32
     *
33
     * @return Response
34
     * @Route("/{mediaId}", requirements={"mediaId" = "\d+"}, name="VictoireMediaBundle_media_show", options={"expose"=true})
35
     */
36
    public function showAction(Request $request, $mediaId)
37
    {
38
        $em = $this->getDoctrine()->getManager();
39
40
        /* @var \Victoire\Bundle\MediaBundle\Entity\Media $media */
41
        $media = $em->getRepository('VictoireMediaBundle:Media')->getMedia($mediaId);
42
        $folder = $media->getFolder();
43
44
        /* @var \Victoire\Bundle\MediaBundle\Helper\MediaManager $mediaManager */
45
        $mediaManager = $this->get('victoire_media.media_manager');
46
        $handler = $mediaManager->getHandler($media);
47
        $helper = $handler->getFormHelper($media);
48
49
        $form = $this->createForm($handler->getFormType(), $helper);
50
51 View Code Duplication
        if ('POST' == $request->getMethod()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            $form->handleRequest($request);
53
            if ($form->isValid()) {
54
                $media = $helper->getMedia();
55
                $em->getRepository('VictoireMediaBundle:Media')->save($media);
56
57
                return new RedirectResponse($this->generateUrl('VictoireMediaBundle_media_show', ['mediaId'  => $media->getId()]));
58
            }
59
        }
60
        $showTemplate = $mediaManager->getHandler($media)->getShowTemplate($media);
61
62
        return $this->render($showTemplate, [
63
                'handler'       => $handler,
64
                'mediamanager'  => $this->get('victoire_media.media_manager'),
65
                'editform'      => $form->createView(),
66
                'media'         => $media,
67
                'helper'        => $helper,
68
                'folder'        => $folder, ]);
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 16.
Loading history...
69
    }
70
71
    /**
72
     * @param int $mediaId
73
     *
74
     * @Route("/delete/{mediaId}", requirements={"mediaId" = "\d+"}, name="VictoireMediaBundle_media_delete")
75
     *
76
     * @return RedirectResponse
77
     */
78
    public function deleteAction($mediaId)
79
    {
80
        $em = $this->getDoctrine()->getManager();
81
82
        /* @var \Victoire\Bundle\MediaBundle\Entity\Media $media */
83
        $media = $em->getRepository('VictoireMediaBundle:Media')->getMedia($mediaId);
84
        $medianame = $media->getName();
85
        $folder = $media->getFolder();
86
87
        $em->getRepository('VictoireMediaBundle:Media')->delete($media);
88
89
        $this->congrat('Entry \''.$medianame.'\' has been deleted!');
90
91
        return new RedirectResponse($this->generateUrl('VictoireMediaBundle_folder_show', ['folderId'  => $folder->getId()]));
92
    }
93
94
    /**
95
     * @param Request $request
96
     * @param int     $folderId
97
     *
98
     * @throws \Doctrine\ORM\EntityNotFoundException
99
     *
100
     * @return array|RedirectResponse
101
     * @Route("bulkupload/{folderId}", requirements={"folderId" = "\d+"}, name="VictoireMediaBundle_media_bulk_upload")
102
     * @Method({"GET", "POST"})
103
     * @Template()
104
     */
105
    public function bulkUploadAction(Request $request, $folderId)
106
    {
107
        $em = $this->getDoctrine()->getManager();
108
109
        /* @var \Victoire\Bundle\MediaBundle\Entity\Folder $folder */
110
        $folder = $em->getRepository('VictoireMediaBundle:Folder')->getFolder($folderId);
111
112
        $helper = new BulkUploadHelper();
113
114
        $form = $this->createForm(BulkUploadType::class, $helper, ['accept' => '*/*']);
115
116
        if ('POST' == $request->getMethod()) {
117
            $form->handleRequest($request);
118
            if ($form->isValid()) {
119
                foreach ($helper->getFiles() as $file) {
120
                    /* @var \Victoire\Bundle\MediaBundle\Entity\Media $media */
121
                    $media = $this->get('victoire_media.media_manager')->getHandler($file)->createNew($file);
122
                    $media->setFolder($folder);
123
                    $em->getRepository('VictoireMediaBundle:Media')->save($media);
124
                }
125
126
                $this->congrat('New entry has been uploaded');
127
128
                return new RedirectResponse($this->generateUrl('VictoireMediaBundle_folder_show', ['folderId'  => $folder->getId()]));
129
            }
130
        }
131
132
        $formView = $form->createView();
133
        $filesfield = $formView->children['files'];
134
        $filesfield->vars = array_replace($filesfield->vars, [
135
            'full_name' => 'mediabundle_bulkupload[files][]',
136
        ]);
137
138
        return [
139
            'form'      => $formView,
140
            'folder'    => $folder,
141
        ];
142
    }
143
144
    /**
145
     * @param Request $request
146
     * @param int     $folderId
147
     *
148
     * @throws \Doctrine\ORM\EntityNotFoundException
149
     *
150
     * @return Response
151
     * @Route("drop/{folderId}", requirements={"folderId" = "\d+"}, name="VictoireMediaBundle_media_drop_upload")
152
     * @Method({"GET", "POST"})
153
     */
154
    public function dropAction(Request $request, $folderId)
155
    {
156
        $em = $this->getDoctrine()->getManager();
157
158
        /* @var \Victoire\Bundle\MediaBundle\Entity\Folder $folder */
159
        $folder = $em->getRepository('VictoireMediaBundle:Folder')->getFolder($folderId);
160
161
        $drop = null;
0 ignored issues
show
$drop 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...
162
        if (isset($request->files) && array_key_exists('files', $request->files)) {
163
            $drop = $request->files->get('files');
164
        } else {
165
            $drop = $request->get('text');
166
        }
167
        $media = $this->get('victoire_media.media_manager')->createNew($drop);
168
        if ($media) {
169
            $media->setFolder($folder);
170
            $em->getRepository('VictoireMediaBundle:Media')->save($media);
171
172
            return new Response(json_encode(['status' => 'File was uploaded successfuly!']));
173
        }
174
175
        $request->getSession()->getFlashBag()->add('notice', 'Could not recognize what you dropped!');
176
177
        return new Response(json_encode(['status' => 'Could not recognize anything!']));
178
    }
179
180
    /**
181
     * @param Request $request
182
     * @param int     $folderId The folder id
183
     * @param string  $type     The type
184
     *
185
     * @return array|RedirectResponse
186
     * @Route("create/{folderId}/{type}", requirements={"folderId" = "\d+", "type" = ".+"}, name="VictoireMediaBundle_media_create")
187
     * @Method({"GET", "POST"})
188
     * @Template()
189
     */
190
    public function createAction(Request $request, $folderId, $type)
191
    {
192
        return $this->createAndRedirect($request, $folderId, $type, 'VictoireMediaBundle_folder_show');
193
    }
194
195
    /**
196
     * @param Request $request
197
     * @param int     $folderId The folder id
198
     * @param string  $type     The type
199
     *
200
     * @return array|RedirectResponse
201
     * @Route("create/modal/{folderId}/{type}", requirements={"folderId" = "\d+", "type" = ".+"}, name="VictoireMediaBundle_media_modal_create")
202
     * @Method({"GET", "POST"})
203
     * @Template()
204
     */
205
    public function createModalAction(Request $request, $folderId, $type)
206
    {
207
        return $this->createAndRedirect($request, $folderId, $type, 'VictoireMediaBundle_chooser_show_folder');
208
    }
209
210
    /**
211
     * @param Request $request
212
     * @param int     $folderId    The folder Id
213
     * @param string  $type        The type
214
     * @param string  $redirectUrl The url where we want to redirect to on success
215
     *
216
     * @return array
217
     */
218
    private function createAndRedirect(Request $request, $folderId, $type, $redirectUrl)
219
    {
220
        $em = $this->getDoctrine()->getManager();
221
222
        /* @var \Victoire\Bundle\MediaBundle\Entity\Folder $folder */
223
        $folder = $em->getRepository('VictoireMediaBundle:Folder')->getFolder($folderId);
224
225
        /* @var \Victoire\Bundle\MediaBundle\Helper\MediaManager $mediaManager */
226
        $mediaManager = $this->get('victoire_media.media_manager');
227
        $handler = $mediaManager->getHandlerForType($type);
228
        $media = new Media();
229
        $helper = $handler->getFormHelper($media);
230
231
        $options = array_merge([
232
            'action' => $this->generateUrl('VictoireMediaBundle_media_create', ['folderId' => $folderId, 'type' => $type]),
233
        ], $handler->getFormTypeOptions());
234
        $form = $this->createForm($handler->getFormType(), $helper, $options);
235
236
        if ($request->isMethod('POST')) {
237
            $form->handleRequest($request);
238 View Code Duplication
            if ($form->isValid()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
                $media = $helper->getMedia();
240
                $media->setFolder($folder);
241
                $em->getRepository('VictoireMediaBundle:Media')->save($media);
242
243
                $this->congrat('Media \''.$media->getName().'\' has been created!');
244
245
                return new RedirectResponse($this->generateUrl($redirectUrl, ['folderId' => $folder->getId()]));
246
            }
247
        }
248
249
        return [
250
            'type'   => $type,
251
            'form'   => $form->createView(),
252
            'folder' => $folder,
253
        ];
254
    }
255
}
256