Issues (24)

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/Reader/FileReader.php (2 issues)

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 Balloon\Reader;
3
4
/**
5
 * Class FileReader
6
 * @package Balloon\Reader
7
 * @author Raphaël Lefebvre <[email protected]>
8
 */
9
class FileReader implements IFileReader
10
{
11
    /**
12
     * @var string
13
     */
14
    private $filePath;
15
16
    /**
17
     * @var bool
18
     */
19
    private $useIncludePath;
20
21
    /**
22
     * @var resource
23
     */
24
    private $context;
25
26
    /**
27
     * @var bool
28
     */
29
    private $exists = false;
30
31
    /**
32
     * @param string $filePath
33
     * @param bool $useIncludePath
34
     * @param resource $context
0 ignored issues
show
Should the type for parameter $context not be resource|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
35
     */
36
    public function __construct($filePath, $useIncludePath = false, $context = null)
37
    {
38
        $this->setFilePath($filePath);
39
        $this->setUseIncludePath($useIncludePath);
40
        $this->setContext($context);
0 ignored issues
show
It seems like $context defined by parameter $context on line 36 can also be of type null; however, Balloon\Reader\FileReader::setContext() does only seem to accept resource, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function read()
47
    {
48
        if(!$this->isExistingFile()){
49
            return '';
50
        }
51
        return file_get_contents($this->getFilePath(), $this->useIncludePath(), $this->getContext());
52
    }
53
54
    /**
55
     * @param string $data
56
     * @param int $mode
57
     * @return int
58
     */
59
    public function write($data, $mode = 0)
60
    {
61
        $this->createDir();
62
        return file_put_contents($this->getFilePath(), $data, $mode, $this->getContext());
63
    }
64
65
    /**
66
     * @return bool
67
     */
68
    public function isExistingFile()
69
    {
70
        if (!$this->exists) {
71
            $this->exists = file_exists($this->getFilePath());
72
        }
73
        return $this->exists;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isExistingDir()
80
    {
81
        if (!$this->exists) {
82
            $this->exists = is_dir($this->getDir());
83
        }
84
        return $this->exists;
85
    }
86
87
    /**
88
     * Getter of $filePath
89
     *
90
     * @return string
91
     */
92
    public function getFilePath()
93
    {
94
        return $this->filePath;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getDir()
101
    {
102
        return dirname($this->getFilePath());
103
    }
104
105
    /**
106
     * Getter of $useIncludePath
107
     *
108
     * @return boolean
109
     */
110
    public function useIncludePath()
111
    {
112
        return $this->useIncludePath;
113
    }
114
115
    /**
116
     * Getter of $context
117
     *
118
     * @return resource
119
     */
120
    public function getContext()
121
    {
122
        return $this->context;
123
    }
124
125
    /**
126
     * Setter of $filePath
127
     *
128
     * @param string $filePath
129
     */
130
    private function setFilePath($filePath)
131
    {
132
        $this->filePath = (string)$filePath;
133
    }
134
135
    /**
136
     * Setter of $useIncludePath
137
     *
138
     * @param boolean $useIncludePath
139
     */
140
    private function setUseIncludePath($useIncludePath)
141
    {
142
        $this->useIncludePath = (boolean)$useIncludePath;
143
    }
144
145
    /**
146
     * Setter of $context
147
     *
148
     * @param resource $context
149
     */
150
    private function setContext($context)
151
    {
152
        $this->context = $context;
153
    }
154
155
    /**
156
     *
157
     */
158
    private function createDir()
159
    {
160
        if (!$this->isExistingDir()) {
161
            mkdir($this->getDir(), 0777, true);
162
            $this->exists = true;
163
        }
164
    }
165
}
166
167