Issues (116)

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.

Bundle/OAuthBundle/Security/OAuthAuthenticator.php (1 issue)

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
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\OAuthBundle\Security;
14
15
use Doctrine\Common\Collections\Collection;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
19
use Symfony\Component\Security\Core\Exception\AuthenticationException;
20
use Symfony\Component\Security\Core\Security;
21
use Symfony\Component\Security\Core\User\UserInterface;
22
use Symfony\Component\Security\Core\User\UserProviderInterface;
23
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
24
use WellCommerce\Bundle\CoreBundle\Helper\Request\RequestHelperInterface;
25
use WellCommerce\Bundle\OAuthBundle\Provider\OAuthProviderInterface;
26
27
/**
28
 * Class OAuthAuthenticator
29
 *
30
 * @author  Adam Piotrowski <[email protected]>
31
 */
32
final class OAuthAuthenticator extends AbstractGuardAuthenticator
33
{
34
    const PROVIDER_SESSION_KEY = '_oauth_provider';
35
36
    /**
37
     * @var Collection
38
     */
39
    private $providers;
40
41
    /**
42
     * @var RequestHelperInterface
43
     */
44
    private $requestHelper;
45
46
    public function __construct(Collection $providers, RequestHelperInterface $requestHelper)
47
    {
48
        $this->providers     = $providers;
49
        $this->requestHelper = $requestHelper;
50
    }
51
    
52
    public function getCredentials(Request $request)
53
    {
54
        if (null === $this->requestHelper->getSessionAttribute(self::PROVIDER_SESSION_KEY)) {
55
            return null;
56
        }
57
58
        return $this->getProvider()->getCredentials($request);
59
    }
60
    
61
    public function getUser($authorizationCode, UserProviderInterface $userProvider)
62
    {
63
        return $this->getProvider()->getUser($authorizationCode, $userProvider);
64
    }
65
    
66
    public function checkCredentials($credentials, UserInterface $user)
67
    {
68
        return true;
69
    }
70
    
71
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
72
    {
73
        $provider = $this->getProvider();
74
75
        $this->requestHelper->setSessionAttribute(Security::AUTHENTICATION_ERROR, $exception);
76
        $this->requestHelper->setSessionAttribute(self::PROVIDER_SESSION_KEY, null);
77
78
        return $provider->onAuthenticationFailure($request, $exception);
79
    }
80
    
81
    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
82
    {
83
        $provider = $this->getProvider();
84
85
        $this->requestHelper->setSessionAttribute(self::PROVIDER_SESSION_KEY, null);
86
87
        return $provider->onAuthenticationSuccess($request, $token, $providerKey);
88
    }
89
    
90
    public function supportsRememberMe()
91
    {
92
        return true;
93
    }
94
    
95
    public function start(Request $request, AuthenticationException $authException = null)
96
    {
97
        return $this->getProvider()->start($request, $authException);
98
    }
99
    
100
    public function createAuthenticatedToken(UserInterface $user, $providerKey)
101
    {
102
        return new UsernamePasswordToken(
0 ignored issues
show
Bug Best Practice introduced by Adam Piotrowski
The return type of return new \Symfony\Comp...ey, $user->getRoles()); (Symfony\Component\Securi...n\UsernamePasswordToken) is incompatible with the return type declared by the interface Symfony\Component\Securi...reateAuthenticatedToken of type Symfony\Component\Securi...ken\GuardTokenInterface.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
103
            $user,
104
            null,
105
            $providerKey,
106
            $user->getRoles()
107
        );
108
    }
109
    
110
    private function getProvider(): OAuthProviderInterface
111
    {
112
        $name = $this->requestHelper->getSessionAttribute(self::PROVIDER_SESSION_KEY);
113
        
114
        return $this->providers->get($name);
115
    }
116
}
117