Issues (9)

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/YamlEncode.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
namespace Fitbug\SymfonySerializer\YamlEncoderDecoder;
4
5
use Symfony\Component\Serializer\Encoder\EncoderInterface;
6
use Symfony\Component\Serializer\Encoder\scalar;
7
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
8
use Symfony\Component\Yaml\Yaml;
9
10
class YamlEncode implements EncoderInterface
11
{
12
    const OPTION_OBJECT                    = 'yaml_encode_object';
13
    const OPTION_EXCEPTION_ON_INVALID_TYPE = 'yaml_encode_exception_on_invalid_type';
14
    const OPTION_OBJECT_FOR_MAP            = 'yaml_encode_object_for_map';
15
    const OPTION_MULTI_LINE_LITERAL_BLOCK  = 'yaml_encode_multi_line_literal_block';
16
    const OPTION_INLINE                    = 'yaml_encode_inline';
17
    const OPTION_INDENT                    = 'yaml_encode_indent';
18
    const SUPPORTED_ENCODING_YAML          = 'yaml';
19
20
    /**
21
     * @var bool
22
     */
23
    private $multiLineLiteralBlock;
24
25
    /**
26
     * @var bool
27
     */
28
    private $exceptionOnInvalidType;
29
30
    /**
31
     * @var bool
32
     */
33
    private $objectForMap;
34
35
    /**
36
     * @var bool
37
     */
38
    private $object;
39
    /**
40
     * @var int
41
     */
42
    private $indent;
43
    /**
44
     * @var int
45
     */
46
    private $inline;
47
48
    /**
49
     * Constructs a new YamlDecode instance.
50
     *
51
     * @param bool $object
52
     * @param bool $exceptionOnInvalidType
53
     * @param bool $objectForMap
54
     * @param bool $multiLineLiteralBlock
55
     * @param int  $inline
56
     * @param int  $indent
57
     */
58
    public function __construct(
59
        $object = false,
60
        $exceptionOnInvalidType = false,
61
        $objectForMap = false,
62
        $multiLineLiteralBlock = false,
63
        $inline = 2,
64
        $indent = 2
65
    ) {
66
        $this->object                 = $object;
67
        $this->exceptionOnInvalidType = $exceptionOnInvalidType;
68
        $this->objectForMap           = $objectForMap;
69
        $this->multiLineLiteralBlock  = $multiLineLiteralBlock;
70
        $this->indent                 = $indent;
71
72
        $this->inline = $inline;
73
    }
74
75
    /**
76
     * Encodes data into the given format.
77
     *
78
     * The only supported is yaml
79
     *
80
     * @param mixed  $data    Data to encode
81
     * @param string $format  Format name
82
     * @param array  $context options that normalizers/encoders have access to
83
     *
84
     * @return string
85
     *
86
     * @throws UnexpectedValueException
87
     */
88
    public function encode($data, $format, array $context = [])
89
    {
90
        $context = $this->resolveContext($context);
91
92
        if ($this->isYamlOldStyleInterface()) {
93
            $encodedData = Yaml::dump(
94
                $data,
95
                $context[ self::OPTION_INLINE ],
96
                $context[ self::OPTION_INDENT ],
97
                $context[ self::OPTION_EXCEPTION_ON_INVALID_TYPE ],
98
                $context[ self::OPTION_OBJECT ]
99
            );
100
101
        } else {
102
            $options = $this->contextToOptions($context);
103
104
            $encodedData = Yaml::dump(
105
                $data,
106
                $context[ self::OPTION_INLINE ],
107
                $context[ self::OPTION_INDENT ],
108
                $options
109
            );
110
        }
111
112
        return $encodedData;
113
    }
114
115
    /**
116
     * Merges the default options of the Yaml Encoder with the passed context.
117
     *
118
     * @param array $context
119
     *
120
     * @return array
121
     */
122
    private function resolveContext(array $context)
123
    {
124
        $defaultOptions = [
125
            self::OPTION_OBJECT                    => $this->object,
126
            self::OPTION_EXCEPTION_ON_INVALID_TYPE => $this->exceptionOnInvalidType,
127
            self::OPTION_OBJECT_FOR_MAP            => $this->objectForMap,
128
            self::OPTION_MULTI_LINE_LITERAL_BLOCK  => $this->multiLineLiteralBlock,
129
            self::OPTION_INLINE                    => $this->inline,
130
            self::OPTION_INDENT                    => $this->indent,
131
        ];
132
133
        return array_merge($defaultOptions, $context);
134
    }
135
136
    /**
137
     * Convert the context to options understood by the parser
138
     *
139
     * @param array $options
140
     *
141
     * @return int
142
     */
143 View Code Duplication
    private function contextToOptions(array $options)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
    {
145
        $optionToBitMap = [
146
            self::OPTION_OBJECT                    => Yaml::DUMP_OBJECT,
147
            self::OPTION_EXCEPTION_ON_INVALID_TYPE => Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE,
148
            self::OPTION_OBJECT_FOR_MAP            => Yaml::DUMP_OBJECT_AS_MAP,
149
            self::OPTION_MULTI_LINE_LITERAL_BLOCK  => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK,
150
        ];
151
152
        $bitMaskedOption = 0;
153
154
        foreach ($optionToBitMap as $option => $bitMask) {
155
            if ($options[ $option ]) {
156
                $bitMaskedOption = $bitMaskedOption | $bitMask;
157
            }
158
        }
159
160
        return $bitMaskedOption;
161
    }
162
163
164
    /**
165
     * Checks whether the serializer can encode to given format.
166
     *
167
     * The only supported format is yaml
168
     *
169
     * @param string $format format name
170
     *
171
     * @return bool
172
     */
173
    public function supportsEncoding($format)
174
    {
175
        return $format == self::SUPPORTED_ENCODING_YAML;
176
    }
177
178
    private function isYamlOldStyleInterface()
179
    {
180
        return !defined("Symfony\\Component\\Yaml\\Yaml::DUMP_OBJECT");
181
    }
182
}
183