Issues (6)

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.

Controllers/Backend/WbmQueryManager.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
 * Query Manager
4
 * Copyright (c) Webmatch GmbH
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 */
16
17
use WbmQueryManager\Models\Query;
18
19
/**
20
 * Class Shopware_Controllers_Backend_WbmQueryManager
21
 */
22
class Shopware_Controllers_Backend_WbmQueryManager extends Shopware_Controllers_Backend_ExtJs {
23
24
    public function postDispatch()
25
    {
26
        if (
27
            $this->Request()->getActionName() === 'load' &&
28
            $this->container->get('config')->getByNamespace('WbmQueryManager', 'autocomplete')
29
        ) {
30
            $dbData = $this->container->getParameter('shopware.db');
31
            $sql = "SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ?";
32
            $tables = $this->container->get('shopware.db')->fetchAll(
33
                $sql,
34
                array($dbData['dbname']), \Zend_Db::FETCH_GROUP|\Zend_Db::FETCH_COLUMN
35
            );
36
            $columns = [];
37
            foreach ($tables as $table => $content) {
38
                foreach ($content as $column) {
39
                    $columns[] = array(
40
                        'caption' => $table . '.' . $column,
41
                        'value' => '`' . $table . '`.`' . $column . '`',
42
                        'meta' => 'Column'
43
                    );
44
                }
45
            }
46
            $hintOptions = json_encode(
47
                array_merge(
48
                    array_map(
49
                        function($tableName) {
50
                            return array(
51
                                'caption' => $tableName,
52
                                'value' => '`' . $tableName . '`',
53
                                'meta' => 'Table'
54
                            );
55
                        },
56
                        array_keys($tables)
57
                    ),
58
                    $columns
59
                )
60
            );
61
            $this->View()->hintOptions = $hintOptions;
62
            $this->View()->autocompleteActive = true;
63
        }
64
    }
65
    
66
    public function indexAction() 
67
    {
68
        $this->View()->loadTemplate("backend/wbm_query_manager/app.js");
69
    }
70
    
71
    public function listAction()
72
    {
73
        $id = $this->Request()->getParam('id', null);
74
75
        /** @var \Doctrine\ORM\QueryBuilder $qb */
76
        $qb = $this->container->get('models')->createQueryBuilder();
77
        $qb->select(
78
                array(
79
                    'query'
80
                )
81
            )
82
            ->from('WbmQueryManager\Models\Query', 'query');
83
        
84
        if(!empty($id)){
85
            $qb->where('query.id = :id')
86
                ->setParameter(':id', $id);
87
        } else {
88
            $qb->addOrderBy('query.name', 'ASC');
89
        }
90
91
        $data = $qb->getQuery()->getArrayResult();
92
        
93
        $this->View()->assign(
94
            array('success' => true, 'data' => $data)
95
        );
96
    }
97
    
98
    public function createAction() 
99
    {
100
        $params = $this->Request()->getPost();
101
        
102
        if($params['hasCronjob'] && empty($params['nextRun'])){
103
            $params['nextRun'] = new \DateTime();
104
        }
105
        
106
        $query = new Query();
107
        $query->fromArray($params);
108
109
        $this->container->get('models')->persist($query);
110
        $this->container->get('models')->flush();
111
112
        $this->View()->assign(
113
            array(
114
                'success' => true,
115
                'id' => $query->getId()
116
            )
117
        );
118
    }
119
120
    public function updateAction() 
121
    {
122
        $params = $this->Request()->getPost();
123
        $id = (int)$this->Request()->get('id');
124
        
125
        if($params['hasCronjob'] && empty($params['nextRun'])){
126
            $params['nextRun'] = new \DateTime();
127
        }
128
129
        /** @var Query $query */
130
        $query = $this->container->get('models')->getRepository('WbmQueryManager\Models\Query')->find($id);
131
        $query->fromArray($params);
132
133
        $this->container->get('models')->persist($query);
134
        $this->container->get('models')->flush();
135
        
136
        $this->View()->assign(
137
            array('success' => true)
138
        );
139
    }
140
    
141
    public function deleteAction() 
142
    {
143
        $id = (int)$this->Request()->get('id');
144
145
        /** @var Query $query */
146
        $query = $this->container->get('models')->getRepository('WbmQueryManager\Models\Query')->find($id);
147
148
        $this->container->get('models')->remove($query);
149
        $this->container->get('models')->flush();
150
        
151
        $this->View()->assign(
152
            array('success' => true)
153
        );
154
    }
155
    
156
    public function cloneAction() 
157
    {
158
        $id = (int)$this->Request()->get('id');
159
160
        /** @var Query $query */
161
        $query = $this->container->get('models')->getRepository('WbmQueryManager\Models\Query')->find($id);
162
163
        $query = clone $query;
164
        $query->setId(null);
165
        $query->setName('(Clone) ' . $query->getName());
0 ignored issues
show
Consider using $query->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
166
167
        $this->container->get('models')->persist($query);
168
        $this->container->get('models')->flush();
169
        
170
        $this->View()->assign(
171
            array('success' => true)
172
        );
173
    }
174
    
175
    public function runAction() 
176
    {
177
        $sql = $this->Request()->get('query');
178
        $download = $this->Request()->get('download');
179
        $rowsetKey = $this->Request()->get('rowset');
180
        
181
        try {
182
            /** @var \mysqli|\Zend_Db_Statement_Pdo $query */
183
            $query = $this->container->get('wbm_query_manager.db')->query($sql);
184
            $data = array();
185
            $i = 0;
186
187
            do {
188
                $data[$i]['rowsetKey'] = $i;
189
190
                if($this->container->get('wbm_query_manager.db')->getColumnCount($query)){
191
                    $records = $this->container->get('wbm_query_manager.db')->fetchAll($query);
192
                    $data[$i]['rowCount'] = $this->container->get('wbm_query_manager.db')->getRowCount($query);
193
194
                    if($download && $rowsetKey != $i){
195
                        $i++;
196
                        continue;
197
                    }
198
199
                    $recordFields = array_keys($records[0]);
200
                    $columns = array();
201
                    foreach($recordFields as $recordField){
202
                        $columns[] = array(
203
                            'header' => $recordField,
204
                            'dataIndex' => $recordField,
205
                            'flex' => 1
206
                        );
207
                    }
208
209
                    $data[$i]['fetchData'] = array(
210
                        'records' => $records,
211
                        'recordFields' => $recordFields,
212
                        'columns' => $columns
213
                    );
214
215
                    if($download){
216
                        $this->container->get('plugins')->Controller()->ViewRenderer()->setNoRender();
217
                        $now = new \DateTime();
218
                        $file = "query_" . $now->format('Y_m_d_h_i_s') . ".csv";
219
                        header("Content-Type: text/csv");
220
                        header("Content-Disposition: attachment; filename=\"$file\"");
221
222
                        $outputBuffer = fopen("php://output", 'w');
223 View Code Duplication
                        foreach(array_merge(array(0 => $recordFields),$records) as $val) {
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...
224
                            fputcsv($outputBuffer, $val, $this->container->get('config')->getByNamespace('WbmQueryManager', 'csv_field_separator'));
225
                        }
226
                        fclose($outputBuffer);
227
228
                        exit();
229
                    }
230
                } else {
231
                    $data[$i]['rowCount'] = $this->container->get('wbm_query_manager.db')->getRowCount($query);
232
                    $data[$i]['fetchData'] = null;
233
                }
234
235
                $i++;
236
            } while ($this->container->get('wbm_query_manager.db')->nextResult($query));
237
238
            $this->container->get('wbm_query_manager.db')->close($query);
239
240
            $this->View()->assign(
241
                array('success' => true, 'data' => array_reverse($data))
242
            );
243
        } catch (Exception $e) {
244
            $this->View()->assign(
245
                array('success' => false, 'data' => $e->getMessage())
246
            );
247
        }
248
    }
249
    
250
}
251
252