Issues (71)

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.

Controller/AdminBlockController.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 Alpixel\Bundle\CMSBundle\Controller;
4
5
use Sonata\AdminBundle\Controller\CRUDController as Controller;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
10
11
class AdminBlockController extends Controller
12
{
13
    private $_cmsParameter = 'alpixel_cms.blocks';
14
    private $_cmsContentParameter = null;
15
    private $_blockDefaultClass = 'Alpixel\Bundle\CMSBundle\Entity\Block';
16
17
    public function editContentAction()
18
    {
19
        $object = $this->admin->getSubject();
20
        if (!$object) {
21
            throw new NotFoundHttpException(sprintf('unable to find the object'));
22
        }
23
24
        $instanceAdmin = $this->admin->getConfigurationPool()->getAdminByClass(get_class($object));
25
        if ($instanceAdmin !== null) {
26
            return $this->redirect($instanceAdmin->generateUrl('edit', ['id' => $object->getId()]));
27
        }
28
29
        throw new NotFoundHttpException(sprintf('unable to find a class admin for the %s class', get_class($content)));
30
    }
31
32
    public function listAction(Request $request = null)
33
    {
34
        if (false === $this->admin->isGranted('LIST')) {
35
            throw new AccessDeniedException();
36
        }
37
38
        $this->getInstancesAdmin();
39
        // set the theme for the current Admin Form
40
        $datagrid = $this->admin->getDatagrid();
41
        $formView = $datagrid->getForm()->createView();
42
        $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
43
44
        return $this->render($this->admin->getTemplate('list'), [
45
            'action'         => 'list',
46
            'cmsContentType' => $this->getCMSParameter(),
47
            'form'           => $formView,
48
            'datagrid'       => $datagrid,
49
            'csrf_token'     => $this->getCsrfToken('sonata.batch'),
50
        ], null, $request);
51
    }
52
53
    /**
54
     *  Set instances of admin in $_cmsContentParameter.
55
     */
56
    protected function getInstancesAdmin()
57
    {
58
        foreach ($this->getCMSParameter() as $key => $value) {
59
            if ($this->checkRolesCMS($value)) {
60
                $instanceAdmin = $this->admin->getConfigurationPool()->getAdminByClass($value['class']);
61
                if ($instanceAdmin !== null) {
62
                    $this->_cmsContentParameter[$key]['admin'] = $instanceAdmin;
63
                }
64
            }
65
        }
66
    }
67
68
    /**
69
     * @param $role array Role in cms.yml
70
     *
71
     * Check role define in different parameter of block or content_types cms.yml
72
     */
73
    protected function checkRolesCMS(array $role)
74
    {
75
        $user = $this->getUser();
76
77
        if (!$user) {
78
            throw new NotFoundHttpException(sprintf('unable to find user'));
79
        }
80
81
        if (!array_key_exists('role', $role) || in_array($user->getRoles()[0], $role['role'])) {
82
            return true;
83
        }
84
85
        return false;
86
    }
87
88
    /**
89
     * Get content in cms.yml and set in $_cmsParameter.
90
     *
91
     * @return content of cms.yml
92
     */
93
    protected function getCMSParameter()
94
    {
95
        if ($this->_cmsContentParameter !== null) {
96
            return $this->_cmsContentParameter;
97
        }
98
99
        $this->_cmsContentParameter = $this->container->getParameter($this->_cmsParameter);
100
101
        return $this->_cmsContentParameter;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    protected function redirectTo($object)
108
    {
109
        $request = $this->getRequest();
110
111
        $url = $backToNodeList = false;
112
        $instanceAdmin = $this->admin->getConfigurationPool()->getInstance('alpixel_cms.admin.block');
113
114 View Code Duplication
        if (null !== $request->get('btn_update_and_list') || null !== $request->get('btn_create_and_list')) {
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...
115
            $backToNodeList = true;
116
        }
117
118 View Code Duplication
        if (null !== $request->get('btn_create_and_create')) {
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...
119
            $params = [];
120
            if ($this->admin->hasActiveSubClass()) {
121
                $params['subclass'] = $request->get('subclass');
122
            }
123
            $url = $this->admin->generateUrl('create', $params);
124
        }
125
126
        if ($this->getRestMethod() === 'DELETE') {
127
            $backToNodeList = true;
128
        }
129
130 View Code Duplication
        if (!$url) {
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...
131
            foreach (['edit', 'show'] as $route) {
132
                if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) {
133
                    $url = $this->admin->generateObjectUrl($route, $object);
134
                    break;
135
                }
136
            }
137
        }
138
139
        if ($backToNodeList || !$url) {
140
            $url = $instanceAdmin->generateUrl('list');
141
        }
142
143
        return new RedirectResponse($url);
144
    }
145
}
146