Issues (19)

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/FileParser/Php.php (1 issue)

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
/**
4
 * Konfig.
5
 *
6
 * Yet another simple configuration loader library.
7
 *
8
 * PHP version 5
9
 *
10
 * @category Library
11
 * @package  Konfig
12
 * @author   Xeriab Nabil (aka KodeBurner) <[email protected]>
13
 * @license  https://raw.github.com/xeriab/konfig/master/LICENSE MIT
14
 * @link     https://xeriab.github.io/projects/konfig
15
 */
16
17
namespace Exen\Konfig\FileParser;
18
19
use Exception;
20
use Exen\Konfig\Exception\ParseException;
21
use Exen\Konfig\Exception\UnsupportedFileFormatException;
22
23
/**
24
 * Konfig's PHP parser class.
25
 *
26
 * @category FileParser
27
 * @package  Konfig
28
 * @author   Xeriab Nabil (aka KodeBurner) <[email protected]>
29
 * @license  https://raw.github.com/xeriab/konfig/master/LICENSE MIT
30
 * @link     https://xeriab.github.io/projects/konfig
31
 *
32
 * @implements Exen\Konfig\FileParser\AbstractFileParser
33
 */
34
class Php extends AbstractFileParser
35
{
36
    /**
37
     * Loads a PHP file and gets its contents as an array.
38
     *
39
     * @param string $path File path
40
     *
41
     * @throws ParseException             If the PHP file throws an exception
42
     * @throws UnsupportedFormatException If the PHP file does not return an array
43
     *
44
     * @return array The parsed data
45
     *
46
     * @since 0.1.0
47
     */
48 12
    public function parse($path)
49
    {
50 12
        $data = null;
51
52
        // Require the file, if it throws an exception, rethrow it
53
        try {
54 12
            $data = $this->loadFile($path);
55 6
        } catch (Exception $ex) {
56 3
            throw new ParseException(
57
                [
58 3
                'message' => 'PHP file threw an exception',
59 3
                'file' => $path,
60 3
                'exception' => $ex,
61
                ]
62 1
            );
63
        }
64
65
        // If we have a callable, run it and expect an array back
66 9
        if (is_callable($data)) {
67 3
            $data = call_user_func($data);
68 1
        }
69
70
        // Check for array, if its anything else, throw an exception
71 9
        if (empty($data) || !is_array($data)) {
72 3
            throw new UnsupportedFileFormatException(
73 2
                'PHP file does not return an array'
74 1
            );
75
        }
76
77 6
        return $data;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     *
83
     * @return array Supported extensions
84
     *
85
     * @since 0.1.0
86
     */
87 3
    public function getSupportedFileExtensions()
88
    {
89 3
        return ['php', 'inc'];
90
    }
91
92
    /**
93
     * Loads in the given file and parses it.
94
     *
95
     * @param string|bool|null $file File to load
96
     *
97
     * @return array The parsed file data
98
     *
99
     * @since              0.2.4
100
     * @codeCoverageIgnore
101
     */
102
    protected function loadFile($file = null)
103
    {
104
        $this->file = is_file($file) ? $file : false;
0 ignored issues
show
Documentation Bug introduced by
It seems like is_file($file) ? $file : false can also be of type boolean. However, the property $file is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
105
106
        return include $this->file;
107
    }
108
109
    /**
110
     * Returns the formatted configuration file contents.
111
     *
112
     * @param array $contents configuration array
113
     *
114
     * @return string formatted configuration file contents
115
     *
116
     * @since              0.2.4
117
     * @codeCoverageIgnore
118
     */
119
    protected function exportFormat($contents = null)
120
    {
121
        throw new Exception(
122
            'Saving configuration to `PHP` is not supported at this time'
123
        );
124
    }
125
126
    /**
127
     * __toString.
128
     *
129
     * @return             string
130
     * @since              0.1.2
131
     * @codeCoverageIgnore
132
     */
133
    public function __toString()
134
    {
135
        return 'Exen\Konfig\FileParser\Php' . PHP_EOL;
136
    }
137
}
138
139
// END OF ./src/FileParser/Php.php FILE
140