Issues (116)

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.

AppBundle/Command/Admin/RefreshMenuCommand.php (1 issue)

Labels
Severity

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
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\AppBundle\Command\Admin;
14
15
use Doctrine\ORM\EntityManager;
16
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17
use Symfony\Component\Config\Util\XmlUtils;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Filesystem\Filesystem;
21
use Symfony\Component\Finder\Finder;
22
use Symfony\Component\Finder\SplFileInfo;
23
use Symfony\Component\HttpKernel\KernelInterface;
24
use WellCommerce\Bundle\AppBundle\Entity\AdminMenu;
25
use WellCommerce\Bundle\CoreBundle\Doctrine\Repository\RepositoryInterface;
26
27
/**
28
 * Class RefreshMenuCommand
29
 *
30
 * @author  Adam Piotrowski <[email protected]>
31
 */
32
final class RefreshMenuCommand extends ContainerAwareCommand
33
{
34
    /**
35
     * @var EntityManager
36
     */
37
    private $em;
38
    
39
    /**
40
     * @var RepositoryInterface
41
     */
42
    private $repository;
43
    
44
    protected function configure()
45
    {
46
        $this->setDescription('Refreshes the admin menu');
47
        $this->setName('wellcommerce:admin:menu-refresh');
48
    }
49
    
50
    protected function initialize(InputInterface $input, OutputInterface $output)
51
    {
52
        $this->em         = $this->getContainer()->get('doctrine.helper')->getEntityManager();
53
        $this->repository = $this->getContainer()->get('admin_menu.repository');
54
    }
55
    
56
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        $files = $this->locateFiles();
59
        
60
        foreach ($files as $file) {
0 ignored issues
show
The expression $files of type array|object<Symfony\Com...ent\Finder\SplFileInfo> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
61
            $output->writeln(sprintf('<info>Reimporting %s</info>', $file->getRealPath()));
62
            $this->importFile($file);
63
        }
64
    }
65
    
66
    private function importFile(SplFileInfo $file)
67
    {
68
        $xml = $this->parseFile($file);
69
        foreach ($xml->documentElement->getElementsByTagName('item') as $item) {
70
            $dom = simplexml_import_dom($item);
71
            $this->addMenuItem($dom);
72
        }
73
    }
74
    
75
    protected function addMenuItem(\SimpleXMLElement $xml)
76
    {
77
        $item   = $this->repository->findOneBy(['identifier' => (string)$xml->identifier]);
78
        $parent = $this->repository->findOneBy(['identifier' => (string)$xml->parent]);
79
        
80
        if (!$item instanceof AdminMenu) {
81
            $item = new AdminMenu();
82
        }
83
        
84
        $item->setCssClass((string)$xml->css_class);
85
        $item->setIdentifier((string)$xml->identifier);
86
        $item->setName((string)$xml->name);
87
        $item->setRouteName((string)$xml->route_name);
88
        $item->setHierarchy((int)$xml->hierarchy);
89
        $item->setParent($parent);
90
        
91
        $this->em->persist($item);
92
        $this->em->flush();
93
    }
94
    
95
    /**
96
     * @return array|SplFileInfo
97
     */
98
    private function locateFiles(): array
99
    {
100
        $filesystem = new Filesystem();
101
        $files      = [];
102
        
103
        foreach ($this->getKernel()->getBundles() as $bundle) {
104
            $directory = $bundle->getPath() . '/Resources/config/admin_menu';
105
            if (false === $filesystem->exists($directory)) {
106
                continue;
107
            }
108
            
109
            $finder = new Finder();
110
            
111
            /** @var SplFileInfo $file */
112
            foreach ($finder->files()->name('*.xml')->in($directory) as $file) {
113
                $files[] = $file;
114
            }
115
        }
116
        
117
        return $files;
118
    }
119
    
120
    private function parseFile(SplFileInfo $file): \DOMDocument
121
    {
122
        return XmlUtils::loadFile($file->getRealPath());
123
    }
124
    
125
    private function getKernel(): KernelInterface
126
    {
127
        return $this->getContainer()->get('kernel');
128
    }
129
}
130