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.

Model/Api/Request/Authorization.php (1 issue)

Labels
Severity

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\Model\Api\Request;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Payone\Core\Model\Methods\PayoneMethod;
31
use Magento\Sales\Model\Order;
32
33
/**
34
 * Class for the PAYONE Server API request "(pre)authorization"
35
 *
36
 * @category  Payone
37
 * @package   Payone_Magento2_Plugin
38
 * @author    FATCHIP GmbH <[email protected]>
39
 * @copyright 2003 - 2016 Payone GmbH
40
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
41
 * @link      http://www.payone.de
42
 */
43
class Authorization extends AddressRequest
44
{
45
    /**
46
     * Invoice generator
47
     *
48
     * @var \Payone\Core\Model\Api\Invoice
49
     */
50
    protected $invoiceGenerator;
51
52
    /**
53
     * Checkout session object
54
     *
55
     * @var \Magento\Checkout\Model\Session
56
     */
57
    protected $checkoutSession;
58
59
    /**
60
     * PAYONE toolkit helper
61
     *
62
     * @var \Payone\Core\Helper\Toolkit
63
     */
64
    protected $toolkitHelper;
65
66
    /**
67
     * Constructor
68
     *
69
     * @param \Payone\Core\Helper\Shop                $shopHelper
70
     * @param \Payone\Core\Helper\Environment         $environmentHelper
71
     * @param \Payone\Core\Helper\Api                 $apiHelper
72
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
73
     * @param \Payone\Core\Helper\Customer            $customerHelper
74
     * @param \Payone\Core\Model\Api\Invoice          $invoiceGenerator
75
     * @param \Magento\Checkout\Model\Session         $checkoutSession
76
     * @param \Payone\Core\Helper\Toolkit             $toolkitHelper
77
     */
78
    public function __construct(
79
        \Payone\Core\Helper\Shop $shopHelper,
80
        \Payone\Core\Helper\Environment $environmentHelper,
81
        \Payone\Core\Helper\Api $apiHelper,
82
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
83
        \Payone\Core\Helper\Customer $customerHelper,
84
        \Payone\Core\Model\Api\Invoice $invoiceGenerator,
85
        \Magento\Checkout\Model\Session $checkoutSession,
86
        \Payone\Core\Helper\Toolkit $toolkitHelper
87
    ) {
88
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
89
        $this->invoiceGenerator = $invoiceGenerator;
90
        $this->checkoutSession = $checkoutSession;
91
        $this->toolkitHelper = $toolkitHelper;
92
    }
93
94
    /**
95
     * Send request to PAYONE Server-API with
96
     * request-type "authorization" or "preauthorization"
97
     *
98
     * @param  PayoneMethod $oPayment payment object
99
     * @param  Order        $oOrder   order object
100
     * @param  float        $dAmount  order sum amount
101
     * @return array
102
     */
103
    public function sendRequest(PayoneMethod $oPayment, Order $oOrder, $dAmount)
104
    {
105
        $this->setOrderId($oOrder->getRealOrderId()); // save order id to object for later use
106
107
        $this->addParameter('request', $oPayment->getAuthorizationMode()); // add request type
108
        $this->addParameter('mode', $oPayment->getOperationMode()); // add mode ( live or test )
109
        $this->addParameter('customerid', $oOrder->getCustomerId()); // add customer id
110
        $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // add sub account id
111
        $this->setAuthorizationParameters($oPayment, $oOrder, $dAmount); // set authorization params
112
113
        $aResponse = $this->send($oPayment); // send request to PAYONE Server API
114
115
        $this->apiHelper->addPayoneOrderData($oOrder, $this->getParameters(), $aResponse); // add payone data to order
116
117
        return $aResponse;
118
    }
119
120
    /**
121
     * Add user parameters
122
     *
123
     * @param  PayoneMethod $oPayment
124
     * @param  Order        $oOrder
125
     * @return void
126
     */
127
    protected function setUserParameters(PayoneMethod $oPayment, Order $oOrder)
128
    {
129
        $oQuote = $this->checkoutSession->getQuote(); // get quote from session
130
        $oCustomer = $oQuote->getCustomer(); // get customer object from quote
131
        $this->addUserDataParameters($oOrder->getBillingAddress(), $oPayment, $oCustomer->getGender(), $oOrder->getCustomerEmail(), $oCustomer->getDob());
132
133
        $oShipping = $oOrder->getShippingAddress(); // get shipping address from order
134
        if ($oShipping) {// shipping address existing?
135
            $this->addAddress($oShipping, true); // add regular shipping address
136
        } elseif ($oPayment->getCode() == PayoneConfig::METHOD_PAYDIREKT || ($oPayment->getCode() == PayoneConfig::METHOD_PAYPAL && $this->shopHelper->getConfigParam('bill_as_del_address', PayoneConfig::METHOD_PAYPAL, 'payone_payment'))) {
137
            $this->addAddress($oOrder->getBillingAddress(), true); // add billing address as shipping address
138
        }
139
    }
140
141
    /**
142
     * Set the parameters needed for the authorization requests
143
     *
144
     * @param  PayoneMethod $oPayment
145
     * @param  Order        $oOrder
146
     * @param  float        $dAmount
147
     * @return void
148
     */
149
    protected function setAuthorizationParameters(PayoneMethod $oPayment, Order $oOrder, $dAmount)
150
    {
151
        $sRefNr = $this->shopHelper->getConfigParam('ref_prefix').$oOrder->getIncrementId(); // ref_prefix to prevent duplicate refnumbers in testing environments
152
        $sRefNr = $oPayment->formatReferenceNumber($sRefNr); // some payment methods have refnr regulations
153
        $this->addParameter('reference', $sRefNr); // add ref-nr to request
154
        $this->addParameter('amount', number_format($dAmount, 2, '.', '') * 100); // add price to request
155
        $this->addParameter('currency', $oOrder->getOrderCurrencyCode()); // add currency to request
156
        if ($this->shopHelper->getConfigParam('transmit_ip') == '1') {// is IP transmission needed?
157
            $sIp = $this->environmentHelper->getRemoteIp(); // get remote IP
158
            if ($sIp != '') {// is IP not empty
159
                $this->addParameter('ip', $sIp); // add IP address to the request
160
            }
161
        }
162
        $this->setUserParameters($oPayment, $oOrder); // add user data - addresses etc.
163
        $this->setPaymentParameters($oPayment, $oOrder); // add payment specific parameters
164
165
        if ($this->apiHelper->isInvoiceDataNeeded($oPayment)) {
166
            $this->invoiceGenerator->addProductInfo($this, $oOrder); // add invoice parameters
167
        }
168
    }
169
170
    /**
171
     * Set payment-specific parameters
172
     *
173
     * @param  PayoneMethod $oPayment
174
     * @param  Order        $oOrder
175
     * @return void
176
     */
177
    protected function setPaymentParameters(PayoneMethod $oPayment, Order $oOrder)
178
    {
179
        $this->addParameter('clearingtype', $oPayment->getClearingtype()); // add payment type to request
0 ignored issues
show
It seems like $oPayment->getClearingtype() targeting Payone\Core\Model\Method...thod::getClearingtype() can also be of type boolean; however, Payone\Core\Model\Api\Request\Base::addParameter() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
180
        $sNarrativeText = $this->toolkitHelper->getNarrativeText($oOrder, $oPayment);
181
        if (!empty($sNarrativeText)) {// narrative text existing?
182
            $this->addParameter('narrative_text', $sNarrativeText); // add narrative text parameter
183
        }
184
        $aPaymentParams = $oPayment->getPaymentSpecificParameters($oOrder); // get payment params specific to the payment type
185
        $this->aParameters = array_merge($this->aParameters, $aPaymentParams); // merge payment params with other params
186
        if ($oPayment->needsRedirectUrls() === true) {// does the used payment type need redirect urls?
187
            $this->addRedirectUrls($oPayment); // add needed redirect urls
188
        }
189
    }
190
}
191