Issues (1919)

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.

lib/Ajde/Resource/Local.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
class Ajde_Resource_Local extends Ajde_Resource
4
{
5
    private $_filename;
6
7
    public function __construct($type, $base, $action, $format = 'html', $arguments = '')
8
    {
9
        $this->setBase($base);
0 ignored issues
show
Documentation Bug introduced by
The method setBase does not exist on object<Ajde_Resource_Local>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
10
        $this->setAction($action);
0 ignored issues
show
Documentation Bug introduced by
The method setAction does not exist on object<Ajde_Resource_Local>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
11
        $this->setFormat($format);
0 ignored issues
show
Documentation Bug introduced by
The method setFormat does not exist on object<Ajde_Resource_Local>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
12
        $this->setArguments($arguments);
0 ignored issues
show
Documentation Bug introduced by
The method setArguments does not exist on object<Ajde_Resource_Local>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
13
        parent::__construct($type);
14
    }
15
16
    /**
17
     * @param string $type
18
     * @param string $base
19
     * @param string $action
20
     * @param string $format (optional)
21
     *
22
     * @return Ajde_Resource
23
     */
24
    public static function lazyCreate($type, $base, $action, $format = 'html')
25
    {
26
        if (self::getFilenameFromStatic($base, $type, $action, $format)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::getFilenameFromSta...type, $action, $format) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
27
            return new self($type, $base, $action, $format);
28
        }
29
30
        return false;
31
    }
32
33
    /**
34
     * @param string $hash
35
     *
36
     * @throws Ajde_Core_Exception_Deprecated
37
     * @throws Ajde_Exception
38
     *
39
     * @return Ajde_Resource
40
     */
41
    public static function fromHash($hash)
0 ignored issues
show
The parameter $hash is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        // TODO:
44
        throw new Ajde_Core_Exception_Deprecated();
45
        $session = new Ajde_Session('AC.Resource');
0 ignored issues
show
$session = new \Ajde_Session('AC.Resource'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
46
47
        return $session->get($hash);
48
    }
49
50
    public static function fromFingerprint($type, $fingerprint)
51
    {
52
        $array = self::decodeFingerprint($fingerprint);
53
        extract($array);
54
55
        return new self($type, $b, $a, $f);
56
    }
57
58
    public function getFingerprint()
59
    {
60
        $array = ['b' => $this->getBase(), 'a' => $this->getAction(), 'f' => $this->getFormat()];
61
62
        return $this->encodeFingerprint($array);
63
    }
64
65
    public function getBase()
66
    {
67
        return $this->get('base');
68
    }
69
70
    public function getAction()
71
    {
72
        return $this->get('action');
73
    }
74
75
    public function getFormat()
76
    {
77
        return $this->get('format');
78
    }
79
80
    public function getArguments()
81
    {
82
        return $this->get('arguments');
83
    }
84
85
    protected static function _getFilename($base, $type, $action, $format)
86
    {
87
        $dirPrefixPatterns = [
88
            CORE_DIR,
89
            APP_DIR,
90
        ];
91
        $layoutDir = 'layout.'.Ajde::app()->getDocument()->getLayout()->getName().DIRECTORY_SEPARATOR;
92
        $layoutPrefixPatterns = ['', $layoutDir];
93
94
        $filename = false;
95
96
        foreach ($dirPrefixPatterns as $dirPrefixPattern) {
97
            foreach ($layoutPrefixPatterns as $layoutPrefixPattern) {
98
                $prefixedBase = $dirPrefixPattern.$base;
99
                $formatResource = $prefixedBase.'res/'.$type.DIRECTORY_SEPARATOR.$layoutPrefixPattern.$action.'.'.$format.'.'.$type;
100
101
                if (self::exist($formatResource)) {
102
                    $filename = $formatResource;
103
                } else {
104
                    $noFormatResource = $prefixedBase.'res/'.$type.DIRECTORY_SEPARATOR.$layoutPrefixPattern.$action.'.'.$type;
105
                    if (self::exist($noFormatResource)) {
106
                        $filename = $noFormatResource;
107
                    }
108
                }
109
            }
110
        }
111
112
        return $filename;
113
    }
114
115
    public function getFilename()
116
    {
117
        if (!isset($this->_filename)) {
118
            $this->_filename = $this->_getFilename($this->getBase(), $this->getType(), $this->getAction(),
119
                $this->getFormat());
120
        }
121
122
        if (!$this->_filename) {
123
            // TODO:
124
            throw new Ajde_Exception(sprintf('Resource %s could not be found',
125
                $this->getBase().'res/'.$this->getType().DS.$this->getAction().'[.'.$this->getFormat().'].'.$this->getType()));
126
        }
127
128
        return $this->_filename;
129
    }
130
131
    public static function getFilenameFromStatic($base, $type, $action, $format)
132
    {
133
        return self::_getFilename($base, $type, $action, $format);
134
    }
135
136
    protected function getLinkUrl()
137
    {
138
        $base = '_core/component:resourceLocal';
139
        if (config('app.debug') === true) {
140
            $url = $base.'/'.urlencode($this->getFingerprint()).'.'.$this->getType().'?'.str_replace([
141
                    '%2F',
142
                    '%5C',
143
                ], ':', urlencode($this->getFilename()));
144
        } else {
145
            $url = $base.'/'.urlencode($this->getFingerprint()).'.'.$this->getType();
146
        }
147
148
        return $url;
149
    }
150
}
151