Issues (43)

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.

Service/RefreshToken.php (3 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
/*
4
 * This file is part of the GesdinetJWTRefreshTokenBundle package.
5
 *
6
 * (c) Gesdinet <http://www.gesdinet.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gesdinet\JWTRefreshTokenBundle\Service;
13
14
use Gesdinet\JWTRefreshTokenBundle\Event\RefreshEvent;
15
use Gesdinet\JWTRefreshTokenBundle\Security\Authenticator\RefreshTokenAuthenticator;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
18
use InvalidArgumentException;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\Security\Core\Exception\AuthenticationException;
21
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
22
use Gesdinet\JWTRefreshTokenBundle\Security\Provider\RefreshTokenProvider;
23
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
24
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
25
26
/**
27
 * Class RefreshToken.
28
 */
29
class RefreshToken
30
{
31
    /**
32
     * @var RefreshTokenAuthenticator
33
     */
34
    private $authenticator;
35 4
36
    /**
37 4
     * @var RefreshTokenProvider
38 4
     */
39 4
    private $provider;
40 4
41 4
    /**
42 4
     * @var AuthenticationSuccessHandlerInterface
43 4
     */
44 4
    private $successHandler;
45 4
46
    /**
47
     * @var AuthenticationFailureHandlerInterface
48
     */
49
    private $failureHandler;
50
51
    /**
52
     * @var RefreshTokenManagerInterface
53
     */
54
    private $refreshTokenManager;
55
56 3
    /**
57
     * @var int
58
     */
59 3
    private $ttl;
60 3
61 3
    /**
62 3
     * @var string
63
     */
64
    private $providerKey;
65
66 3
    /**
67
     * @var bool
68 3
     */
69 1
    private $ttlUpdate;
70 1
71 1
    /**
72 1
     * @var EventDispatcherInterface
73
     */
74
    private $eventDispatcher;
75 2
76 1
    /**
77 1
     * RefreshToken constructor.
78 1
     *
79
     * @param RefreshTokenAuthenticator             $authenticator
80 1
     * @param RefreshTokenProvider                  $provider
81 1
     * @param AuthenticationSuccessHandlerInterface $successHandler
82
     * @param AuthenticationFailureHandlerInterface $failureHandler
83 2
     * @param RefreshTokenManagerInterface          $refreshTokenManager
84
     * @param int                                   $ttl
85
     * @param string                                $providerKey
86
     * @param bool                                  $ttlUpdate
87
     * @param EventDispatcherInterface              $eventDispatcher
88
     */
89
    public function __construct(
90
        RefreshTokenAuthenticator $authenticator,
91
        RefreshTokenProvider $provider,
92
        AuthenticationSuccessHandlerInterface $successHandler,
93
        AuthenticationFailureHandlerInterface $failureHandler,
94
        RefreshTokenManagerInterface $refreshTokenManager,
95
        $ttl,
96
        $providerKey,
97
        $ttlUpdate,
98
        EventDispatcherInterface $eventDispatcher
99
    ) {
100
        $this->authenticator = $authenticator;
101
        $this->provider = $provider;
102
        $this->successHandler = $successHandler;
103
        $this->failureHandler = $failureHandler;
104
        $this->refreshTokenManager = $refreshTokenManager;
105
        $this->ttl = $ttl;
106
        $this->providerKey = $providerKey;
107
        $this->ttlUpdate = $ttlUpdate;
108
        $this->eventDispatcher = $eventDispatcher;
109
    }
110
111
    /**
112
     * Refresh token.
113
     *
114
     * @param Request $request
115
     *
116
     * @return mixed
117
     *
118
     * @throws InvalidArgumentException
119
     * @throws AuthenticationException
120
     */
121
    public function refresh(Request $request)
122
    {
123
        try {
124
            $user = $this->authenticator->getUser(
125
                $this->authenticator->getCredentials($request),
126
                $this->provider
127
            );
128
129
            $postAuthenticationToken = $this->authenticator->createAuthenticatedToken($user, $this->providerKey);
0 ignored issues
show
It seems like $user defined by $this->authenticator->ge...uest), $this->provider) on line 124 can be null; however, Symfony\Component\Securi...ateAuthenticatedToken() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
130
        } catch (AuthenticationException $e) {
131
            return $this->failureHandler->onAuthenticationFailure($request, $e);
132
        }
133
134
        $refreshToken = $this->refreshTokenManager->get($this->authenticator->getCredentials($request));
0 ignored issues
show
$this->authenticator->getCredentials($request) is of type array<string,*,{"token":"*"}>, but the function expects a string.

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...
135
136
        if (null === $refreshToken || !$refreshToken->isValid()) {
137
            return $this->failureHandler->onAuthenticationFailure($request, new AuthenticationException(
138
                    sprintf('Refresh token "%s" is invalid.', $refreshToken)
139
                )
140
            );
141
        }
142
143
        if ($this->ttlUpdate) {
144
            $expirationDate = new \DateTime();
145
            $expirationDate->modify(sprintf('+%d seconds', $this->ttl));
146
            $refreshToken->setValid($expirationDate);
147
148
            $this->refreshTokenManager->save($refreshToken);
149
        }
150
151
        if ($this->eventDispatcher instanceof ContractsEventDispatcherInterface) {
0 ignored issues
show
The class Symfony\Contracts\EventD...ventDispatcherInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
152
            $this->eventDispatcher->dispatch(new RefreshEvent($refreshToken, $postAuthenticationToken), 'gesdinet.refresh_token');
153
        } else {
154
            $this->eventDispatcher->dispatch('gesdinet.refresh_token', new RefreshEvent($refreshToken, $postAuthenticationToken));
155
        }
156
157
        return $this->successHandler->onAuthenticationSuccess($request, $postAuthenticationToken);
158
    }
159
}
160