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.

Kunstmaan/AdminBundle/Command/UpdateAclCommand.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\AdminBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Kunstmaan\AdminBundle\Service\AclManager;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ChoiceQuestion;
11
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
12
13
/**
14
 * Permissions update of ACL entries for all nodes for given role.
15
 *
16
 * @final since 5.1
17
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
18
 */
19
class UpdateAclCommand extends ContainerAwareCommand
20
{
21
    /** @var AclManager */
22
    private $aclManager;
23
24
    /** @var PermissionMapInterface */
25
    private $permissionMap;
26
27
    /** @var EntityManagerInterface */
28
    private $em;
29
30
    /** @var array */
31
    private $roles;
32
33
    public function __construct(/*AclManager*/ $aclManager = null, EntityManagerInterface $em = null, PermissionMapInterface $permissionMap = null, array $roles = null)
34
    {
35
        parent::__construct();
36
37 View Code Duplication
        if (!$aclManager instanceof AclManager) {
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...
38
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);
39
40
            $this->setName(null === $aclManager ? 'kuma:acl:update' : $aclManager);
41
42
            return;
43
        }
44
45
        $this->aclManager = $aclManager;
46
        $this->em = $em;
47
        $this->permissionMap = $permissionMap;
48
        $this->roles = $roles;
0 ignored issues
show
Documentation Bug introduced by
It seems like $roles can be null. However, the property $roles is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function configure()
55
    {
56
        parent::configure();
57
58
        $this->setName('kuma:acl:update')
59
            ->setDescription('Permissions update of ACL entries for all nodes for given role')
60
            ->setHelp('The <info>kuma:acl:update</info> will update ACL entries for the nodes of the current project' .
61
                'with given role and permissions');
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69
        $helper = $this->getHelper('question');
70
        if (null === $this->aclManager) {
71
            $this->aclManager = $this->getContainer()->get('kunstmaan_admin.acl.manager');
72
        }
73
        if (null === $this->em) {
74
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
75
        }
76
        if (null === $this->permissionMap) {
77
            $this->permissionMap = $this->getContainer()->get('security.acl.permission.map');
78
        }
79
        if (null === $this->roles) {
80
            $this->roles = $this->getContainer()->getParameter('security.role_hierarchy.roles');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getContainer()->g....role_hierarchy.roles') of type * is incompatible with the declared type array of property $roles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81
        }
82
83
        // Select Role
84
        $question = new ChoiceQuestion('Select role', array_keys($this->roles));
85
        $question->setErrorMessage('Role %s is invalid.');
86
        $role = $helper->ask($input, $output, $question);
87
88
        // Select Permission(s)
89
        $permissionMap = $this->permissionMap;
90
        $question = new ChoiceQuestion('Select permissions(s) (separate by ",")',
91
            $permissionMap->getPossiblePermissions());
92
        $question->setMultiselect(true);
93
        $mask = array_reduce($helper->ask($input, $output, $question), function ($a, $b) use ($permissionMap) {
94
            return $a | $permissionMap->getMasks($b, null)[0];
95
        }, 0);
96
97
        // Fetch all nodes & grant access
98
        $nodes = $this->em->getRepository('KunstmaanNodeBundle:Node')->findAll();
99
100
        $this->aclManager->updateNodesAclToRole($nodes, $role, $mask);
101
102
        $output->writeln(\count($nodes) . ' nodes processed.');
103
104
        return 0;
105
    }
106
}
107