Issues (13)

Security Analysis    not enabled

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/Providers/LaravelServiceProvider.php (3 issues)

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
namespace Realshadow\RequestDeserializer\Providers;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\AnnotationRegistry;
7
use Illuminate\Foundation\Application;
8
use Illuminate\Support\ServiceProvider;
9
use JMS\Serializer\EventDispatcher\EventDispatcher;
10
use JMS\Serializer\SerializerBuilder;
11
use JsonSchema\Constraints\Constraint;
12
use JsonSchema\Constraints\Factory;
13
use JsonSchema\SchemaStorage;
14
use JsonSchema\Uri\UriRetriever;
15
use JsonSchema\Validator;
16
use Realshadow\RequestDeserializer\Console\Commands\Schema\ConvertCommand;
17
use Realshadow\RequestDeserializer\JsonSchema\Uri\Retrievers\FileGetContents;
18
use Realshadow\RequestDeserializer\Http\Request\RequestDeserializationHandler;
19
use Realshadow\RequestDeserializer\Http\Request\RequestHandler;
20
use Realshadow\RequestDeserializer\Serializers\LaravelSerializer;
21
22
23
/**
24
 * Service provider for API wrapper responsible for loading all neccessary components
25
 *
26
 * @package Realshadow\RequestDeserializer\Providers
27
 * @author Lukáš Homza <[email protected]>
28
 */
29
class LaravelServiceProvider extends ServiceProvider
30
{
31
32
    const CONFIG_KEY = 'request_deserializer';
33
34
    /**
35
     * Initializes serializer with required laravel bindings
36
     *
37
     * @return SerializerBuilder
38
     */
39
    protected function prepareSerializer()
40
    {
41
        return (new LaravelSerializer())->getBuilderInstance();
42
    }
43
44
    /**
45
     * Register third party providers
46
     */
47
    protected function registerProviders()
48
    {
49
        //region Purifier
50
        $this->app->register(\Mews\Purifier\PurifierServiceProvider::class);
51
52
        $this->app->bind('purifier', \Realshadow\RequestDeserializer\Validation\Purifier::class);
53
        //endregion
54
    }
55
56
    /**
57
     * Registers/binds all third party classes to service container and/or autoloader
58
     *
59
     * @throws \InvalidArgumentException
60
     */
61
    protected function registerClasses()
62
    {
63
        //region Annotations
64
        AnnotationRegistry::registerLoader('class_exists');
65
66
        $this->app->singleton('app.annotation_reader', function (Application $app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
            return new AnnotationReader;
68
        });
69
        //endregion
70
71
        //region Serializer
72
        $this->app->singleton('api.serializer', function (Application $app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
            return $this->prepareSerializer()->build();
74
        });
75
        //endregion
76
77
        //region JSON Schema Constraint
78
        $this->app->singleton('api.schema.constraint', function (Application $app) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
            $fileRetriever = new FileGetContents;
80
            $fileRetriever->setBasePath(config(self::CONFIG_KEY . '.request.schema_path') . DIRECTORY_SEPARATOR);
81
82
            $retriever = (new UriRetriever)
83
                ->setUriRetriever($fileRetriever);
84
85
            $constraintFactory = new Factory(new SchemaStorage($retriever));
86
            $constraintFactory->setConfig(Constraint::CHECK_MODE_APPLY_DEFAULTS | Constraint::CHECK_MODE_COERCE_TYPES);
87
88
            return $constraintFactory;
89
        });
90
        //endregion
91
92
        //region JSON Schema Validator
93
        $this->app->singleton('api.schema.validator', function (Application $app) {
94
            return new Validator(
95
                $app->make('api.schema.constraint')
96
            );
97
        });
98
        //endregion
99
100
        //region RequestHandler
101
        $this->app->singleton(RequestHandler::class, function (Application $app) {
102
            $serializer = $this->prepareSerializer()
103
                ->configureListeners(function (EventDispatcher $dispatcher) use ($app) {
104
                    $dispatcher->addSubscriber(
105
                        new RequestDeserializationHandler(
106
                            $app->make('api.schema.validator'),
107
                            $app->make('purifier')
108
                        )
109
                    );
110
                })
111
                ->build();
112
113
            return new RequestHandler($serializer);
114
        });
115
        //endregion
116
    }
117
118
    /**
119
     * Registers all provided console commands
120
     */
121
    protected function registerCommands()
122
    {
123
        $this->commands([
124
            ConvertCommand::class,
125
        ]);
126
    }
127
128
    /**
129
     * Perform post-registration booting of services
130
     */
131
    public function boot()
132
    {
133
        if ($this->app->runningInConsole()) {
134
            $this->registerCommands();
135
        }
136
137
        $this->publishes([__DIR__ . '/../../config/purifier.php' => config_path('purifier.php')]);
138
139
        $this->mergeConfigFrom(
140
            __DIR__ . '/../../config/request_deserializer.php',
141
            'request_deserializer'
142
        );
143
    }
144
145
    /**
146
     * Register every component
147
     *
148
     * @throws \InvalidArgumentException
149
     */
150
    public function register()
151
    {
152
        $this->registerProviders();
153
154
        $this->registerClasses();
155
    }
156
157
}
158