Issues (3)

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/Webhooks/BaseWebhook.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
namespace Bencoderus\Webhook\Webhooks;
4
5
use Bencoderus\Webhook\Exceptions\WebhookException;
6
use Bencoderus\Webhook\Traits\SendWebhook;
7
use Illuminate\Http\Resources\DelegatesToResource;
8
use Illuminate\Support\Str;
9
10
abstract class BaseWebhook
11
{
12
    use SendWebhook, DelegatesToResource;
13
14
    /**
15
     * Webhook encryption signature.
16
     *
17
     * @var array
18
     */
19
    public $signature;
20
21
    /**
22
     * The URL the outgoing will be dispatched to.
23
     *
24
     * @var string
25
     */
26
    private $url;
27
28
    /**
29
     * The data that will be dispatched with the outgoing webhook.
30
     *
31
     * @var array
32
     */
33
    private $payload;
34
35
    /**
36
     * An instance of the webhook payload.
37
     *
38
     * @var null
39
     */
40
    private $resource;
41
42
    /**
43
     * Create a webhook instance.
44
     *
45
     * @param null $model
46
     */
47
    public function __construct($model = null)
48
    {
49
        $this->resource = $model;
50
    }
51
52
    /**
53
     * Add a webhook signature.
54
     *
55
     * @param string $signatureName
56
     * @param string $encryptionKey
57
     * @param string $hashAlgorithm
58
     *
59
     * @return $this
60
     */
61
    public function withSignature(string $signatureName, string $encryptionKey, string $hashAlgorithm = 'sha512'): self
62
    {
63
        $encryptionKey = hash($hashAlgorithm, $encryptionKey);
64
65
        $this->signature = [$signatureName => $encryptionKey];
66
67
        return $this;
68
    }
69
70
    /**
71
     * Add webhook url.
72
     *
73
     * @param string $url
74
     *
75
     * @return $this
76
     */
77
    public function url(string $url): self
78
    {
79
        $this->url = $url;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Send webhook asynchronously(Queue) or synchronously.
86
     *
87
     * @param bool $sendWithQueue
88
     *
89
     * @return bool
90
     * @throws \Bencoderus\Webhook\Exceptions\WebhookException
91
     */
92
    public function send(bool $sendWithQueue = true): bool
93
    {
94
        $data = $this->prepareWebhook();
95
96
        if (empty($data['url'])) {
97
            throw new WebhookException("You need to set a webhook URL");
98
        }
99
100
        if (! config('webhook.dispatch_webhook')) {
101
            return true;
102
        }
103
104
        if ($sendWithQueue) {
105
            return $this->sendViaQueue($data);
106
        }
107
108
        return $this->sendViaHttp($data);
109
    }
110
111
    /**
112
     * Generate webhook data.
113
     *
114
     * @return array
115
     */
116
    public function prepareWebhook(): array
117
    {
118
        $webhookData = [];
119
120
        $this->generatePayload();
121
122
        if ($this->signature) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->signature of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
123
            $webhookData['signature'] = $this->signature ?? [];
124
        }
125
126
        $webhookData['url'] = $this->url;
127
        $webhookData['payload'] = $this->payload;
128
        $webhookData['webhook_id'] = Str::uuid();
129
130
        return $webhookData;
131
    }
132
133
    /**
134
     * Format outgoing webhook payload
135
     *
136
     * @return array
137
     */
138
    private function generatePayload(): array
139
    {
140
        $this->payload = array_merge(
141
            ['event' => $this->event],
0 ignored issues
show
The property event does not exist on object<Bencoderus\Webhook\Webhooks\BaseWebhook>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
142
            ['data' => $this->data()]
143
        );
144
145
        return $this->payload;
146
    }
147
148
    /**
149
     * Webhook payload data.
150
     *
151
     * @return mixed
152
     */
153
    abstract public function data();
154
155
}
156