Issues (260)

Security Analysis    not enabled

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.

core/App.php (7 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
/**
3
 * Created by rozbo at 2017/3/18 下午8:52
4
 */
5
6
namespace puck;
7
8
9
use Dotenv\Dotenv;
10
use Whoops\Run;
11
12
class App extends Container {
13
    /**
14
     * 已经加载的config文件
15
     *
16
     * @var array
17
     */
18
    protected $loadedConfigurations = [];
19
20
    /**
21
     * 应用的根目录.
22
     *
23
     * @var string
24
     */
25
    protected $basePath;
26
    public function __construct($basePath) {
27
        $this->basePath=$basePath;
28
        $this->initEnv();
29
        $this->initContainer();
30
        $this->initConfig();
31
    }
32
33
    private function initEnv(){
34
        try{
35
            $dotEnv = new Dotenv($this->basePath);
36
            $dotEnv->load();
37
        }
38
        catch (\Dotenv\Exception\InvalidPathException $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
39
40
        }
41
        date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai'));
42
        define('IS_CLI', $this->runningInConsole());
43
        define('IS_DEBUG',env('DEBUG',false));
44
        if (IS_DEBUG) {
45
            error_reporting(E_ALL);
46
            @ini_set('display_errors', 'On');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
47
            //@ob_start();
48
            $whoops=new Run;
49
            $handle=IS_CLI ? "PlainTextHandler" : "PrettyPageHandler";
50
            $handle="\\Whoops\\Handler\\".$handle;
51
            $whoops->pushHandler(new $handle);
52
            $whoops->register();
53
        }
54
55
    }
56
57
    /**
58
     * 判断是否是cli模式
59
     *
60
     * @return bool
61
     */
62
    public function runningInConsole() {
63
        return php_sapi_name() == 'cli';
64
    }
65
66
    /**
67
     * 初始化容器
68
     */
69
    private function initContainer() {
70
        static::setInstance($this);
71
        $this->instance('app',$this);
72
        $this->instance('config',new Config());
73
        $this->instance('request',new Request($this->config));
0 ignored issues
show
The property config does not seem to exist. Did you mean loadedConfigurations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
74
        $this->instance('route',new Route($this->request));
0 ignored issues
show
The property request does not exist on object<puck\App>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
        $this->regexBind('#^(\w+)_model$#', "\\app\\models\\\\$1");
76
        $this->bind('pinyin','\puck\helpers\PinYin');
77
        $this->bind('curl','\puck\helpers\Curl');
78
        $this->bind('dom', '\puck\helpers\Dom');
79
        $this->bind('db', '\puck\Db');
80
    }
81
82
    private function initConfig() {
83
        $this->configure('core');
84
    }
85
86
    /**
87
     * 加载一个配置文件
88
     *
89
     * @param  string  $name
90
     * @return void
91
     */
92
    public function configure($name)
93
    {
94
        if (isset($this->loadedConfigurations[$name])) {
95
            return;
96
        }
97
        //标记为已加载
98
        $this->loadedConfigurations[$name] = true;
99
        $path = $this->getConfigurationPath($name);
100
        if ($path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
101
            $this->make('config')->set($name, require $path);
102
        }
103
    }
104
105
    /**
106
     * 获取配置文件的路径。
107
     *
108
     * 如果没有给定配置文件的名字,则返回目录。
109
     *
110
     * 如果应用目录下有相应配置文件则优先返回。
111
     *
112
     * @param  string|null  $name
113
     * @return string
114
     */
115
    public function getConfigurationPath($name = null)
116
    {
117
        if (! $name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
118
            $appConfigDir = $this->basePath('configs').'/';
119
120
            if (file_exists($appConfigDir)) {
121
                return $appConfigDir;
122
            } elseif (file_exists($path = __DIR__.'/configs/')) {
123
                return $path;
124
            }
125
        } else {
126
            $appConfigPath = $this->basePath('configs').'/'.$name.'.php';
127
            if (file_exists($appConfigPath)) {
128
                return $appConfigPath;
129
            } elseif (file_exists($path = __DIR__.'/configs/'.$name.'.php')) {
130
                return $path;
131
            }
132
        }
133
    }
134
135
    /**
136
     * Get the base path for the application.
137
     *
138
     * @param  string|null $path
139
     * @return string
140
     */
141 3
    public function basePath($path = null) {
142 3
        if (isset($this->basePath)) {
143 3
            return $this->basePath . ($path ? '/' . $path : $path);
144
        }
145
146
        if ($this->runningInConsole()) {
147
            $this->basePath = getcwd();
148
        } else {
149
            $this->basePath = realpath(getcwd() . '/../');
150
        }
151
152
        return $this->basePath($path);
153
    }
154
155
    public function run() {
156
        $this->route->dispatch();
0 ignored issues
show
The property route does not exist on object<puck\App>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
157
    }
158
}