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.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Infrastructure/FLockerStore.php (3 issues)

1
<?php
2
/**
3
 * This file is part of the LockerManager package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LockerManager\Infrastructure;
12
13
use Cocur\Slugify\Slugify;
14
use LockerManager\Domain\Lock;
15
use LockerManager\Infrastructure\Exception\ExistingKeyException;
16
use LockerManager\Infrastructure\Exception\InvalidArgumentException;
17
use LockerManager\Infrastructure\Exception\LockingKeyException;
18
use LockerManager\Infrastructure\Exception\NotExistingKeyException;
19
20
class FLockerStore implements LockerStoreInterface
21
{
22
    /**
23
     * @var null|string
24
     */
25
    private $lockPath;
26
27
    /**
28
     * FLockerStore constructor.
29
     * @param null $lockPath
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $lockPath is correct as it would always require null to be passed?
Loading history...
30
     */
31
    public function __construct($lockPath = null)
32
    {
33
        if (null === $lockPath) {
34
            $lockPath = sys_get_temp_dir();
35
        }
36
37
        if (!is_dir($lockPath)) {
38
            mkdir($lockPath, 0755, true);
39
        }
40
41
        if (!is_writable($lockPath)) {
42
            throw new InvalidArgumentException(sprintf('The directory "%s" is not writable.', $lockPath));
43
        }
44
45
        $this->lockPath = $lockPath;
46
    }
47
48
    /**
49
     * @param Lock $lock
50
     * @throws ExistingKeyException
51
     */
52 View Code Duplication
    public function acquire(Lock $lock)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $key = $lock->key();
55
        $fileName = $this->getLockPath($key);
56
57
        if (file_exists($fileName)) {
58
            throw new ExistingKeyException(sprintf('The key "%s" already exists.', $key));
59
        }
60
61
        $this->save($lock, $fileName);
62
    }
63
64
    /**
65
     * @param Lock $lock
66
     * @param $fileName
67
     * @throws LockingKeyException
68
     */
69
    private function save(Lock $lock, $fileName)
70
    {
71
        $file = @fopen($fileName, 'w');
72
73
        if (flock($file, LOCK_EX)) {
74
            fwrite($file, serialize($lock));
75
            flock($file, LOCK_UN);
76
        } else {
77
            throw new LockingKeyException(sprintf('Error locking file "%s".', $lock->key()));
78
        }
79
80
        fclose($file);
81
    }
82
83
    /**
84
     * clear all locks
85
     */
86
    public function clear()
87
    {
88
        $files = scandir($this->lockPath);
89
90
        foreach ($files as $file) {
91
            if (is_file($this->lockPath.$file)) {
92
                unlink($this->lockPath.$file);
93
            }
94
        }
95
    }
96
97
    /**
98
     * @param $key
99
     * @throws NotExistingKeyException
100
     */
101
    public function delete($key)
102
    {
103
        if (!$this->exists($key)) {
104
            throw new NotExistingKeyException(sprintf('The key "%s" does not exists.', $key));
105
        }
106
107
        unlink($this->getLockPath($key));
108
    }
109
110
    /**
111
     * @param $key
112
     * @return bool
113
     */
114
    public function exists($key)
115
    {
116
        if (!@fopen($this->getLockPath($key), 'r')) {
117
            return false;
118
        }
119
120
        return true;
121
    }
122
123
    /**
124
     * @param $key
125
     * @return string
126
     */
127
    private function getLockPath($key)
128
    {
129
        return $this->lockPath.(new Slugify())->slugify($key).'.lock';
130
    }
131
132
    /**
133
     * @param $key
134
     * @return mixed
135
     * @throws NotExistingKeyException
136
     */
137
    public function get($key)
138
    {
139
        if (!$this->exists($key)) {
140
            throw new NotExistingKeyException(sprintf('The key "%s" does not exists.', $key));
141
        }
142
143
        return unserialize(file_get_contents($this->getLockPath($key)));
144
    }
145
146
    /**
147
     * @return array
148
     */
149
    public function getAll()
150
    {
151
        $files = scandir($this->lockPath);
152
        $locks = [];
153
154
        unset($files[0]);
155
        unset($files[1]);
156
157
        foreach ($files as $lock) {
158
            $locks[] = str_replace('.lock', '', $lock);
159
        }
160
161
        return array_values($locks);
162
    }
163
164
    /**
165
     * @param $key
166
     * @param $payload
167
     * @throws LockingKeyException
168
     * @throws NotExistingKeyException
169
     */
170 View Code Duplication
    public function update($key, $payload)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
    {
172
        $fileName = $this->getLockPath($key);
173
174
        if (!file_exists($fileName)) {
175
            throw new NotExistingKeyException(sprintf('The key "%s" does not exists.', $key));
176
        }
177
178
        /** @var Lock $lock */
179
        $lock = $this->get($key);
180
        $lock->update($payload);
181
182
        $this->save($lock, $fileName);
183
    }
184
}
185