Issues (23)

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/Interceptor/AbstractCache.php (1 issue)

Labels
Severity

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
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 *
13
 * This software consists of voluntary contributions made by many individuals
14
 * and is licensed under the MIT license.
15
 *
16
 * Copyright (c) 2015-2020 Yuuki Takezawa
17
 *
18
 */
19
20
namespace Ytake\LaravelAspect\Interceptor;
21
22
use Illuminate\Contracts\Cache\Repository;
23
use Ray\Aop\MethodInvocation;
24
use Ray\Aop\MethodInterceptor;
25
use Illuminate\Cache\CacheManager;
26
use Illuminate\Contracts\Cache\Factory;
27
use Doctrine\Common\Annotations\Annotation;
28
use Ytake\LaravelAspect\Annotation\AnnotationReaderTrait;
29
use Ytake\LaravelAspect\Annotation\Cacheable;
30
use Ytake\LaravelAspect\Annotation\CacheEvict;
31
use Ytake\LaravelAspect\Annotation\CachePut;
32
33
use function in_array;
34
use function is_array;
35
use function is_object;
36
use function is_null;
37
use function count;
38
use function get_class;
39
40
/**
41
 * Class AbstractCache
42
 */
43
abstract class AbstractCache implements MethodInterceptor
44
{
45
    use AnnotationReaderTrait;
46
47
    /** @var string */
48
    protected $join = ":";
49
50
    /** @var Factory|\Illuminate\Cache\CacheManager */
51
    protected static $factory;
52
53
    /**
54
     * @param string|array     $name
55
     * @param MethodInvocation $invocation
56
     *
57
     * @return array
58
     */
59
    protected function generateCacheName($name, MethodInvocation $invocation): array
60
    {
61
        if (is_array($name)) {
62
            throw new \InvalidArgumentException('Invalid argument');
63
        }
64
        if (is_null($name)) {
65
            $name = $invocation->getMethod()->name;
66
        }
67
68
        return [$name];
69
    }
70
71
    /**
72
     * @param MethodInvocation                         $invocation
73
     * @param Annotation|Cacheable|CacheEvict|CachePut $annotation
74
     * @param array                                    $keys
75
     *
76
     * @return array
77
     */
78
    protected function detectCacheKeys(
79
        MethodInvocation $invocation,
80
        Annotation $annotation,
81
        array $keys
82
    ): array {
83
        $arguments = $invocation->getArguments();
84
        foreach ($invocation->getMethod()->getParameters() as $parameter) {
85
            // exclude object
86
            if (in_array('#' . $parameter->name, $annotation->key)) {
87
                if (isset($arguments[$parameter->getPosition()])) {
88
                    if (!is_object($arguments[$parameter->getPosition()])) {
89
                        $keys[] = $arguments[$parameter->getPosition()];
90
                    }
91
                }
92
                if (!isset($arguments[$parameter->getPosition()])) {
93
                    $keys[] = $parameter->getDefaultValue();
94
                }
95
            }
96
        }
97
98
        return $keys;
99
    }
100
101
    /**
102
     * @param $annotation
103
     *
104
     * @return \Illuminate\Contracts\Cache\Repository
105
     */
106
    protected function detectCacheRepository($annotation): Repository
107
    {
108
        /** @var Factory|CacheManager $cacheFactory */
109
        $cacheFactory = self::$factory;
110
        $driver = (is_null($annotation->driver)) ? $cacheFactory->getDefaultDriver() : $annotation->driver;
111
        /** @var \Illuminate\Contracts\Cache\Repository|\Illuminate\Cache\TaggableStore $cache */
112
        $cache = $cacheFactory->store($driver);
113
        if (count($annotation->tags)) {
114
            $cache = $cache->tags($annotation->tags);
0 ignored issues
show
The method tags does only exist in Illuminate\Cache\TaggableStore, but not in Illuminate\Contracts\Cache\Repository.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
115
116
            return $cache;
117
        }
118
119
        return $cache;
120
    }
121
122
    /**
123
     * set cache instance
124
     *
125
     * @param Factory $factory
126
     */
127
    public function setCache(Factory $factory): void
128
    {
129
        static::$factory = $factory;
130
    }
131
132
    /**
133
     * @param string $glue
134
     * @param array  $array
135
     *
136
     * @return string
137
     */
138
    protected function recursiveImplode(string $glue, array $array): string
139
    {
140
        $return = '';
141
        $index = 0;
142
        $count = count($array);
143
        foreach ($array as $row) {
144
            if (is_array($row)) {
145
                $return .= $this->recursiveImplode($glue, $row);
146
            } else {
147
                $return .= (is_object($row)) ? get_class($row) : $row;
148
            }
149
            if ($index < $count - 1) {
150
                $return .= $glue;
151
            }
152
            ++$index;
153
        }
154
155
        return $return;
156
    }
157
}
158