Issues (1446)

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.

LazyLoadingGhost/MethodGenerator/MagicGetTest.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
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
6
7
use Laminas\Code\Generator\MethodGenerator;
8
use Laminas\Code\Generator\PropertyGenerator;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
12
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
13
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\PrivatePropertiesMap;
14
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\ProtectedPropertiesMap;
15
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
16
use ProxyManagerTestAsset\BaseClass;
17
use ProxyManagerTestAsset\ClassWithMagicMethods;
18
use ReflectionClass;
19
20
/**
21
 * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet}
22
 *
23
 * @group Coverage
24
 */
25
final class MagicGetTest extends TestCase
26
{
27
    /** @var PropertyGenerator&MockObject */
28
    private PropertyGenerator $initializer;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
29
30
    /** @var MethodGenerator&MockObject */
31
    private MethodGenerator $initMethod;
32
33
    /** @var PublicPropertiesMap&MockObject */
34
    private PublicPropertiesMap $publicProperties;
35
36
    /** @var ProtectedPropertiesMap&MockObject */
37
    private ProtectedPropertiesMap $protectedProperties;
38
39
    /** @var PrivatePropertiesMap&MockObject */
40
    private PrivatePropertiesMap $privateProperties;
41
42
    /** @var InitializationTracker&MockObject */
43
    private InitializationTracker $initializationTracker;
44
45
    /** @var string */
46
    private string $expectedCode = <<<'PHP'
47
$this->foo && ! $this->init && $this->baz('__get', array('name' => $name));
48
49
if (isset(self::$bar[$name])) {
50
    return $this->$name;
51
}
52
53
if (isset(self::$baz[$name])) {
54
    if ($this->init) {
55
        return $this->$name;
56
    }
57
58
    // check protected property access via compatible class
59
    $callers      = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
60
    $caller       = isset($callers[1]) ? $callers[1] : [];
61
    $object       = isset($caller['object']) ? $caller['object'] : '';
62
    $expectedType = self::$baz[$name];
63
64
    if ($object instanceof $expectedType) {
65
        return $this->$name;
66
    }
67
68
    $class = isset($caller['class']) ? $caller['class'] : '';
69
70
    if ($class === $expectedType || is_subclass_of($class, $expectedType) || $class === 'ReflectionProperty') {
71
        return $this->$name;
72
    }
73
} elseif (isset(self::$tab[$name])) {
74
    // check private property access via same class
75
    $callers = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
76
    $caller  = isset($callers[1]) ? $callers[1] : [];
77
    $class   = isset($caller['class']) ? $caller['class'] : '';
78
79
    static $accessorCache = [];
80
81
    if (isset(self::$tab[$name][$class])) {
82
        $cacheKey = $class . '#' . $name;
83
        $accessor = isset($accessorCache[$cacheKey])
84
            ? $accessorCache[$cacheKey]
85
            : $accessorCache[$cacheKey] = \Closure::bind(static function & ($instance) use ($name) {
86
                return $instance->$name;
87
            }, null, $class);
88
89
        return $accessor($this);
90
    }
91
92
    if ($this->init || 'ReflectionProperty' === $class) {
93
        $tmpClass = key(self::$tab[$name]);
94
        $cacheKey = $tmpClass . '#' . $name;
95
        $accessor = isset($accessorCache[$cacheKey])
96
            ? $accessorCache[$cacheKey]
97
            : $accessorCache[$cacheKey] = \Closure::bind(static function & ($instance) use ($name) {
98
                return $instance->$name;
99
            }, null, $tmpClass);
100
101
        return $accessor($this);
102
    }
103
}
104
105
%a
106
PHP;
107
108
    /**
109
     * {@inheritDoc}
110
     */
111
    protected function setUp() : void
112
    {
113
        $this->initializer           = $this->createMock(PropertyGenerator::class);
114
        $this->initMethod            = $this->createMock(MethodGenerator::class);
115
        $this->publicProperties      = $this->createMock(PublicPropertiesMap::class);
116
        $this->protectedProperties   = $this->createMock(ProtectedPropertiesMap::class);
117
        $this->privateProperties     = $this->createMock(PrivatePropertiesMap::class);
118
        $this->initializationTracker = $this->createMock(InitializationTracker::class);
119
120
        $this->initializer->method('getName')->willReturn('foo');
121
        $this->initMethod->method('getName')->willReturn('baz');
122
        $this->publicProperties->method('isEmpty')->willReturn(false);
123
        $this->publicProperties->method('getName')->willReturn('bar');
124
        $this->protectedProperties->method('getName')->willReturn('baz');
125
        $this->privateProperties->method('getName')->willReturn('tab');
126
        $this->initializationTracker->method('getName')->willReturn('init');
127
    }
128
129
    /**
130
     * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet
131
     */
132
    public function testBodyStructure() : void
133
    {
134
        $magicGet = new MagicGet(
135
            new ReflectionClass(BaseClass::class),
136
            $this->initializer,
137
            $this->initMethod,
138
            $this->publicProperties,
139
            $this->protectedProperties,
140
            $this->privateProperties,
141
            $this->initializationTracker
142
        );
143
144
        self::assertSame('__get', $magicGet->getName());
145
        self::assertCount(1, $magicGet->getParameters());
146
147
        self::assertStringMatchesFormat($this->expectedCode, $magicGet->getBody());
148
    }
149
150
    /**
151
     * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet
152
     */
153
    public function testBodyStructureWithOverriddenMagicGet() : void
154
    {
155
        $magicGet = new MagicGet(
156
            new ReflectionClass(ClassWithMagicMethods::class),
157
            $this->initializer,
158
            $this->initMethod,
159
            $this->publicProperties,
160
            $this->protectedProperties,
161
            $this->privateProperties,
162
            $this->initializationTracker
163
        );
164
165
        self::assertSame('__get', $magicGet->getName());
166
        self::assertCount(1, $magicGet->getParameters());
167
168
        self::assertStringMatchesFormat($this->expectedCode, $magicGet->getBody());
169
        self::assertStringMatchesFormat('%Areturn parent::__get($name);', $magicGet->getBody());
170
    }
171
}
172