Issues (5)

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/OVHSwiftAdapter.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 Sausin\LaravelOvh;
4
5
use DateTime;
6
use DateTimeInterface;
7
use InvalidArgumentException;
8
use League\Flysystem\Config;
9
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;
10
use OpenStack\Common\Error\BadResponseError;
11
use OpenStack\ObjectStore\v1\Models\Container;
12
13
class OVHSwiftAdapter extends SwiftAdapter
14
{
15
    /** @var OVHConfiguration */
16
    protected OVHConfiguration $config;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
18
    /**
19
     * OVHSwiftAdapter constructor.
20
     *
21
     * @param  Container $container
22
     * @param  OVHConfiguration $config
23
     * @param  string|null $prefix
24
     */
25
    public function __construct(Container $container, OVHConfiguration $config, ?string $prefix = null)
26
    {
27
        parent::__construct($container, $prefix);
28
29
        $this->config = $config;
30
    }
31
32
    /**
33
     * Gets the endpoint url of the bucket.
34
     *
35
     * @param  string|null $path
36
     * @return string
37
     */
38
    protected function getEndpoint(?string $path = null): string
39
    {
40
        $url = !empty($this->config->getEndpoint())
41
            // Allows assigning custom endpoint url
42
            ? rtrim($this->config->getEndpoint(), '/').'/'
43
            // If no custom endpoint assigned, use traditional swift v1 endpoint
44
            : sprintf(
45
                'https://storage.%s.cloud.ovh.net/v1/AUTH_%s/%s/',
46
                $this->config->getRegion(),
47
                $this->config->getProjectId(),
48
                $this->config->getContainerName()
49
            );
50
51
        if (!empty($path)) {
52
            $url .= $this->applyPathPrefix($path);
53
        }
54
55
        return $url;
56
    }
57
58
    /**
59
     * Custom function to comply with the Storage::url() function in laravel
60
     * without checking the existence of a file (faster).
61
     *
62
     * @param  string $path
63
     * @return string
64
     */
65
    public function getUrl($path)
66
    {
67
        return $this->getEndpoint($path);
68
    }
69
70
    /**
71
     * Custom function to get an url with confirmed file existence.
72
     *
73
     * @param  string $path
74
     * @return string
75
     * @throws BadResponseError
76
     */
77
    public function getUrlConfirm($path): string
78
    {
79
        // check if object exists
80
        try {
81
            $this->has($path);
82
        } catch (BadResponseError $e) {
83
            throw $e;
84
        }
85
86
        return $this->getEndpoint($path);
87
    }
88
89
    /**
90
     * Generate a temporary URL for private containers.
91
     *
92
93
     * For more information, refer to OpenStack's documentation on Temporary URL middleware:
94
     * https://docs.openstack.org/swift/stein/api/temporary_url_middleware.html
95
     *
96
     * @param  string $path
97
     * @param  DateTimeInterface $expiresAt
98
     * @param  array $options
99
100
     * @return string
101
     */
102
    public function getTemporaryUrl(string $path, DateTimeInterface $expiresAt, array $options = []): string
103
    {
104
        // Ensure Temp URL Key is provided for the Disk
105
        if (empty($this->config->getTempUrlKey())) {
106
            throw new InvalidArgumentException("No Temp URL Key provided for container '".$this->container->name."'");
107
        }
108
109
        // Get the method
110
        $method = $options['method'] ?? 'GET';
111
112
        // The url on the OVH host
113
        $codePath = sprintf(
114
            '/v1/AUTH_%s/%s/%s',
115
            $this->config->getProjectId(),
116
            $this->config->getContainerName(),
117
            $this->applyPathPrefix($path)
118
        );
119
120
        // Body for the HMAC hash
121
        $body = sprintf("%s\n%s\n%s", $method, $expiresAt->getTimestamp(), $codePath);
122
123
        // The actual hash signature
124
        $signature = hash_hmac('sha1', $body, $this->config->getTempUrlKey());
125
126
        // Return signed url
127
        return sprintf(
128
            '%s?temp_url_sig=%s&temp_url_expires=%s',
129
            $this->getEndpoint($path),
130
            $signature,
131
            $expiresAt->getTimestamp()
132
        );
133
    }
134
135
    /**
136
     * Generate a FormPost signature to upload files directly to your OVH container.
137
     *
138
     * For more information, refer to OpenStack's documentation on FormPost middleware:
139
     * https://docs.openstack.org/swift/stein/api/form_post_middleware.html
140
     *
141
     * @param  string $path
142
     * @param  DateTimeInterface $expiresAt
143
     * @param  string|null $redirect
144
     * @param  int $maxFileCount
145
     * @param  int $maxFileSize Defaults to 25MB (25 * 1024 * 1024)
146
     * @return string
147
     */
148
    public function getFormPostSignature(string $path, DateTimeInterface $expiresAt, ?string $redirect = null, int $maxFileCount = 1, int $maxFileSize = 26214400): string
149
    {
150
        // Ensure Temp URL Key is provided for the Disk
151
        if (empty($this->config->getTempUrlKey())) {
152
            throw new InvalidArgumentException("No Temp URL Key provided for container '".$this->container->name."'");
153
        }
154
155
        // Ensure that 'expires' timestamp is in the future
156
        if ((new DateTime()) >= $expiresAt) {
157
            throw new InvalidArgumentException('Expiration time of FormPost signature must be in the future.');
158
        }
159
160
        // Ensure $path doesn't begin with a slash
161
        $path = $this->applyPathPrefix($path);
162
163
        // The url on the OVH host
164
        $codePath = sprintf(
165
            '/v1/AUTH_%s/%s/%s',
166
            $this->config->getProjectId(),
167
            $this->config->getContainerName(),
168
            $path
169
        );
170
171
        // Body for the HMAC hash
172
        $body = sprintf("%s\n%s\n%s\n%s\n%s", $codePath, $redirect ?? '', $maxFileSize, $maxFileCount, $expiresAt->getTimestamp());
173
174
        // The actual hash signature
175
        return hash_hmac('sha1', $body, $this->config->getTempUrlKey());
176
    }
177
178
    /**
179
     * Expose the container to allow for modification to metadata.
180
     *
181
     * @return Container
182
     */
183
    public function getContainer(): Container
184
    {
185
        return $this->container;
186
    }
187
188
    /**
189
     * Include support for object deletion.
190
     *
191
     * @param  string $path
192
     * @param  Config $config
193
     * @return array
194
     * @see SwiftAdapter
195
     */
196
    protected function getWriteData($path, $config): array
197
    {
198
        $data = parent::getWriteData($path, $config);
199
200
        if ($config->has('deleteAfter')) {
201
            // Apply object expiration timestamp if given
202
            $data['deleteAfter'] = $config->get('deleteAfter');
203
        } elseif ($config->has('deleteAt')) {
204
            // Apply object expiration time if given
205
            $data['deleteAt'] = $config->get('deleteAt');
206
        } elseif (!empty($this->config->getDeleteAfter())) {
207
            // Apply default object expiration time from package config
208
            $data['deleteAfter'] = $this->config->getDeleteAfter();
209
        }
210
211
        return $data;
212
    }
213
}
214