Issues (11)

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.

src/Paybox.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
/*
4
 * This file is part of the Nexylan packages.
5
 *
6
 * (c) Nexylan SAS <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Nexy\PayboxDirect;
13
14
use Doctrine\Common\Annotations\AnnotationRegistry;
15
use Nexy\PayboxDirect\Enum\Activity;
16
use Nexy\PayboxDirect\Enum\Currency;
17
use Nexy\PayboxDirect\Enum\Version;
18
use Nexy\PayboxDirect\Exception\InvalidRequestPropertiesException;
19
use Nexy\PayboxDirect\HttpClient\AbstractHttpClient;
20
use Nexy\PayboxDirect\HttpClient\GuzzleHttpClient;
21
use Nexy\PayboxDirect\Request\InquiryRequest;
22
use Nexy\PayboxDirect\Request\RequestInterface;
23
use Nexy\PayboxDirect\Response\DirectPlusResponse;
24
use Nexy\PayboxDirect\Response\DirectResponse;
25
use Nexy\PayboxDirect\Response\InquiryResponse;
26
use Nexy\PayboxDirect\Response\ResponseInterface;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
use Symfony\Component\Validator\Validation;
29
use Symfony\Component\Validator\Validator\ValidatorInterface;
30
31
/**
32
 * @author Sullivan Senechal <[email protected]>
33
 *
34
 * @see http://www1.paybox.com/espace-integrateur-documentation/les-solutions-paybox-direct-et-paybox-direct-plus/les-operations-de-caisse-direct-plus/
35
 * @see http://www1.paybox.com/espace-integrateur-documentation/dictionnaire-des-donnees/paybox-direct-et-direct-plus/
36
 */
37
final class Paybox
38
{
39
    const API_URL_PRODUCTION = 'https://ppps.paybox.com/PPPS.php';
40
41
    const API_URL_RESCUE = 'https://ppps1.paybox.com/PPPS.php';
42
43
    const API_URL_TEST = 'https://preprod-ppps.paybox.com/PPPS.php';
44
45
    /**
46
     * @var ValidatorInterface
47
     */
48
    private $validator;
49
50
    /**
51
     * @var AbstractHttpClient
52
     */
53
    private $httpClient;
54
55
    /**
56
     * @var array
57
     */
58
    private $options;
59
60
    public function __construct(array $options = [], AbstractHttpClient $httpClient = null)
61
    {
62
        $resolver = new OptionsResolver();
63
        $this->configureOptions($resolver);
64
65
        $this->options = $resolver->resolve($options);
66
67
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...istry::registerLoader() has been deprecated with message: This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
68
        $this->validator = Validation::createValidatorBuilder()
69
            ->enableAnnotationMapping()
70
            ->getValidator();
71
72
        $this->httpClient = $httpClient ? $httpClient : new GuzzleHttpClient();
73
        $this->httpClient->setOptions($this->options);
74
        $this->httpClient->init();
75
    }
76
77
    /**
78
     * @param RequestInterface $request
79
     *
80
     * @return DirectResponse
81
     */
82
    public function sendDirectRequest(RequestInterface $request)
83
    {
84
        if ($request->getRequestType() >= RequestInterface::SUBSCRIBER_AUTHORIZE) {
85
            throw new \InvalidArgumentException(
86
                'Direct Plus requests must be passed onto '.__CLASS__.'::sendDirectPlusRequest method.'
87
            );
88
        }
89
        if ($request instanceof InquiryRequest) {
90
            throw new \InvalidArgumentException(
91
                'Inquiry requests must be passed onto '.__CLASS__.'::sendInquiryRequest method.'
92
            );
93
        }
94
95
        return $this->request($request);
96
    }
97
98
    /**
99
     * @param RequestInterface $request
100
     *
101
     * @return DirectPlusResponse
102
     */
103
    public function sendDirectPlusRequest(RequestInterface $request)
104
    {
105
        if ($request->getRequestType() < RequestInterface::SUBSCRIBER_AUTHORIZE) {
106
            throw new \InvalidArgumentException(
107
                'Direct requests must be passed onto '.__CLASS__.'::sendDirectRequest method.'
108
            );
109
        }
110
111
        return $this->request($request, DirectPlusResponse::class);
112
    }
113
114
    /**
115
     * @param InquiryRequest $request
116
     *
117
     * @return InquiryResponse
118
     */
119
    public function sendInquiryRequest(InquiryRequest $request)
120
    {
121
        return $this->request($request, InquiryResponse::class);
122
    }
123
124
    /**
125
     * @param RequestInterface $request
126
     * @param string           $responseClass
127
     *
128
     * @return ResponseInterface
129
     *
130
     * @throws Exception\InvalidRequestPropertiesException
131
     * @throws Exception\PayboxException
132
     */
133
    private function request(RequestInterface $request, $responseClass = DirectResponse::class)
134
    {
135
        $errors = $this->validator->validate($request);
136
        if ($errors->count() > 0) {
137
            throw new InvalidRequestPropertiesException($request, $errors);
138
        }
139
140
        return $this->httpClient->call($request->getRequestType(), $request->getParameters(), $responseClass);
141
    }
142
143
    /**
144
     * Paybox base options validation.
145
     *
146
     * @param OptionsResolver $resolver
147
     */
148
    private function configureOptions(OptionsResolver $resolver)
149
    {
150
        $resolver->setDefaults([
151
            'timeout' => 10,
152
            'production' => false,
153
            'paybox_default_currency' => Currency::EURO,
154
        ]);
155
        $resolver->setDefined([
156
            'paybox_default_activity',
157
        ]);
158
        $resolver->setRequired([
159
            'paybox_version', // Paybox Direct Plus protocol
160
            'paybox_site',
161
            'paybox_rank',
162
            'paybox_identifier',
163
            'paybox_key',
164
        ]);
165
166
        $resolver->setAllowedTypes('timeout', 'int');
167
        $resolver->setAllowedTypes('production', 'bool');
168
        $resolver->setAllowedTypes('paybox_version', 'string');
169
        $resolver->setAllowedTypes('paybox_default_currency', 'int');
170
        $resolver->setAllowedTypes('paybox_site', 'string');
171
        $resolver->setAllowedTypes('paybox_rank', 'string');
172
        $resolver->setAllowedTypes('paybox_identifier', 'string');
173
        $resolver->setAllowedTypes('paybox_key', 'string');
174
175
        $resolver->setAllowedValues('paybox_version', Version::getConstants());
176
        $resolver->setAllowedValues('paybox_default_activity', Activity::getConstants());
177
    }
178
}
179