Issues (102)

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.

src/Controller/CLI/Itemdata.php (2 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
 * Created by PhpStorm.
4
 * User: mhaase
5
 * Date: 28.06.2017
6
 * Time: 10:26
7
 */
8
9
namespace HaaseIT\HCSF\Controller\CLI;
10
11
use Zend\ServiceManager\ServiceManager;
12
13
class Itemdata
14
{
15
    /**
16
     * @var ServiceManager
17
     */
18
    protected $serviceManager;
19
20
    /**
21
     * @var \Doctrine\DBAL\Connection
22
     */
23
    protected $dbal;
24
25
    /**
26
     * @var array
27
     */
28
    protected $items;
29
30
    /**
31
     * @var array
32
     */
33
    protected $itemschanged = [];
34
35
    public function __construct(ServiceManager $serviceManager)
36
    {
37
        $this->serviceManager = $serviceManager;
38
        $this->dbal = $serviceManager->get('dbal');
39
    }
40
41
    public function getItems()
42
    {
43
        return $this->items;
44
    }
45
46
    public function fetchItems()
47
    {
48
        $querybuilder = $this->dbal->createQueryBuilder();
49
50
        $querybuilder
51
            ->select('itm_id', 'itm_data')
52
            ->from('item_base')
53
        ;
54
55
        $stmt = $querybuilder->execute();
56
57
        $this->items = $stmt->fetchAll();
58
59
        $this->decodeItemData();
60
    }
61
62
    protected function decodeItemData()
63
    {
64
        foreach ($this->items as $key => $item) {
65
            if (empty($item['itm_data']) || ($itemdata = json_decode($item['itm_data'])) === null) {
66
                $itemdata = new \stdClass();
67
            }
68
            $this->items[$key]['itm_data'] = $itemdata;
69
        }
70
    }
71
72
    protected function encodeItemData()
73
    {
74
        foreach ($this->items as $key => $item) {
75
            $this->items[$key]['itm_data'] = json_encode($item['itm_data'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
76
        }
77
    }
78
79
    public function addDataWhere($field, $needle, $newfield, $content)
80
    {
81
        foreach ($this->items as $key => $item) {
82
            if ($needle !== false) {
83 View Code Duplication
                if (!empty($item['itm_data']->$field) && $item['itm_data']->$field == $needle) {
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...
84
                    $this->items[$key]['itm_data']->$newfield = $content;
85
                    $this->itemschanged[$key] = true;
86
                }
87
            } else {
88
                if (!empty($item['itm_data']->$field)) {
89
                    $this->items[$key]['itm_data']->$newfield = $content;
90
                    $this->itemschanged[$key] = true;
91
                }
92
            }
93
        }
94
    }
95
96
    // if $needls is set to false, existence of the field is enough to trigger removal
97
    public function removeDataWhere($field, $needle, $fieldtoremove)
98
    {
99
        foreach ($this->items as $key => $item) {
100
            if (!empty($item['itm_data']->$field)) {
101
                if ($needle) {
102 View Code Duplication
                    if ($item['itm_data']->$field == $needle && isset($item['itm_data']->$fieldtoremove)) {
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...
103
                        unset($this->items[$key]['itm_data']->$fieldtoremove);
104
                        $this->itemschanged[$key] = true;
105
                    }
106
                } else {
107
                    if (isset($item['itm_data']->$fieldtoremove)) {
108
                        unset($this->items[$key]['itm_data']->$fieldtoremove);
109
                        $this->itemschanged[$key] = true;
110
                    }
111
                }
112
            }
113
        }
114
    }
115
116
    public function writeItems()
117
    {
118
        $this->encodeItemData();
119
120
        foreach ($this->items as $key => $item) {
121
            if (!isset($this->itemschanged[$key])) {
122
                continue;
123
            }
124
            $querybuilder = $this->dbal->createQueryBuilder();
125
126
            $querybuilder
127
                ->update('item_base')
128
                ->set('itm_data', '?')
129
                ->setParameter(0, $item['itm_data'])
130
                ->where('itm_id = '.$item['itm_id'])
131
            ;
132
            echo 'updating item with itm_id: '.$item['itm_id'].PHP_EOL;
133
            $querybuilder->execute();
134
        }
135
    }
136
}