Issues (87)

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/Proxy/FunctionProxyGenerator.php (1 issue)

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
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2013, Lisachenko Alexander <[email protected]>
8
 *
9
 * This source file is subject to the license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Go\Proxy;
14
15
use Go\Aop\Framework\ReflectionFunctionInvocation;
16
use Go\Core\AspectContainer;
17
use Go\Core\AspectKernel;
18
use Go\ParserReflection\ReflectionFileNamespace;
19
use Go\Proxy\Part\FunctionCallArgumentListGenerator;
20
use Go\Proxy\Part\InterceptedFunctionGenerator;
21
use Laminas\Code\Generator\FileGenerator;
22
use Laminas\Code\Generator\ValueGenerator;
23
use ReflectionException;
24
use ReflectionFunction;
25
use ReflectionNamedType;
26
27
/**
28
 * Function proxy builder that is used to generate a proxy-function from the list of joinpoints
29
 */
30
class FunctionProxyGenerator
31
{
32
    /**
33
     * List of advices that are used for generation of child
34
     */
35
    protected array $adviceNames = [];
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
36
37
    /**
38
     * Instance of file generator
39
     */
40
    protected FileGenerator $fileGenerator;
41
42
    /**
43
     * Constructs functions stub class from namespace Reflection
44
     *
45
     * @param ReflectionFileNamespace $namespace            Reflection of namespace
46
     * @param string[][]              $adviceNames          List of function advices
47
     * @param bool                    $useParameterWidening Enables usage of parameter widening feature
48
     *
49
     * @throws ReflectionException If there is an advice for unknown function
50
     */
51
    public function __construct(
52
        ReflectionFileNamespace $namespace,
53
        array $adviceNames = [],
54
        bool $useParameterWidening = false
55
    ) {
56
        $this->adviceNames   = $adviceNames;
57
        $this->fileGenerator = new FileGenerator();
58
        $this->fileGenerator->setNamespace($namespace->getName());
59
60
        $functionsContent = [];
61
        $functionAdvices  = $adviceNames[AspectContainer::FUNCTION_PREFIX] ?? [];
62
        foreach (array_keys($functionAdvices) as $functionName) {
63
            $functionReflection  = new ReflectionFunction($functionName);
64
            $functionBody        = $this->getJoinpointInvocationBody($functionReflection);
65
            $interceptedFunction = new InterceptedFunctionGenerator($functionReflection, $functionBody, $useParameterWidening);
66
            $functionsContent[]  = $interceptedFunction->generate();
67
        }
68
69
        $this->fileGenerator->setBody(implode("\n", $functionsContent));
70
    }
71
72
    /**
73
     * Returns a joinpoint for specific function in the namespace
74
     *
75
     * @param array $adviceNames List of advices
76
     */
77
    public static function getJoinPoint(string $functionName, array $adviceNames): ReflectionFunctionInvocation
78
    {
79
        static $accessor;
80
81
        if ($accessor === null) {
82
            $accessor = AspectKernel::getInstance()->getContainer()->get('aspect.advisor.accessor');
83
        }
84
85
        $filledAdvices = [];
86
        foreach ($adviceNames as $advisorName) {
87
            $filledAdvices[] = $accessor->$advisorName;
88
        }
89
90
        return new ReflectionFunctionInvocation($filledAdvices, $functionName);
91
    }
92
93
    /**
94
     * Generates the source code of function proxies in given namespace
95
     */
96
    public function generate(): string
97
    {
98
        return $this->fileGenerator->generate();
99
    }
100
101
    /**
102
     * Creates string definition for function method body by function reflection
103
     */
104
    protected function getJoinpointInvocationBody(ReflectionFunction $function): string
105
    {
106
        $class = '\\' . self::class;
107
108
        $argumentList = new FunctionCallArgumentListGenerator($function);
109
        $argumentCode = $argumentList->generate();
110
111
        $return = 'return ';
112
        if ($function->hasReturnType()) {
113
            $returnType = $function->getReturnType();
114
            if ($returnType instanceof ReflectionNamedType && $returnType->getName() === 'void') {
115
                // void return types should not return anything
116
                $return = '';
117
            }
118
        }
119
120
        $functionAdvices = $this->adviceNames[AspectContainer::FUNCTION_PREFIX][$function->name];
121
        $advicesArray    = new ValueGenerator($functionAdvices, ValueGenerator::TYPE_ARRAY_SHORT);
122
        $advicesArray->setArrayDepth(1);
123
        $advicesCode = $advicesArray->generate();
124
125
        return <<<BODY
126
static \$__joinPoint;
127
if (\$__joinPoint === null) {
128
    \$__joinPoint = {$class}::getJoinPoint('{$function->name}', {$advicesCode});
129
}
130
{$return}\$__joinPoint->__invoke($argumentCode);
131
BODY;
132
    }
133
}
134