Issues (4)

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/Console/Command/VersioningHelper.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 Swatty007\LaravelVersioningHelper\Console\Command;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\App;
8
use Illuminate\Support\Facades\Cache;
9
use Illuminate\Support\Facades\Config;
10
use PHLAK\SemVer;
11
12
class VersioningHelper extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'versioning:helper
20
        {--major= : Major Version}
21
        {--minor= : Minor Version}
22
        {--patch= : Patch Version}
23
        {--preRelease= : Pre-Release Version}
24
        {--build= : Build Version}
25
26
        {--incrementMajor : Increment Major Version}
27
        {--incrementMinor : Increment Minor Version}
28
        {--incrementPatch : Increment Patch Version}
29
30
        {--parse=true : Defines version should be parsed. (Automatically applies build & modification date from your versioning system) }
31
    ';
32
33
    /**
34
     * The console command description.
35
     *
36
     * @var string
37
     */
38
    protected $description = 'Helper Command to set your applications version.';
39
40
    /**
41
     * Current Version
42
     *
43
     */
44
    public SemVer\Version $version;
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...
45
46
    /**
47
     * Defines the modification date of our current revision
48
     *
49
     * @var Carbon
50
     */
51
    public Carbon $modificationDate;
52
53
    /**
54
     * Defines the current PHP runtime at which our application runs
55
     * @var string
56
     */
57
    public string $runtime;
58
59
    /**
60
     * Create a new command instance.
61
     *
62
     * @return void
63
     */
64
    public function __construct()
65
    {
66
        parent::__construct();
67
    }
68
69
    /**
70
     * Execute the console command.
71
     *
72
     * @return int
73
     * @throws SemVer\Exceptions\InvalidVersionException
74
     */
75
    public function handle(): int
76
    {
77
        $this->version = new SemVer\Version();
78
79
        $currentVersion = Cache::pull(config('laravel-versioning-helper.version_key')) ?? Config::get(config('laravel-versioning-helper.version_key'));
80
        if ($currentVersion) {
81
            $this->version->setVersion($currentVersion);
82
        }
83
84
        $this->applyOptions();
85
86
        $this->info("Current Version: " . $currentVersion);
87
        $this->line("New Version: " . $this->version);
88
89
        $this->parseBuild();
90
91
        $this->saveVersion();
92
93
        return 0;
94
    }
95
96
    /**
97
     * Helper Method to apply our Commands Options
98
     *
99
     */
100
    private function applyOptions()
101
    {
102
        $options = $this->options();
103
104
        if (isset($options['major'])) {
105
            $this->version->setMajor($options['major']);
106
        }
107
        if (isset($options['minor'])) {
108
            $this->version->setMinor($options['minor']);
109
        }
110
        if (isset($options['patch'])) {
111
            $this->version->setPatch($options['patch']);
112
        }
113
        if (isset($options['preRelease'])) {
114
            $this->version->setPreRelease($options['preRelease']);
115
        }
116
        if (isset($options['build'])) {
117
            $this->version->setBuild($options['build']);
118
        }
119
120
        if ($options['incrementMajor']) {
121
            $this->version->incrementMajor();
122
        }
123
        if ($options['incrementMinor']) {
124
            $this->version->incrementMinor();
125
        }
126
        if ($options['incrementPatch']) {
127
            $this->version->incrementPatch();
128
        }
129
    }
130
131
    /**
132
     * Helper Method to assemble a version string based on our used repository system
133
     *
134
     */
135
    private function parseBuild()
136
    {
137
        $versioningSystem = config('laravel-versioning-helper.versioning_system');
138
139
        switch ($versioningSystem) {
140
            case 'git':
141
                // For git we can use the tag to receive our version number as fallback
142
                $currentVersion = config('laravel-versioning-helper.version') ?? exec('git describe --tags --abbrev=0');
143
                // And the latest hash as our revision Nr
144
                $revision = trim(exec('git log --pretty="%h" -n1 HEAD'));
145
                $modificationDate = Carbon::parse(trim(exec('git log -n1 --pretty=%ci HEAD')));
146
                break;
147
            case 'svn':
148
                // For SVN we have to take our version from our config & assume it was set by a build script!
149
                $currentVersion = config('laravel-versioning-helper.version');
150
                // and SVNs latest rev as our revision
151
                $revision = exec("svn info | grep 'Last Changed Rev' | awk '{ print $4; }'");
152
                $modificationDate = Carbon::parse(trim(exec("svn info | grep 'Last Changed Date' | awk '{ print $4 \" \" $5; }'")));
153
                break;
154
            case 'self-updater':
155
                $currentVersion = config('laravel-versioning-helper.version');
156
                $revision = '';
157
                $modificationDate = Carbon::parse(config('self-update.version_date'));
158
                break;
159
            default:
160
                $currentVersion = '0.0.0';
161
                $revision = '';
162
                $modificationDate = Carbon::now();
163
                break;
164
        }
165
166
        if ($modificationDate) {
167
            $this->modificationDate = $modificationDate;
168
        }
169
170
        if ($currentVersion && $this->options()['parse']) {
171
            $this->version->setVersion($currentVersion);
172
            $this->version->setBuild($revision);
173
        }
174
175
        if (!App::environment('production')) {
176
            $this->runtime = 'PHP v' . PHP_VERSION;
177
        }
178
    }
179
180
    /**
181
     * Helper Method to save our applications version within the system
182
     */
183
    private function saveVersion()
184
    {
185
        Cache::put(config('laravel-versioning-helper.version_key'), $this->version);
186
        Cache::put(config('laravel-versioning-helper.modification_date_key'), $this->modificationDate);
187
        Cache::put(config('laravel-versioning-helper.runtime_key'), $this->runtime);
188
    }
189
}
190