Issues (31)

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.

Model/UpdateByPatchs.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
namespace kujaff\VersionsBundle\Model;
4
5
use kujaff\VersionsBundle\Entity\BundleVersion;
6
use Symfony\Component\Finder\Finder;
7
use kujaff\VersionsBundle\Entity\Version;
8
use kujaff\VersionsBundle\Entity\Patch;
9
10
/**
11
 * Search for patchs in Patch
12
 * CurrentClass.php
13
 *     - Patch
14
 *         - Version_X_Y_Z
15
 *             - PatchYYYYmmDDhhIIss.php
16
 *         - Current
17
 *             - PatchYYYYmmDDhhIIss.php
18
 */
19
trait UpdateByPatchs
20
{
21
22
    /**
23
     * Sort dirs with version in name
24
     *
25
     * @param string $versionA
26
     * @param string  $versionB
27
     * @return int
28
     */
29
    private function compareDirVersion(&$versionA, &$versionB)
30
    {
31
        return $this->container->get('versions.version')->compare($versionA, $versionB);
0 ignored issues
show
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
34
    /**
35
     * Find patch files in good order
36
     *
37
     * @param string $dir
38
     * @return array
39
     */
40
    protected function findPatchsFiles($dir)
41
    {
42
        if (is_dir($dir) === false) {
43
            return array();
44
        }
45
46
        $finderFiles = new Finder();
47
        $finderFiles->files();
48
        $finderFiles->in($dir);
49
        $finderFiles->name('Patch*.php');
50
        $finderFiles->sortByName();
51
        // we want first patch in first, but sortByName sort first patch in last
52
        $return = array();
53
        foreach ($finderFiles as $file) {
54
            $return = array_merge($return, array($file));
55
        }
56
        return $return;
57
    }
58
59
    /**
60
     * Call update
61
     *
62
     * @param string $className Fully qualified class name
63
     * @param BundleVersion $bundleVersion
64
     */
65
    protected function callUpdate($className, BundleVersion $bundleVersion)
66
    {
67
        $update = new $className();
68
        $update->update($bundleVersion);
69
    }
70
71
    /**
72
     * Try to patch all older versions, in Patch\Version_X_Y_Z dirs
73
     *
74
     * @param BundleVersion $bundleVersion
75
     * @return Version
76
     */
77
    protected function patchOldVersions(BundleVersion $bundleVersion)
78
    {
79
        $reflection = new \ReflectionClass(get_called_class());
80
        $fileInfos = new \SplFileInfo($reflection->getFileName());
81
        $patchPath = $fileInfos->getPath() . DIRECTORY_SEPARATOR . 'Patch';
82
83
        // directory doesn't exists, no patch to call
84
        if (is_dir($patchPath) === false) {
85
            return $bundleVersion->getInstalledVersion();
86
        }
87
88
        // dirs like Update\Version_X_Y_Z
89
        $finderVersions = new Finder();
90
        $finderVersions->directories()->in($patchPath)->name('Version_*')->sortByName();
91
        $dirsVersions = array();
92
        foreach ($finderVersions as $dir) {
93
            $dirsVersions[] = str_replace('_', '.', substr($dir->getFilename(), 8));
94
        }
95
        usort($dirsVersions, array($this, 'compareDirVersion'));
96
97
        // now that we have dirs in right order, let's find patch files
98
        $return = $bundleVersion->getInstalledVersion();
99
        foreach ($dirsVersions as $dir) {
100
            $files = $this->findPatchsFiles($patchPath . DIRECTORY_SEPARATOR . 'Version_' . str_replace('.', '_', $dir));
101
            foreach ($files as $file) {
102
                $className = $reflection->getNamespaceName() . '\\Patch\\Version_' . str_replace('.', '_', $dir) . '\\' . $file->getBasename('.' . $file->getExtension());
103
                $this->callUpdate($className, $bundleVersion);
104
            }
105
106
            $return = new Version($dir);
107
        }
108
109
        return $return;
110
    }
111
112
    /**
113
     * Try to patch current versions, in Patch\Current dir
114
     *
115
     * @param BundleVersion $bundleVersion
116
     * @return Version
117
     */
118
    protected function patchCurrentVersion(BundleVersion $bundleVersion)
119
    {
120
        $reflection = new \ReflectionClass(get_called_class());
121
        $fileInfos = new \SplFileInfo($reflection->getFileName());
122
        $manager = $this->container->get('doctrine')->getManager();
123
        $patchPath = $fileInfos->getPath() . DIRECTORY_SEPARATOR . 'Patch' . DIRECTORY_SEPARATOR . 'Current';
124
        $files = $this->findPatchsFiles($patchPath);
125
126
        foreach ($files as $file) {
127
            $className = $reflection->getNamespaceName() . '\\Patch\\Current\\' . $file->getBasename('.' . $file->getExtension());
128
            $this->callUpdate($className, $bundleVersion);
129
130
            // insert this patch into Patch, to know that we have already called it
131
            $patch = new Patch();
132
            $patch->setBundle($bundleVersion->getName());
133
            $patch->setDate(new \DateTime());
134
            $manager->persist($patch);
135
            $manager->flush();
136
        }
137
    }
138
139
    /**
140
     * Update bundle
141
     *
142
     * @param BundleVersion $bundleVersion
143
     * @return Version
144
     */
145
    public function update(BundleVersion $bundleVersion)
146
    {
147
        $return = $this->patchOldVersions($bundleVersion);
148
        $this->patchCurrentVersion($bundleVersion);
149
150
        return $return;
151
    }
152
}
153