GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6cbd46...4c991e )
by François
04:09
created

FileConfigStorage::getAllConfig()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 9
nc 4
nop 1
1
<?php
2
/**
3
 * Copyright 2015 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace fkooman\VPN\Server\Config;
19
20
use fkooman\Json\Json;
21
use RuntimeException;
22
23
class FileConfigStorage implements ConfigStorageInterface
24
{
25
    /** @var string */
26
    private $staticConfigDir;
27
28
    public function __construct($staticConfigDir)
29
    {
30
        $this->staticConfigDir = $staticConfigDir;
31
    }
32
33
    public function getConfig($commonName)
34
    {
35
        $commonNamePath = sprintf('%s/%s', $this->staticConfigDir, $commonName);
36
        try {
37
            return new ConfigData(Json::decodeFile($commonNamePath));
38
        } catch (RuntimeException $e) {
39
            return new ConfigData([]);
40
        }
41
    }
42
43
    public function getAllConfig($userId)
44
    {
45
        $configArray = [];
46
        $pathFilter = sprintf('%s/*', $this->staticConfigDir);
47
        if (!is_null($userId)) {
48
            $pathFilter = sprintf('%s/%s_*', $this->staticConfigDir, $userId);
49
        }
50
        foreach (glob($pathFilter) as $commonNamePath) {
0 ignored issues
show
Security File Exposure introduced by
$pathFilter can contain request data and is used in file inclusion context(s) leading to a potential security vulnerability.

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
51
            $commonName = basename($commonNamePath);
52
            $configArray[$commonName] = $this->getConfig($commonName)->toArray();
53
        }
54
55
        return $configArray;
56
    }
57
58
    public function setConfig($commonName, ConfigData $config)
59
    {
60
        $commonNamePath = sprintf('%s/%s', $this->staticConfigDir, $commonName);
61
62
        if (false === @file_put_contents($commonNamePath, Json::encode($config->toArray()))) {
63
            throw new RuntimeException('unable to write to static configuration file');
64
        }
65
    }
66
}
67