Issues (547)

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.

Helper/Toolkit.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
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper;
28
29
use Magento\Framework\DataObject;
30
use Magento\Sales\Model\Order as SalesOrder;
31
use Payone\Core\Model\Methods\PayoneMethod;
32
33
/**
34
 * Toolkit class for methods that dont fit in a certain drawer
35
 */
36
class Toolkit extends \Payone\Core\Helper\Base
37
{
38
    /**
39
     * PAYONE payment helper
40
     *
41
     * @var \Payone\Core\Helper\Payment
42
     */
43
    protected $paymentHelper;
44
45
    /**
46
     * Constructor
47
     *
48
     * @param \Magento\Framework\App\Helper\Context      $context
49
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
50
     * @param \Payone\Core\Helper\Payment                $paymentHelper
51
     * @param \Payone\Core\Helper\Shop                   $shopHelper
52
     */
53
    public function __construct(
54
        \Magento\Framework\App\Helper\Context $context,
55
        \Magento\Store\Model\StoreManagerInterface $storeManager,
56
        \Payone\Core\Helper\Payment $paymentHelper,
57
        \Payone\Core\Helper\Shop $shopHelper
58
    ) {
59
        parent::__construct($context, $storeManager, $shopHelper);
60
        $this->paymentHelper = $paymentHelper;
61
    }
62
63
    /**
64
     * Get security keys for all payment types for the given store code
65
     *
66
     * @param  string $sStoreCode
67
     * @return array
68
     */
69
    protected function getAllPayoneSecurityKeysByStoreCode($sStoreCode)
70
    {
71
        $aKeys = [];
72
        foreach ($this->paymentHelper->getAvailablePaymentTypes() as $sPaymentCode) {
73
            $iUseGlobal = $this->getConfigParam('use_global', $sPaymentCode, 'payone_payment', $sStoreCode);
74
            if ($iUseGlobal == '0') {
75
                $aKeys[] = $this->getConfigParam('key', $sPaymentCode, 'payone_payment', $sStoreCode);
76
            }
77
        }
78
        return $aKeys;
79
    }
80
81
    /**
82
     * Get the configured security keys for all available stores
83
     * and payment types - since every payment-type can have its own
84
     *
85
     * @return array
86
     */
87
    public function getAllPayoneSecurityKeys()
88
    {
89
        $aKeys = $this->getConfigParamAllStores('key');
90
        $aShopIds = $this->storeManager->getStores(false, true);
91
        foreach ($aShopIds as $sStoreCode => $oStore) {
92
            $aKeys = array_merge($aKeys, $this->getAllPayoneSecurityKeysByStoreCode($sStoreCode));
93
        }
94
        return array_unique($aKeys);
95
    }
96
97
    /**
98
     * Check wheither the given key is configured in the shop and thus valid
99
     *
100
     * @param  string $sKey
101
     * @return bool
102
     */
103
    public function isKeyValid($sKey)
104
    {
105
        $aKeyValues = $this->getAllPayoneSecurityKeys();
106
        foreach ($aKeyValues as $sConfigKey) {
107
            if (md5($sConfigKey) == $sKey) {
108
                return true;
109
            }
110
        }
111
        return false;
112
    }
113
114
    /**
115
     * Replace substitutes in a given text with the given replacements
116
     *
117
     * @param  string   $sText
118
     * @param  string   $aSubstitutionArray
119
     * @param  int|bool $iMaxLength
120
     * @return string
121
     */
122
    public function handleSubstituteReplacement($sText, $aSubstitutionArray, $iMaxLength = false)
123
    {
124
        if (!empty($sText)) {
125
            $sText = str_replace(array_keys($aSubstitutionArray), array_values($aSubstitutionArray), $sText);
126
            if ($iMaxLength !== false && strlen($sText) > $iMaxLength) {
127
                $sText = substr($sText, 0, $iMaxLength); // shorten text if too long
128
            }
129
            return $sText;
130
        }
131
        return '';
132
    }
133
134
    /**
135
     * Get substituted invoice appendix text
136
     *
137
     * @param  SalesOrder $oOrder
138
     * @return string
139
     */
140 View Code Duplication
    public function getInvoiceAppendix(SalesOrder $oOrder)
141
    {
142
        $sText = $this->getConfigParam('invoice_appendix', 'invoicing'); // get invoice appendix from config
143
        $aSubstitutionArray = [
144
            '{{order_increment_id}}' => $oOrder->getIncrementId(),
145
            '{{customer_id}}' => $oOrder->getCustomerId(),
146
        ];
147
        $sInvoiceAppendix = $this->handleSubstituteReplacement($sText, $aSubstitutionArray, 255);
0 ignored issues
show
$aSubstitutionArray is of type array<string,?,{"{{order..."{{customer_id}}":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
148
        return $sInvoiceAppendix;
149
    }
150
151
    /**
152
     * Returns narrative text for authorization request
153
     *
154
     * @param  SalesOrder   $oOrder
155
     * @param  PayoneMethod $oPayment
156
     * @return string
157
     */
158 View Code Duplication
    public function getNarrativeText(SalesOrder $oOrder, PayoneMethod $oPayment)
159
    {
160
        $sText = $this->getConfigParam('narrative_text', $oPayment->getCode(), 'payone_payment'); // get narrative text for payment from config
161
        $aSubstitutionArray = [
162
            '{{order_increment_id}}' => $oOrder->getIncrementId(),
163
        ];
164
        $sNarrativeText = $this->handleSubstituteReplacement($sText, $aSubstitutionArray, $oPayment->getNarrativeTextMaxLength());
0 ignored issues
show
$aSubstitutionArray is of type array<string,?,{"{{order_increment_id}}":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
        return $sNarrativeText;
166
    }
167
168
    /**
169
     * Format a price to the XX.YY format
170
     *
171
     * @param  double $dPrice    price of any sort
172
     * @param  int    $iDecimals number of digits behind the decimal point
173
     * @return string
174
     */
175
    public function formatNumber($dPrice, $iDecimals = 2)
176
    {
177
        return number_format($dPrice, $iDecimals, '.', '');
178
    }
179
180
    /**
181
     * Checks if given string is utf8 encoded
182
     *
183
     * @param  string $sString
184
     * @return bool
185
     */
186
    public function isUTF8($sString)
187
    {
188
        return $sString === mb_convert_encoding(mb_convert_encoding($sString, "UTF-32", "UTF-8"), "UTF-8", "UTF-32");
189
    }
190
191
    /**
192
     * Return data from data-object
193
     * Needed because of different ways to read from it for different magento versions
194
     *
195
     * @param  DataObject $oData
196
     * @param  string     $sKey
197
     * @return string|null
198
     */
199
    public function getAdditionalDataEntry(DataObject $oData, $sKey)
200
    {
201
        // The way to read the form-parameters changed with version 2.0.6
202
        if (version_compare($this->shopHelper->getMagentoVersion(), '2.0.6', '>=')) { // Magento 2.0.6 and above
203
            $aAdditionalData = $oData->getAdditionalData();
204
            if (isset($aAdditionalData[$sKey])) {
205
                return $aAdditionalData[$sKey];
206
            }
207
            return null;
208
        }
209
        // everything below 2.0.6
210
        return $oData->getData($sKey);
211
    }
212
}
213