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/ApplyAclCommand.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 Kunstmaan\AdminBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Kunstmaan\AdminBundle\Entity\AclChangeset;
7
use Kunstmaan\UtilitiesBundle\Helper\Shell\Shell;
8
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Kunstmaan\AdminBundle\Service\AclManager;
12
13
/**
14
 * Symfony CLI command to apply the {@link AclChangeSet} with status {@link AclChangeSet::STATUS_NEW} to their entities
15
 *
16
 * @final since 5.1
17
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
18
 */
19
class ApplyAclCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    /**
22
     * @var EntityManager
23
     */
24
    private $em = null;
25
26
    /**
27
     * @var Shell
28
     */
29
    private $shellHelper = null;
30
31
    /** @var AclManager */
32
    private $aclManager = null;
33
34
    public function __construct(/*AclManager*/ $aclManager = null, EntityManagerInterface $em = null, Shell $shellHelper = null)
35
    {
36
        parent::__construct();
37
38 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...
39
            @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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
40
41
            $this->setName(null === $aclManager ? 'kuma:acl:apply' : $aclManager);
42
43
            return;
44
        }
45
46
        $this->aclManager = $aclManager;
47
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
It seems like $em can also be of type object<Doctrine\ORM\EntityManagerInterface>. However, the property $em is declared as type object<Kunstmaan\AdminBu...\Command\EntityManager>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
48
        $this->shellHelper = $shellHelper;
49
    }
50
51
    /**
52
     * Configures the command.
53
     */
54
    protected function configure()
55
    {
56
        parent::configure();
57
58
        $this->setName('kuma:acl:apply')
59
             ->setDescription('Apply ACL changeset.')
60
             ->setHelp('The <info>kuma:acl:apply</info> can be used to apply an ACL changeset recursively, changesets are fetched from the database.');
61
    }
62
63
    /**
64
     * Apply the {@link AclChangeSet} with status {@link AclChangeSet::STATUS_NEW} to their entities
65
     *
66
     * @param InputInterface  $input  The input
67
     * @param OutputInterface $output The output
68
     *
69
     * @return int
70
     */
71
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73
        if (null === $this->aclManager) {
74
            $this->aclManager = $this->getContainer()->get('kunstmaan_admin.acl.manager');
75
        }
76
        if (null === $this->em) {
77
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
78
        }
79
        if (null === $this->shellHelper) {
80
            $this->shellHelper = $this->getContainer()->get('kunstmaan_utilities.shell');
81
        }
82
83
        // Check if another ACL apply process is currently running & do nothing if it is
84
        if ($this->isRunning()) {
85
            return 0;
86
        }
87
88
        $this->aclManager->applyAclChangesets();
89
90
        return 0;
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    private function isRunning()
97
    {
98
        // Check if we have records in running state, if so read PID & check if process is active
99
        /* @var AclChangeset $runningAclChangeset */
100
        $runningAclChangeset = $this->em->getRepository(AclChangeset::class)->findRunningChangeset();
101
        // Found running process, check if PID is still running
102
        if (!\is_null($runningAclChangeset) && !$this->shellHelper->isRunning($runningAclChangeset->getPid())) {
103
            // PID not running, process probably failed...
104
            $runningAclChangeset->setStatus(AclChangeset::STATUS_FAILED);
105
            $this->em->persist($runningAclChangeset);
106
            $this->em->flush();
107
        }
108
109
        return false;
110
    }
111
}
112