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.php (8 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
abstract class Ajde_Resource extends Ajde_Object_Standard
4
{
5
    const TYPE_JAVASCRIPT = 'js';
6
    const TYPE_STYLESHEET = 'css';
7
8
    public function __construct($type)
9
    {
10
        $this->setType($type);
0 ignored issues
show
Documentation Bug introduced by
The method setType does not exist on object<Ajde_Resource>? 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
    }
12
13
    public function __toString()
14
    {
15
        return implode(', ', $this->_data);
16
    }
17
18
    abstract public function getFilename();
19
20
    abstract protected function getLinkUrl();
21
22
    protected static function exist($filename)
23
    {
24
        if (is_file(self::realpath($filename))) {
25
            return true;
26
        }
27
28
        return false;
29
    }
30
31
    protected static function realpath($filename)
32
    {
33
        //        dump($filename, realpath(LOCAL_ROOT . $filename));
34
        return realpath(LOCAL_ROOT.$filename);
35
    }
36
37
    public static function encodeFingerprint($array)
38
    {
39
        return self::_urlEncode(serialize($array));
40
    }
41
42
    public static function decodeFingerprint($fingerprint)
43
    {
44
        return unserialize(self::_urlDecode($fingerprint));
45
    }
46
47
    public static function _urlDecode($string)
48
    {
49
        return base64_decode($string);
50
    }
51
52
    public static function _urlEncode($string)
53
    {
54
        return base64_encode($string);
55
    }
56
57
    public static function getLinkTemplateFilename($type, $format = 'null')
58
    {
59
        if (Ajde::app()->getDocument()->hasLayout()) {
0 ignored issues
show
Documentation Bug introduced by
The method hasLayout does not exist on object<Ajde_Document>? 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...
60
            $layout = Ajde::app()->getDocument()->getLayout();
61
        } else {
62
            $layout = new Ajde_Layout(config('layout.frontend'));
63
        }
64
        $format = issetor($format, 'html');
0 ignored issues
show
Are you sure the assignment to $format is correct as issetor($format, 'html') (which targets issetor()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
65
66
        $dirPrefixPatterns = [
67
            APP_DIR,
68
            CORE_DIR,
69
        ];
70
        foreach ($dirPrefixPatterns as $dirPrefixPattern) {
71
            $prefixedLayout = $dirPrefixPattern.LAYOUT_DIR;
72
            if (self::exist($prefixedLayout.$layout->getName().'/link/'.$type.'.'.$format.'.php')) {
73
                return $prefixedLayout.$layout->getName().'/link/'.$type.'.'.$format.'.php';
74
            }
75
        }
76
77
        return false;
78
    }
79
80
    public function getType()
81
    {
82
        return $this->get('type');
83
    }
84
85
    public function setPosition($position)
86
    {
87
        $this->set('position', $position);
88
    }
89
90
    public function getPosition()
91
    {
92
        return $this->get('position');
93
    }
94
95
    protected function _getLinkTemplateFilename()
96
    {
97
        $format = $this->hasFormat() ? $this->getFormat() : null;
0 ignored issues
show
Documentation Bug introduced by
The method hasFormat does not exist on object<Ajde_Resource>? 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...
Documentation Bug introduced by
The method getFormat does not exist on object<Ajde_Resource>? 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...
98
99
        return self::getLinkTemplateFilename($this->getType(), $format);
100
    }
101
102
    public function getLinkCode()
103
    {
104
        ob_start();
105
106
        // variables for use in included link template
107
        $url = $this->getLinkUrl();
108
        $arguments = $this->hasArguments() ? $this->getArguments() : '';
0 ignored issues
show
Documentation Bug introduced by
The method hasArguments does not exist on object<Ajde_Resource>? 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...
Documentation Bug introduced by
The method getArguments does not exist on object<Ajde_Resource>? 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...
109
110
        // create temporary resource for link filename
111
        $linkFilename = $this->_getLinkTemplateFilename();
112
113
        // TODO: performance gain?
114
        // Ajde_Cache::getInstance()->addFile($linkFilename);
115
        if ($linkFilename) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $linkFilename 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...
116
            include LOCAL_ROOT.$linkFilename;
117
        } else {
118
            throw new Ajde_Exception('Link filename for '.$url.' not found');
119
        }
120
121
        $contents = ob_get_contents();
122
        ob_end_clean();
123
124
        return $contents;
125
    }
126
127
    public function getContents()
128
    {
129
        ob_start();
130
131
        $filename = $this->getFilename();
132
133
        Ajde_Cache::getInstance()->addFile($filename);
134
        if ($this->exist($filename)) {
135
            include $this->realpath($filename);
136
        } else {
137
            throw new Exception("Couldn't find resource ".$filename);
138
        }
139
140
        $contents = ob_get_contents();
141
        ob_end_clean();
142
143
        return $contents;
144
    }
145
}
146