Issues (13)

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.

Laravel5/JSendSerializer/JSendSerializer.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
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 8/16/15
6
 * Time: 4:43 AM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Laravel5\JSendSerializer;
12
13
use ErrorException;
14
use Illuminate\Database\Eloquent\Model;
15
use NilPortugues\Api\JSend\JSendTransformer;
16
use NilPortugues\Serializer\DeepCopySerializer;
17
use ReflectionClass;
18
use ReflectionMethod;
19
20
/**
21
 * Class JSendSerializer.
22
 */
23
class JSendSerializer extends DeepCopySerializer
24
{
25
    /**
26
     * @param JSendTransformer $jSendTransformer
27
     */
28
    public function __construct(JSendTransformer $jSendTransformer)
0 ignored issues
show
Unused Code Comprehensibility introduced by
Overwriting this method does not seem to be necessary. You may want to remove this method.
Loading history...
29
    {
30
        parent::__construct($jSendTransformer);
31
    }
32
33
    /**
34
     * Extract the data from an object.
35
     *
36
     * @param mixed $value
37
     *
38
     * @return array
39
     */
40
    protected function serializeObject($value)
41
    {
42 View Code Duplication
        if ($value instanceof \Illuminate\Database\Eloquent\Collection) {
43
            $items = [];
44
            foreach ($value as &$v) {
45
                $items[] = $this->serializeObject($v);
46
            }
47
48
            return [self::MAP_TYPE => 'array', self::SCALAR_VALUE => $items];
49
        }
50
51 View Code Duplication
        if ($value instanceof \Illuminate\Contracts\Pagination\Paginator) {
52
            $items = [];
53
            foreach ($value->items() as &$v) {
54
                $items[] = $this->serializeObject($v);
55
            }
56
57
            return [self::MAP_TYPE => 'array', self::SCALAR_VALUE => $items];
58
        }
59
        
60
        if (is_subclass_of($value, Model::class, true)) {
61
62
            $stdClass = (object) $value->getAttributes();
63
            $data =  $this->serializeData($stdClass);
64
            $data[self::CLASS_IDENTIFIER_KEY] = get_class($value);
65
66
            $methods = $this->getRelationshipMethodsAsPropertyName($value, get_class($value), new ReflectionClass($value));
67
68
            if (!empty($methods)) {
69
                $data = array_merge($data, $methods);
70
            }
71
72
            return $data;
73
        }
74
75
        return parent::serializeObject($value);
76
    }
77
78
    /**
79
     * @param                 $value
80
     * @param string          $className
81
     * @param ReflectionClass $reflection
82
     *
83
     * @return array
84
     */
85
    protected function getRelationshipMethodsAsPropertyName($value, $className, ReflectionClass $reflection)
86
    {
87
88
        $methods = [];
89
        foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
90
            if (ltrim($method->class, "\\") === ltrim($className, "\\")) {
91
92
                $name = $method->name;
93
                $reflectionMethod = $reflection->getMethod($name);
94
95
                // Eloquent relations do not include parameters, so we'll be filtering based on this criteria.
96
                if (0 == $reflectionMethod->getNumberOfParameters()) {
97
                    try {
98
                        $returned = $reflectionMethod->invoke($value);
99
                        //All operations (eg: boolean operations) are now filtered out.
100
                        if (is_object($returned)) {
101
102
                            // Only keep those methods as properties if these are returning Eloquent relations.
103
                            // But do not run the operation as it is an expensive operation.
104
                            if (false !== strpos(get_class($returned), 'Illuminate\Database\Eloquent\Relations')) {
105
106
                                $items = [];
107
                                foreach ($returned->getResults() as $model) {
108
109
                                    if (is_object($model)) {
110
                                        $stdClass = (object) $model->getAttributes();
111
                                        $data =  $this->serializeData($stdClass);
112
                                        $data[self::CLASS_IDENTIFIER_KEY] = get_class($model);
113
114
                                        $items[] = $data;
115
                                    }
116
                                }
117
                                if (!empty($items)) {
118
                                    $methods[$name] = [self::MAP_TYPE => 'array', self::SCALAR_VALUE => $items];
119
                                }
120
121
                            }
122
                        }
123
                    } catch (ErrorException $e) {}
124
                }
125
            }
126
        }
127
128
        return $methods;
129
    }
130
}
131