Issues (195)

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.

Alpha/Controller/ExcelController.php (1 issue)

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 Alpha\Controller;
4
5
use Alpha\Util\Logging\Logger;
6
use Alpha\Util\Convertor\ActiveRecord2Excel;
7
use Alpha\Util\Http\Request;
8
use Alpha\Util\Http\Response;
9
use Alpha\Exception\IllegalArguementException;
10
use Alpha\Exception\RecordNotFoundException;
11
use Alpha\Exception\ResourceNotFoundException;
12
use Alpha\Model\ActiveRecord;
13
14
/**
15
 * Controller for viewing an active record as Excel spreadsheets.
16
 *
17
 * @since 1.0
18
 *
19
 * @author John Collins <[email protected]>
20
 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
21
 * @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework).
22
 * All rights reserved.
23
 *
24
 * <pre>
25
 * Redistribution and use in source and binary forms, with or
26
 * without modification, are permitted provided that the
27
 * following conditions are met:
28
 *
29
 * * Redistributions of source code must retain the above
30
 *   copyright notice, this list of conditions and the
31
 *   following disclaimer.
32
 * * Redistributions in binary form must reproduce the above
33
 *   copyright notice, this list of conditions and the
34
 *   following disclaimer in the documentation and/or other
35
 *   materials provided with the distribution.
36
 * * Neither the name of the Alpha Framework nor the names
37
 *   of its contributors may be used to endorse or promote
38
 *   products derived from this software without specific
39
 *   prior written permission.
40
 *
41
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
52
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
 * </pre>
55
 */
56
class ExcelController extends Controller implements ControllerInterface
57
{
58
    /**
59
     * Trace logger.
60
     *
61
     * @var \Alpha\Util\Logging\Logger
62
     *
63
     * @since 1.0
64
     */
65
    private static $logger = null;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
66
67
    /**
68
     * Constructor.
69
     *
70
     * @since 1.0
71
     */
72
    public function __construct()
73
    {
74
        self::$logger = new Logger('ExcelController');
75
        self::$logger->debug('>>__construct()');
76
77
        // ensure that the super class constructor is called, indicating the rights group
78
        parent::__construct('Public');
79
80
        self::$logger->debug('<<__construct');
81
    }
82
83
    /**
84
     * Loads the Record indicated in the GET request and handles the conversion to Excel.
85
     *
86
     * @param \Alpha\Util\Http\Request $request
87
     *
88
     * @return \Alpha\Util\Http\Response
89
     *
90
     * @throws \Alpha\Exception\ResourceNotFoundException
91
     *
92
     * @since 1.0
93
     */
94
    public function doGet($request)
95
    {
96
        self::$logger->debug('>>doGet(request=['.var_export($request, true).'])');
97
98
        $params = $request->getParams();
99
100
        $body = '';
101
102
        try {
103
            if (isset($params['ActiveRecordType'])) {
104
                $ActiveRecordType = $params['ActiveRecordType'];
105
106
                $className = "Alpha\\Model\\$ActiveRecordType";
107
                if (class_exists($className)) {
108
                    $this->record = new $className();
109
                } else {
110
                    throw new IllegalArguementException('No ActiveRecord available to render!');
111
                }
112
113
                // the name of the file download
114
                if (isset($params['ActiveRecordID'])) {
115
                    $fileName = $this->record->getTableName().'-'.$params['ActiveRecordID'];
116
                } else {
117
                    $fileName = $this->record->getTableName();
118
                }
119
120
                $response = new Response(200);
121
122
                // header info for browser
123
                $response->setHeader('Content-Type', 'application/vnd.ms-excel');
124
                $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName.'.xls');
125
                $response->setHeader('Pragma', 'no-cache');
126
                $response->setHeader('Expires', '0');
127
128
                // handle a single record
129
                if (isset($params['ActiveRecordID'])) {
130
                    $this->record->load($params['ActiveRecordID']);
131
                    ActiveRecord::disconnect();
132
133
                    $convertor = new ActiveRecord2Excel($this->record);
134
                    $body .= $convertor->render();
135
                } else {
136
                    // handle all records of this type
137
                    $records = $this->record->loadAll();
138
                    ActiveRecord::disconnect();
139
140
                    $first = true;
141
142
                    foreach ($records as $record) {
143
                        $convertor = new ActiveRecord2Excel($record);
144
                        if ($first) {
145
                            $body .= $convertor->render(true);
146
                            $first = false;
147
                        } else {
148
                            $body .= $convertor->render(false);
149
                        }
150
                    }
151
                }
152
            } else {
153
                throw new IllegalArguementException('No ActiveRecordType parameter available for ViewExcel controller!');
154
            }
155
        } catch (RecordNotFoundException $e) {
156
            self::$logger->error($e->getMessage());
157
            throw new ResourceNotFoundException($e->getMessage());
158
        } catch (IllegalArguementException $e) {
159
            self::$logger->error($e->getMessage());
160
            throw new ResourceNotFoundException($e->getMessage());
161
        }
162
163
        self::$logger->debug('<<__doGet');
164
        $response->setBody($body);
165
166
        return $response;
167
    }
168
}
169