Issues (41)

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.

src/Payu.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
namespace Tzsk\Payu;
4
5
use Illuminate\Support\Facades\Session;
6
use Illuminate\Support\Facades\URL;
7
use Illuminate\Support\Facades\Validator;
8
use Illuminate\Validation\ValidationException;
9
use Illuminate\View\View;
10
use Throwable;
11
use Tzsk\Payu\Components\Form;
12
use Tzsk\Payu\Concerns\Transaction;
13
use Tzsk\Payu\Contracts\HasFormParams;
14
use Tzsk\Payu\Events\TransactionInitiated;
15
use Tzsk\Payu\Gateway\Factory;
16
use Tzsk\Payu\Gateway\Gateway;
17
use Tzsk\Payu\Models\PayuTransaction;
18
19
class Payu implements HasFormParams
20
{
21
    protected ?string $destination = null;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
22
    protected ?Gateway $gateway = null;
23
    protected ?Transaction $payment = null;
24
25
    /**
26
     * @param string $gateway
27
     * @return Payu
28
     * @throws Throwable
29
     */
30
    public function via(string $gateway): self
31
    {
32
        $this->gateway = Factory::make($gateway);
33
34
        return $this;
35
    }
36
37
    public function initiate(Transaction $payment): self
38
    {
39
        $this->payment = $payment;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param string $url
46
     * @return View
47
     * @throws Throwable
48
     */
49
    public function redirect(string $url): View
50
    {
51
        Validator::make(compact('url'), ['url' => 'required|url'])->validate();
52
53
        $this->destination = $url;
54
        if (! $this->gateway) {
55
            $this->via($this->defaultGateway());
56
        }
57
58
        Form::inject($payload = $this->prepare());
59
60
        event(new TransactionInitiated($payload['transaction']));
61
62
        return view('payu::form');
63
    }
64
65
    /**
66
     * @throws ValidationException
67
     */
68
    protected function prepare()
69
    {
70
        $this->validate();
71
        $fields = $this->fields();
72
        $hash = $this->getHash();
73
74
        $transaction = PayuTransaction::query()
75
            ->firstOrNew([
76
                'transaction_id' => $this->payment->transactionId,
77
            ]);
78
        $transaction->fill(
79
            array_merge($this->morphFields(), [
80
                'gateway' => $this->gateway,
81
                'body' => $this->payment,
82
                'destination' => $this->destination,
83
                'hash' => $hash,
84
            ])
85
        )->save();
86
87
        Session::put('payuTransactionId', $this->payment->transactionId);
88
89
        return [
90
            'endpoint' => $this->gateway->endpoint(),
91
            'fields' => array_merge($fields, compact('hash')),
92
            'transaction' => $transaction,
93
        ];
94
    }
95
96
    public function capture(): PayuTransaction
97
    {
98
        return PayuTransaction::locate(Session::get('payuTransactionId'));
99
    }
100
101
    protected function morphFields()
102
    {
103
        if (! $this->payment->model) {
104
            return [];
105
        }
106
107
        return [
108
            'paid_for_id' => $this->payment->model->getKey(),
109
            'paid_for_type' => $this->payment->model->getMorphClass(),
110
        ];
111
    }
112
113
    protected function defaultGateway()
114
    {
115
        return config('payu.default');
116
    }
117
118
    public function toArray(): array
119
    {
120
        return [
121
            'furl' => $this->getSignedRoute('failed'),
122
            'surl' => $this->getSignedRoute('successful'),
123
        ];
124
    }
125
126
    public function fields(): array
127
    {
128
        return collect($this->toArray())
129
            ->merge($this->gateway->fields())
130
            ->merge($this->payment->fields())
131
            ->all();
132
    }
133
134
    /**
135
     * @throws ValidationException
136
     */
137
    public function validate(): array
138
    {
139
        $this->gateway->validate();
140
        $this->payment->payee->validate();
141
        $this->payment->params->validate();
142
        $this->payment->validate();
143
144
        return Validator::make($this->toArray(), [
145
            'surl' => 'required|url',
146
            'furl' => 'required|url',
147
        ])->validate();
148
    }
149
150
    public function getSignedRoute(string $urlType): string
151
    {
152
        return URL::temporarySignedRoute(
153
            'payu::redirect',
154
            now()->addMinutes(30),
155
            array_merge(compact('urlType'), ['transaction' => $this->payment->transactionId])
156
        );
157
    }
158
159
    protected function getHash()
160
    {
161
        return Checksum::with($this->gateway->salt())
162
            ->create($this->fields());
163
    }
164
}
165