Issues (66)

Security Analysis    no request data  

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.

src/Actions/Setting.php (5 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 namespace Comodojo\Installer\Actions;
2
3
use \Comodojo\Exception\InstallerException;
4
use \Exception;
5
6
/**
7
 *
8
 *
9
 * @package     Comodojo Framework
10
 * @author      Marco Giovinazzi <[email protected]>
11
 * @author      Marco Castiello <[email protected]>
12
 * @license     GPL-3.0+
13
 *
14
 * LICENSE:
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28
 */
29
30
class Setting extends AbstractAction {
31
32 View Code Duplication
    public function install($package_name, $package_extra) {
0 ignored issues
show
This method seems to be duplicated in 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...
33
34
        $io = $this->getIO();
35
36
        $io->write("<info>>>> Installing setting from package ".$package_name."</info>");
37
38
        foreach ($package_extra as $setting => $value) {
39
40
            $this->addSetting($io, $package_name, $setting, $value);
41
42
        }
43
44
    }
45
46 View Code Duplication
    public function update($package_name, $initial_extra, $target_extra) {
0 ignored issues
show
This method seems to be duplicated in 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...
47
48
        $io = $this->getIO();
49
50
        $io->write("<info>>>> Updating setting from package ".$package_name."</info>");
51
52
        $old_settings = array_keys($initial_extra);
53
        
54
        $new_settings = array_keys($target_extra);
55
        
56
        $uninstall = array_diff($old_settings, $new_settings);
57
58
        $install = array_diff($new_settings, $old_settings);
59
60
        $update = array_intersect($old_settings, $new_settings);
61
        
62
        foreach ( $uninstall as $setting ) {
63
            
64
            $this->removeSetting($io, $package_name, $setting, $initial_extra[$setting]);
65
            
66
        }
67
        
68
        foreach ( $install as $setting ) {
69
            
70
            $this->addSetting($io, $package_name, $setting, $target_extra[$setting]);
71
            
72
        }
73
        
74
        foreach ( $update as $setting ) {
75
            
76
            $this->updateSetting($io, $package_name, $setting, $initial_extra[$setting], $target_extra[$setting]);
77
            
78
        }
79
80
    }
81
82 View Code Duplication
    public function uninstall($package_name, $package_extra) {
0 ignored issues
show
This method seems to be duplicated in 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...
83
84
        $io = $this->getIO();
85
86
        $io->write("<info>>>> Removing setting from package ".$package_name."</info>");
87
88
        foreach ($package_extra as $setting => $value) {
89
90
            $this->addSetting($io, $package_name, $setting, $value);
91
92
        }
93
94
    }
95
96
    private function addSetting($io, $package_name, $setting, $value) {
97
        
98
        try {
99
100
            if ( !self::validateSetting($value) ) throw new InstallerException('Skipping invalid setting '.$setting.' in '.$package_name);
101
102
            $this->getPackageInstaller()->settings()->add($package_name, $setting, $value);
103
104
            $io->write(" <info>+</info> added setting ".$setting);
105
106
        } catch (Exception $e) {
107
108
            $io->write('<error>Error processing setting: '.$e->getMessage().'</error>');
109
110
        }
111
        
112
    }
113
    
114 View Code Duplication
    private function removeSetting($io, $package_name, $setting, $value) {
0 ignored issues
show
This method seems to be duplicated in 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
        
116
        try {
117
118
            if ( !self::validateSetting($value) ) throw new InstallerException('Skipping invalid setting '.$setting.' in '.$package_name);
119
120
            $id = $this->getPackageInstaller()->settings()->getByName($setting)->getId();
121
122
            $this->getPackageInstaller()->settings()->delete($id);
123
124
            $io->write(" <comment>-</comment> removed setting ".$setting);
125
126
        } catch (Exception $e) {
127
128
            $io->write('<error>Error processing setting: '.$e->getMessage().'</error>');
129
130
        }
131
        
132
    }
133
    
134
    private function updateSetting($io, $package_name, $setting, $old_value, $new_value) {
135
        
136
        try {
137
138
            if ( !self::validateSetting($value) ) throw new InstallerException('Skipping invalid setting '.$setting.' in '.$package_name);
0 ignored issues
show
The variable $value does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
139
140
            $old = $this->getPackageInstaller()->settings()->getByName($setting);
141
            
142
            if ( $old->getValue() == $old_value ) {
143
                
144
                $this->getPackageInstaller()->settings()->update($old->getId(), $package_name, $setting, $new_value);
145
                
146
                $io->write(" <comment>~</comment> updated setting ".$setting);
147
                
148
            } else if ( $io->askConfirmation("Replace modified setting ".$setting."?", false) === true ) {
149
                
150
                $this->getPackageInstaller()->settings()->update($old->getId(), $package_name, $setting, $new_value);
151
                
152
                $io->write(" <comment>~</comment> updated setting ".$setting);
153
                
154
            } else {
155
                
156
                $io->write(" <comment>x</comment> modified setting ".$setting." not replaced");
157
                
158
            }
159
160
        } catch (Exception $e) {
161
162
            $io->write('<error>Error processing setting: '.$e->getMessage().'</error>');
163
164
        }
165
        
166
    }
167
168
    private static function validateSetting($value) {
169
170
        return is_scalar($value);
171
172
    }
173
174
}
175