Issues (5)

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/Resolver.php (2 issues)

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 Vssl\Render;
4
5
use Journey\Cache\CacheAdapterInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
class Resolver
10
{
11
    /**
12
     * The request object.
13
     *
14
     * @var \Psr\Http\Message\ServerRequestInterface
15
     */
16
    protected $request;
17
18
    /**
19
     * Configuration array.
20
     *
21
     * @var array
22
     */
23
    protected $config;
24
25
    /**
26
     * The page api object.
27
     *
28
     * @var \Vssl\Render\PageApi
29
     */
30
    protected $api;
31
32
    /**
33
     * Initialize a new Resolver
34
     */
35 11
    public function __construct(ServerRequestInterface $request, $config = false)
36
    {
37 11
        $this->request = $request;
38 11
        $this->config = is_array($config) ? static::config($config) : static::config();
0 ignored issues
show
$config is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39 11
        if (!$this->config['cache'] instanceof CacheAdapterInterface) {
40 1
            throw new ResolverException('Cache must implement \Journey\Cache\CacheAdapterInterface.');
41 1
        }
42 11
        $this->api = new PageApi($request, $this->config);
43 11
    }
44
45
    /**
46
     * Get a modified request message.
47
     *
48
     * @return \Psr\Http\Message\ServerRequestInterface
49
     */
50 4
    public function getRequest()
51
    {
52 4
        return $this->request->withAttribute('vssl-page', $this->resolve());
53
    }
54
55
    /**
56
     * Get an instance of the PageApi class.
57
     *
58
     * @return \Vssl\Render\PageApi
59
     */
60 3
    public function getPageApi()
61
    {
62 3
        return $this->api;
63
    }
64
65
    /**
66
     * Get the configuration settings.
67
     *
68
     * @return array
69
     */
70 1
    public function getConfig()
71
    {
72 1
        return $this->config;
73
    }
74
75
    /**
76
     * Get the configured CacheAdapterInterface.
77
     *
78
     * @return \Journey\Cache\CacheAdapterInterface
79
     */
80 1
    public function getCache()
81
    {
82 1
        return $this->config['cache'];
83
    }
84
85
    /**
86
     * Resolve the current page from WebStories. Returns a render able page or
87
     * false.
88
     *
89
     * @return array
90
     */
91 4
    public function resolve()
92
    {
93 4
        $response = $this->api->getPage($this->request->getUri()->getPath());
94 4
        if ($response && ($page = $this->decodePage($response))) {
95 3
            $status = $response->getStatusCode();
96
            return [
97 3
                'status' => $status,
98 3
                'data' => $page,
99 3
                'page' => (is_array($page) && $status == 200) ? new Renderer($this->config, $page) : $page,
100 3
                'metadata' => (is_array($page) && $status == 200) ? new Metadata($this->config, $page) : $page,
101 3
                'type' => !empty($page['type']) ? $page['type'] : false
102 3
            ];
103
        }
104
        return [
105 1
            'status' => false,
106 1
            'error' => 'An unknown error occurred',
107 1
            'data' => [],
108
            'type' => false
109 1
        ];
110
    }
111
112
    /**
113
     * Decode the body of a particular request.
114
     *
115
     * @return mixed
116
     */
117 4
    public function decodePage(ResponseInterface $response)
118
    {
119 4
        $body = (string) $response->getBody();
120 4
        if ($response->getHeaderLine('Content-Type') == "application/json") {
121 3
            $page = json_decode($body, true);
122 3
            return !empty($page['exists']) ? $page['page'] : false;
123
        }
124 1
        return false;
125
    }
126
127
    /**
128
     * Configure the resolver.
129
     *
130
     * @return void
131
     */
132 24
    public static function config($assign = false)
133
    {
134 24
        static $config;
135
136 24
        if (is_array($assign) || !$config) {
137 17
            $config = array_merge([
138 17
                'cache' => null,
139 17
                'cache_ttl' => false,
140 17
                'base_uri' => 'https://pages.vssl.io/',
141
                'required_fields' => [
142 17
                    'id',
143 17
                    'title',
144
                    'stripes'
145 17
                ],
146
                // 'templates' => 'your-directory'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147 17
            ], $assign);
148 17
        }
149 24
        return $config ?: [];
150
    }
151
}
152