Issues (45)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

app/Middleware/Api.php (13 issues)

1
<?php
2
3
namespace App\Middleware;
4
5
use App\Models\Redirect;
0 ignored issues
show
This use statement conflicts with another class in this namespace, App\Middleware\Redirect. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Zend\Diactoros\Response\JsonResponse;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Interop\Http\ServerMiddleware\DelegateInterface;
9
use Interop\Http\ServerMiddleware\MiddlewareInterface;
10
11
class Api implements MiddlewareInterface
12
{
13
    /**
14
     * The request object.
15
     *
16
     * @var Psr\Http\Message\ServerRequestInterface
0 ignored issues
show
The type App\Middleware\Psr\Http\...\ServerRequestInterface was not found. Did you mean Psr\Http\Message\ServerRequestInterface? If so, make sure to prefix the type with \.
Loading history...
17
     */
18
    protected $request;
19
    /**
20
     * Return the current request.
21
     *
22
     * @return Psr\Http\Message\ServerRequestInterface
23
     */
24 2
    public function getRequest()
25
    {
26 2
        return $this->request;
27
    }
28
29
    /**
30
     * Set the current request object.
31
     *
32
     * @return void
33
     */
34 11
    public function setRequest(ServerRequestInterface $request)
35
    {
36 11
        $route = strtoupper($request->getMethod()) . ' ' . strtolower($request->getUri()->getPath());
37 11
        $this->request = $request->withAttribute('route', $route);
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->withAttribute('route', $route) of type Psr\Http\Message\ServerRequestInterface is incompatible with the declared type App\Middleware\Psr\Http\...\ServerRequestInterface of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38 11
    }
39
40
    /**
41
     * Checks if the current request is an authorized api request.
42
     *
43
     * @return boolean
44
     */
45 3
    public function isApi()
46
    {
47 3
        $this->request = $this->request->withAttribute('isApi', !!$this->request->getHeaderLine('Authorization'));
48 3
        return $this->request->getAttribute('isApi');
49
    }
50
51
    /**
52
     * Check if the current request is authorized for api access.
53
     *
54
     * @return boolean
55
     */
56 7
    public function isAuthorized()
57
    {
58 7
        $auth = substr($this->request->getHeaderLine('Authorization'), 7);
59 7
        return $this->request->getAttribute('config')['api_secret'] === $auth;
60
    }
61
62
    /**
63
     * List all redirects.
64
     *
65
     * @return void
66
     */
67 1
    public function show()
68
    {
69 1
        return new JsonResponse(Redirect::orderBy('created_at', 'DESC')->get());
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zend\Diactoro...ed_at', 'DESC')->get()) returns the type Zend\Diactoros\Response\JsonResponse which is incompatible with the documented return type void.
Loading history...
70
    }
71
72
    /**
73
     * Create a new redirect.
74
     *
75
     * @return App\Models\Create
0 ignored issues
show
The type App\Middleware\App\Models\Create was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
76
     */
77 2
    public function create()
78
    {
79 2
        $body = $this->request->getAttribute('body');
80 2
        if (isset($body['url'])) {
81 1
            return new JsonResponse(Redirect::createUnique($body['url']));
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zend\Diactoro...teUnique($body['url'])) returns the type Zend\Diactoros\Response\JsonResponse which is incompatible with the documented return type App\Middleware\App\Models\Create.
Loading history...
82
        }
83 1
        return new JsonResponse([
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zend\Diactoro...h url property.'), 400) returns the type Zend\Diactoros\Response\JsonResponse which is incompatible with the documented return type App\Middleware\App\Models\Create.
Loading history...
84 1
            'message' => 'Request must include json body with url property.'
85 1
        ], 400);
86
    }
87
88
    /**
89
     * Respond to the api request.
90
     *
91
     * @return Zend\Diactoros\Response\JsonResponse
0 ignored issues
show
The type App\Middleware\Zend\Diac...s\Response\JsonResponse was not found. Did you mean Zend\Diactoros\Response\JsonResponse? If so, make sure to prefix the type with \.
Loading history...
92
     */
93 5
    public function response()
94
    {
95 5
        if ($this->isAuthorized()) {
96 4
            switch ($this->request->getAttribute('route')) {
97 4
                case "GET /redirects":
98 1
                    return $this->show();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->show() returns the type void which is incompatible with the documented return type App\Middleware\Zend\Diac...s\Response\JsonResponse.
Loading history...
Are you sure the usage of $this->show() targeting App\Middleware\Api::show() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
99 3
                case "POST /redirects":
100 2
                    return $this->create();
101
                default:
102 1
                    return new JsonResponse(['status' => 'No such api endpoint'], 404);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zend\Diactoro...ch api endpoint'), 404) returns the type Zend\Diactoros\Response\JsonResponse which is incompatible with the documented return type App\Middleware\Zend\Diac...s\Response\JsonResponse.
Loading history...
103
            }
104
        }
105 1
        return new JsonResponse(['message' => 'Not authorized'], 403);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zend\Diactoro...'Not authorized'), 403) returns the type Zend\Diactoros\Response\JsonResponse which is incompatible with the documented return type App\Middleware\Zend\Diac...s\Response\JsonResponse.
Loading history...
106
    }
107
108
    /**
109
     * PSR-15 middleware callback
110
     *
111
     * @param ServerRequestInterface $request
112
     * @param DelegateInterface $delegate
113
     * @return Psr\Http\Message\ServerRequestInterface
114
     */
115 1
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
116
    {
117 1
        $this->setRequest($request);
118 1
        return ($this->isApi()) ? $this->response() : $delegate->process($this->getRequest());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->isApi() ? ...ss($this->getRequest()) also could return the type Psr\Http\Message\ResponseInterface which is incompatible with the documented return type App\Middleware\Psr\Http\...\ServerRequestInterface.
Loading history...
119
    }
120
}
121