Issues (496)

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.

class/Export.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 namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use CriteriaElement;
22
use XoopsModules\Smartobject;
23
24
/**
25
 * Contains the classes for easily exporting data
26
 *
27
 * @license GNU
28
 * @author  marcan <[email protected]>
29
 * @link    http://www.smartfactory.ca The SmartFactory
30
 * @package SmartObject
31
 */
32
33
/**
34
 * SmartObjectExport class
35
 *
36
 * Class to easily export data from SmartObjects
37
 *
38
 * @package SmartObject
39
 * @author  marcan <[email protected]>
40
 * @link    http://www.smartfactory.ca The SmartFactory
41
 */
42
class Export
43
{
44
    public $handler;
45
    public $criteria;
46
    public $fields;
47
    public $format;
48
    public $filename;
49
    public $filepath;
50
    public $options;
51
    public $outputMethods = false;
52
    public $notDisplayFields;
53
54
    /**
55
     * Constructor
56
     *
57
     * @param PersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export
58
     * @param \CriteriaElement         $criteria      containing the criteria of the query fetching the objects to be exported
59
     * @param array|bool               $fields        fields to be exported. If FALSE then all fields will be exported
60
     * @param bool|string              $filename      name of the file to be created
61
     * @param bool|string              $filepath      path where the file will be saved
62
     * @param string                   $format        format of the ouputed export. Currently only supports CSV
63
     * @param array|bool               $options       options of the format to be exported in
64
     */
65
    public function __construct(
66
        PersistableObjectHandler $objectHandler,
67
        \CriteriaElement $criteria = null,
68
        $fields = false,
69
        $filename = false,
70
        $filepath = false,
0 ignored issues
show
The parameter $filepath is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
        $format = 'csv',
72
        $options = false
73
    ) {
74
        $this->handler          = $objectHandler;
75
        $this->criteria         = $criteria;
76
        $this->fields           = $fields;
77
        $this->filename         = $filename;
78
        $this->format           = $format;
79
        $this->options          = $options;
80
        $this->notDisplayFields = false;
81
    }
82
83
    /**
84
     * Renders the export
85
     * @param $filename
86
     */
87
    public function render($filename)
88
    {
89
        $this->filename = $filename;
90
91
        $objects        = $this->handler->getObjects($this->criteria);
92
        $rows           = [];
93
        $columnsHeaders = [];
94
        $firstObject    = true;
95
        foreach ($objects as $object) {
96
            $row = [];
97
            foreach ($object->vars as $key => $var) {
98
                if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) {
99
                    if ($this->outputMethods && isset($this->outputMethods[$key])
100
                        && method_exists($object, $this->outputMethods[$key])) {
101
                        $method    = $this->outputMethods[$key];
102
                        $row[$key] = $object->$method();
103
                    } else {
104
                        $row[$key] = $object->getVar($key);
105
                    }
106
                    if ($firstObject) {
107
                        // then set the columnsHeaders array as well
108
                        $columnsHeaders[$key] = $var['form_caption'];
109
                    }
110
                }
111
            }
112
            $firstObject = false;
113
            $rows[]      = $row;
114
            unset($row);
115
        }
116
        $data                   = [];
117
        $data['rows']           = $rows;
118
        $data['columnsHeaders'] = $columnsHeaders;
119
        $smartExportRenderer    = new ExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options);
0 ignored issues
show
It seems like $this->options can also be of type boolean; however, XoopsModules\Smartobject...Renderer::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
120
        $smartExportRenderer->execute();
121
    }
122
123
    /**
124
     * Set an array contaning the alternate methods to use instead of the default getVar()
125
     *
126
     * $outputMethods array example: 'uid' => 'getUserName'...
127
     * @param $outputMethods
128
     */
129
    public function setOuptutMethods($outputMethods)
130
    {
131
        $this->outputMethods = $outputMethods;
132
    }
133
134
    /*
135
     * Set an array of fields that we don't want in export
136
     */
137
    /**
138
     * @param $fields
139
     */
140
    public function setNotDisplayFields($fields)
141
    {
142
        if (!$this->notDisplayFields) {
143
            if (is_array($fields)) {
144
                $this->notDisplayFields = $fields;
145
            } else {
146
                $this->notDisplayFields = [$fields];
147
            }
148
        } else {
149
            if (is_array($fields)) {
150
                $this->notDisplayFields = array_merge($this->notDisplayFields, $fields);
151
            } else {
152
                $this->notDisplayFields[] = $fields;
153
            }
154
        }
155
    }
156
}
157