Issues (11)

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.

Security/ShibbolethAuthenticationProvider.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
namespace Kuleuven\AuthenticationBundle\Security;
4
5
use Kuleuven\AuthenticationBundle\Traits\LoggerTrait;
6
use Psr\Log\LoggerAwareInterface;
7
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
8
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
9
use Symfony\Component\Security\Core\Exception\AuthenticationException;
10
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
11
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
12
use Symfony\Component\Security\Core\Role\SwitchUserRole;
13
use Symfony\Component\Security\Core\User\UserCheckerInterface;
14
use Symfony\Component\Security\Core\User\UserProviderInterface;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
17
class ShibbolethAuthenticationProvider implements AuthenticationProviderInterface, LoggerAwareInterface
18
{
19
    use LoggerTrait;
20
21
    /**
22
     * @var UserProviderInterface
23
     */
24
    protected $userProvider;
25
26
    /**
27
     * @var UserCheckerInterface
28
     */
29
    protected $userChecker;
30
31
    /**
32
     * @var string
33
     */
34
    protected $providerKey;
35
36
    /**
37
     * @param UserProviderInterface $userProvider
38
     * @param UserCheckerInterface  $userChecker
39
     * @param string                $providerKey
40
     */
41
    public function __construct(UserProviderInterface $userProvider, UserCheckerInterface $userChecker, $providerKey)
42
    {
43
        $this->userProvider = $userProvider;
44
        $this->userChecker = $userChecker;
45
        $this->providerKey = $providerKey;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function authenticate(TokenInterface $token)
52
    {
53
        if (!$this->supports($token)) {
54
            $this->log(sprintf('Token not supported: %s', $token));
55
            return null;
56
        }
57
58
        if (!$user = $token->getUser()) {
59
            $this->log(sprintf('User not found in token: %s', $token));
60
            throw new BadCredentialsException('User not found in request.');
61
        }
62
63
        // Reattach the objects to Doctrine
64
        $username = $token->getUsername();
65
66
        try {
67 View Code Duplication
            if ($user instanceof UserInterface) {
0 ignored issues
show
This code seems to be duplicated across 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...
68
                $token->setUser($this->userProvider->refreshUser($user));
69
                $user = $token->getUser();
70
            } else {
71
                $user = $this->userProvider->loadUserByUsername($username);
72
            }
73
            if (empty($user) || !$user instanceof UserInterface) {
74
                $this->log(sprintf('User not found for username "%s"', $username));
75
                throw new AuthenticationException('Shibboleth authentication failed.');
76
            }
77
            $this->log(sprintf('User found for username "%s": %s', $username, $user));
78
79
            foreach ($token->getRoles() as $role) {
80 View Code Duplication
                if ($role instanceof SwitchUserRole) {
0 ignored issues
show
This code seems to be duplicated across 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...
81
                    $source = $role->getSource();
82
                    $sourceUser = $source->getUser();
83
                    if ($sourceUser instanceof UserInterface) {
84
                        $source->setUser($this->userProvider->refreshUser($sourceUser));
85
                    }
86
                }
87
            }
88
        } catch (UsernameNotFoundException $notFound) {
89
            $this->log(sprintf('User not found for username "%s": %s', $username, $notFound->getMessage()));
90
            throw new AuthenticationException('Shibboleth authentication failed.', 0, $notFound);
91
        }
92
93
        if ($user instanceof UserInterface) {
94
            $this->userChecker->checkPostAuth($user);
95
        }
96
97
        $authenticatedToken = new KuleuvenUserToken($user, $user->getAttributes(), $this->providerKey, $token->getRoles());
98
        $authenticatedToken->setAuthenticated(true);
99
        $this->log(sprintf('Token authenticated for username "%s": %s', $authenticatedToken->getUsername(), $authenticatedToken));
100
101
        return $authenticatedToken;
102
    }
103
104
    /**
105
     * @inheritdoc
106
     */
107
    public function supports(TokenInterface $token)
108
    {
109
        return $token instanceof KuleuvenUserToken;
110
    }
111
}
112