Issues (37)

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.

Security/User/Provider/RemoteUser.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
namespace Kaliop\IdentityManagementBundle\Security\User\Provider;
4
5
use Symfony\Component\Security\Core\User\UserProviderInterface;
6
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
7
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
use Kaliop\IdentityManagementBundle\Security\User\AMSUser as UserClass;
10
use Kaliop\IdentityManagementBundle\Security\User\RemoteUserProviderInterface;
11
use Kaliop\IdentityManagementBundle\Security\User\RemoteUser as KaliopRemoteUser;
12
use Kaliop\IdentityManagementBundle\Security\User\RemoteUserHandlerInterface;
13
use eZ\Publish\Core\MVC\Symfony\Security\User\APIUserProviderInterface;
14
use eZ\Publish\Core\MVC\Symfony\Security\User as eZMVCUser;
15
use Psr\Log\LoggerInterface;
16
17
class RemoteUser implements UserProviderInterface, RemoteUserProviderInterface
18
{
19
    protected $logger;
20
    protected $eZUserProvider;
21
    protected $handlerMap;
22
    protected $container;
23
24
    /**
25
     * @param APIUserProviderInterface $eZUserProvider the user provider to which we actually delegate finding eZ User
26
     * @param array $handlerMap
27
     */
28
    public function __construct(APIUserProviderInterface $eZUserProvider, array $handlerMap, $container)
29
    {
30
        $this->eZUserProvider = $eZUserProvider;
31
        $this->handlerMap = $handlerMap;
32
        $this->container = $container;
33
    }
34
35
    public function setLogger(LoggerInterface $logger)
36
    {
37
        $this->logger = $logger;
38
    }
39
40
    /**
41
     * @todo throw an exception ?
42
     * @param $username
43
     * @return UserInterface
44
     */
45
    public function loadUserByUsername($username)
46
    {
47
    }
48
49
    /**
50
     * This method is called *on every page after the user logged in*.
51
     * We do not want to call the remote ws on every page.
52
     * We 'might' check in the eZ db if the user is still there and/or enabled, BUT even that might be unnecessary, as
53
     * the remoteuser gets converted to an ezmvcuser by the listener, which means this is only called upon login?
54
     *
55
     * @param UserInterface $user
56
     * @return UserInterface
57
     */
58
    public function refreshUser(UserInterface $user)
59
    {
60
        if (!$user instanceof \Kaliop\IdentityManagementBundle\Security\User\RemoteUser) {
61
            throw new UnsupportedUserException(
62
                sprintf('Instances of "%s" are not supported.', get_class($user))
63
            );
64
        }
65
66
        return $user;
67
    }
68
69
    /**
70
     * Whether this provider supports the given user class.
71
     *
72
     * @param string $class
73
     *
74
     * @return bool
75
     */
76
    public function supportsClass($class)
77
    {
78
        $supportedClass = 'Kaliop\IdentityManagementBundle\Security\User\RemoteUser';
79
        return $class === $supportedClass || is_subclass_of($class, $supportedClass);
80
    }
81
82
    public function loadAPIUserByRemoteUser(KaliopRemoteUser $remoteUser)
83
    {
84
        $repoUser = null;
85
        $userHandler = $this->getHandler($remoteUser);
86
87
        // does eZ user exist? If not, create it, else update it
88
        // NB: it would be nice to be able to wrap these calls in a try/catch block to fix any error during ez user
89
        //     account creation/update, and simply disallow login.
90
        //     Unfortunately, it seems that if at this stage we return null, the Sf session will be set to a logged-in
91
        //     user, while eZP will think that it is an anon user. I tried to fix the Sf session so as to prevent the
92
        //     user from being logged in, without success.
93
        //     This forces the developer to do validation of the user profile data gotten from the remote service inside
94
        //     the client code, which is not as logical/clean...
95
        try {
96
            $repoUser = $userHandler->loadAPIUserByRemoteUser($remoteUser);
97
            if ($repoUser === false) {
98
                // we have to create an eZ MVC user out of an eZ Repo user
99
                $repoUser = $userHandler->createRepoUser($remoteUser);
100
            } else {
101
                $userHandler->updateRepoUser($remoteUser, $repoUser);
102
            }
103
104
            // In case any post-processing is needed, give the user-handler a chance to execute it without the need to
105
            // register further listeners
106
            if (is_callable(array($userHandler, 'onRemoteUserLogin'))) {
107
                $userHandler->onRemoteUserLogin($remoteUser, $repoUser);
0 ignored issues
show
The method onRemoteUserLogin() does not seem to exist on object<Kaliop\IdentityMa...teUserHandlerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
            }
109
110
        } catch (\Exception $e) {
111
            if ($this->logger) $this->logger->error("Unexpected error while finding/creating/updating repo user from data gotten from remote service: " . $e->getMessage());
112
            throw $e;
113
        }
114
115
        return $repoUser;
116
    }
117
118
    /**
119
     * @param KaliopRemoteUser $remoteUser
120
     * @return RemoteUserHandlerInterface
121
     * @throws \Exception
122
     */
123 View Code Duplication
    protected function getHandler($remoteUser)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125
        $class = get_class($remoteUser);
126
        if (!isset($this->handlerMap[$class])) {
127
            throw new \Exception("Can not load conversion handler for remote user of class $class");
128
        }
129
        return $this->container->get($this->handlerMap[$class]);
130
    }
131
132
    /**
133
     * A courtesy method, if some other service wants to retrieve a remote-user handler for a given php class.
134
     * Useful to retrieve the remote-user handler before the actual creation of the actual remote-user object, which
135
     * allows f.e. to put in the remote-user handler some validation code
136
     *
137
     * @param string $class a php class name
138
     * @return RemoteUserHandlerInterface
139
     * @throws \Exception
140
     */
141 View Code Duplication
    public function getHandlerForClass($class)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
    {
143
        if (!isset($this->handlerMap[$class])) {
144
            throw new \Exception("Can not load conversion handler for remote user of class $class");
145
        }
146
        return $this->container->get($this->handlerMap[$class]);
147
    }
148
}