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/Command/KeyGenerateCommand.php (5 issues)

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
namespace RichardStyles\EloquentAES\Command;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Console\ConfirmableTrait;
6
use Illuminate\Encryption\Encrypter;
7
use Illuminate\Support\Str;
8
9
10
class KeyGenerateCommand extends Command
11
{
12
    use ConfirmableTrait;
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'key:eloquent
19
                    {--show : Display the key instead of modifying files}
20
                    {--force : Force the operation to run when in production}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Set the eloquent key';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return void
33
     */
34
    public function handle()
35
    {
36
        $key = $this->generateRandomKey();
37
38
        if ($this->option('show')) {
39
            return $this->line('<comment>'.$key.'</comment>');
40
        }
41
42
        // Next, we will replace the application key in the environment file so it is
43
        // automatically setup for this developer. This key gets generated using a
44
        // secure random byte generator and is later base64 encoded for storage.
45
        if (! $this->setKeyInEnvironmentFile($key)) {
46
            return;
47
        }
48
49
        $this->laravel['config']['eloquentaes.key'] = $key;
50
51
        $this->info('Eloquent key set successfully.');
52
    }
53
54
    /**
55
     * Generate a random key for the application.
56
     *
57
     * @return string
58
     */
59
    protected function generateRandomKey()
60
    {
61
        return 'base64:'.base64_encode(
62
                Encrypter::generateKey($this->laravel['config']['eloquentaes.cipher'])
63
            );
64
    }
65
66
    /**
67
     * Set the application key in the environment file.
68
     *
69
     * @param  string  $key
70
     * @return bool
71
     */
72
    protected function setKeyInEnvironmentFile($key)
73
    {
74
        $currentKey = $this->laravel['config']['eloquentaes.key'];
75
76
        if (strlen($currentKey) !== 0 && (! $this->confirmToProceed())) {
77
            return false;
78
        }
79
80
        $this->writeNewEnvironmentFileWith($key);
81
82
        return true;
83
    }
84
85
    protected function environmentFileWithExists()
86
    {
87
        return preg_match(
88
            $this->keyReplacementPattern(),
89
            file_get_contents($this->laravel->environmentFilePath())
0 ignored issues
show
The method environmentFilePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean environment()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
90
        );
91
    }
92
93
    /**
94
     * Write a new environment file with the given key.
95
     *
96
     * @param  string  $key
97
     * @return void
98
     */
99
    protected function writeNewEnvironmentFileWith($key)
100
    {
101
        if($this->environmentFileWithExists()) {
102
            file_put_contents($this->laravel->environmentFilePath(), preg_replace(
0 ignored issues
show
The method environmentFilePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean environment()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
103
                $this->keyReplacementPattern(),
104
                'ELOQUENT_KEY=' . $key,
105
                file_get_contents($this->laravel->environmentFilePath())
0 ignored issues
show
The method environmentFilePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean environment()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
106
            ));
107
108
            return;
109
        }
110
        file_put_contents($this->laravel->environmentFilePath(),
0 ignored issues
show
The method environmentFilePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean environment()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
111
            file_get_contents($this->laravel->environmentFilePath()) . PHP_EOL .
0 ignored issues
show
The method environmentFilePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean environment()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
112
            '# You should backup this key in a safe secure place' . PHP_EOL .
113
            'ELOQUENT_KEY=' . $key . PHP_EOL
114
        );
115
    }
116
117
    /**
118
     * Get a regex pattern that will match env APP_KEY with any random key.
119
     *
120
     * @return string
121
     */
122
    protected function keyReplacementPattern()
123
    {
124
        $escaped = preg_quote('='.$this->laravel['config']['eloquentaes.key'], '/');
125
126
        return "/^ELOQUENT_KEY{$escaped}/m";
127
    }
128
}