Issues (71)

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/Http/Middleware/CreateFreshApiToken.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
declare(strict_types=1);
4
5
namespace Rinvex\Oauth\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Response;
9
use Illuminate\Http\JsonResponse;
10
use Rinvex\Oauth\Factories\ApiTokenCookieFactory;
11
12
class CreateFreshApiToken
13
{
14
    /**
15
     * The API token cookie factory instance.
16
     *
17
     * @var \Rinvex\Oauth\Factories\ApiTokenCookieFactory
18
     */
19
    protected $cookieFactory;
20
21
    /**
22
     * The authentication guard.
23
     *
24
     * @var string
25
     */
26
    protected $guard;
27
28
    /**
29
     * Create a new middleware instance.
30
     *
31
     * @param \Rinvex\Oauth\Factories\ApiTokenCookieFactory $cookieFactory
32
     *
33
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
34
     */
35
    public function __construct(ApiTokenCookieFactory $cookieFactory)
36
    {
37
        $this->cookieFactory = $cookieFactory;
38
    }
39
40
    /**
41
     * Handle an incoming request.
42
     *
43
     * @param \Illuminate\Http\Request $request
44
     * @param \Closure                 $next
45
     * @param string|null              $guard
46
     *
47
     * @return mixed
48
     */
49
    public function handle($request, Closure $next, $guard = null)
50
    {
51
        $this->guard = $guard;
52
53
        $response = $next($request);
54
55
        if ($this->shouldReceiveFreshToken($request, $response)) {
56
            $response->withCookie($this->cookieFactory->make(
57
                $request->user($this->guard)->getAuthIdentifier(),
58
                $request->session()->token()
0 ignored issues
show
The method token cannot be called on $request->session() (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
59
            ));
60
        }
61
62
        return $response;
63
    }
64
65
    /**
66
     * Determine if the given request should receive a fresh token.
67
     *
68
     * @param \Illuminate\Http\Request  $request
69
     * @param \Illuminate\Http\Response $response
70
     *
71
     * @return bool
72
     */
73
    protected function shouldReceiveFreshToken($request, $response)
74
    {
75
        return $this->requestShouldReceiveFreshToken($request) &&
76
               $this->responseShouldReceiveFreshToken($response);
77
    }
78
79
    /**
80
     * Determine if the request should receive a fresh token.
81
     *
82
     * @param \Illuminate\Http\Request $request
83
     *
84
     * @return bool
85
     */
86
    protected function requestShouldReceiveFreshToken($request)
87
    {
88
        return $request->isMethod('GET') && $request->user($this->guard);
89
    }
90
91
    /**
92
     * Determine if the response should receive a fresh token.
93
     *
94
     * @param \Illuminate\Http\Response $response
95
     *
96
     * @return bool
97
     */
98
    protected function responseShouldReceiveFreshToken($response)
99
    {
100
        return ($response instanceof Response ||
101
                $response instanceof JsonResponse) &&
102
                ! $this->alreadyContainsToken($response);
103
    }
104
105
    /**
106
     * Determine if the given response already contains an API token.
107
     *
108
     * This avoids us overwriting a just "refreshed" token.
109
     *
110
     * @param \Illuminate\Http\Response $response
111
     *
112
     * @return bool
113
     */
114
    protected function alreadyContainsToken($response)
115
    {
116
        foreach ($response->headers->getCookies() as $cookie) {
117
            if ($cookie->getName() === config('rinvex.oauth.cookie')) {
118
                return true;
119
            }
120
        }
121
122
        return false;
123
    }
124
}
125