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/Commands/SetCORSHeaders.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\Commands;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\Facades\Storage;
9
use InvalidArgumentException;
10
use League\Flysystem\Cached\CachedAdapter;
11
use OpenStack\ObjectStore\v1\Models\Container;
12
13
class SetCORSHeaders extends Command
14
{
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'ovh:set-cors-headers
21
                            {--disk=ovh : The disk using your OVH container}
22
                            {--origins=* : The origins to be allowed on the containers (multiple allowed)}
23
                            {--max-age=3600 : The maximum cache validity of pre-flight requests}
24
                            {--force : Forcibly set the new headers}';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Set CORS headers on the container to make Form POST signature work flawlessly';
32
33
    /**
34
     * The Object Storage Container.
35
     *
36
     * @var Container
37
     */
38
    protected $container;
39
40
    /** array */
41
    protected $containerMeta = [];
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * If the '--force' flag is provided, the specified keys will be set on the container.
47
     * This excludes any 'Temp-Url-Key' already present on the container.
48
     *
49
     * @return void
50
     */
51
    public function handle(): void
52
    {
53
        try {
54
            $disk = $this->getDisk();
55
56
            $adapter = Storage::disk($disk)->getAdapter();
57
58
            if ($adapter instanceof CachedAdapter) {
59
                $adapter = $adapter->getAdapter();
60
            }
61
62
            $this->container = $adapter->getContainer();
63
        } catch (InvalidArgumentException $e) {
64
            $this->error($e->getMessage());
65
66
            return;
67
        }
68
69
        $this->containerMeta = $this->container->getMetadata();
70
71
        if ($this->option('force') || $this->askIfShouldOverrideExistingParams()) {
72
            $this->setHeaders();
73
        }
74
    }
75
76
    /**
77
     * If there's no existing Temp URL Key present in the Container, continue.
78
     *
79
     * Otherwise, if there's already an existing Temp URL Key present in the
80
     * Container, the User will be prompted to choose if we should override it
81
     * or not.
82
     *
83
     * @return bool
84
     */
85
    protected function askIfShouldOverrideExistingParams(): bool
86
    {
87
        $metaKeys = ['Access-Control-Allow-Origin', 'Access-Control-Max-Age'];
88
89
        if (count(array_intersect($metaKeys, array_keys($this->containerMeta))) === 0) {
90
            return true;
91
        }
92
93
        return $this->confirm(
94
            'Some CORS Meta keys are already set on the container. Do you want to override them?',
95
            false
96
        );
97
    }
98
99
    /**
100
     * Updates the Temp URL Key for the Container.
101
     *
102
     * @return void
103
     */
104
    protected function setHeaders(): void
105
    {
106
        $origins = '*';
107
108
        if (count($this->option('origins')) !== 0) {
109
            $origins = implode(' ', $this->option('origins'));
110
        }
111
112
        $maxAge = $this->option('max-age');
113
        $meta = ['Access-Control-Allow-Origin' => $origins, 'Access-Control-Max-Age' => $maxAge];
114
115
        if (array_key_exists('Temp-Url-Key', $this->containerMeta)) {
116
            $meta += ['Temp-Url-Key' => $this->containerMeta['Temp-Url-Key']];
117
        }
118
119
        try {
120
            $this->container->resetMetadata($meta);
121
122
            $this->info('CORS meta keys successfully set on the container');
123
        } catch (Exception $e) {
124
            $this->error($e->getMessage());
125
        }
126
    }
127
128
    /**
129
     * Check if selected disk is correct. If not, provide options to user.
130
     *
131
     * @return string
132
     */
133
    public function getDisk(): string
134
    {
135
        $available = array_keys(array_filter(Config::get('filesystems.disks'), function ($d) {
136
            return $d['driver'] === 'ovh';
137
        }));
138
139
        $selected = $this->option('disk');
140
141
        if (in_array($selected, $available)) {
142
            return $selected;
143
        }
144
145
        return $this->choice(
146
            'Selected disk not correct. Please choose from below options:',
147
            $available,
148
        );
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
149
    }
150
}
151