Issues (737)

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/Plugin/ContainerAwarePluginManager.php (6 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
 * @file
5
 * Contains \Drupal\service_container\Plugin\ContainerAwarePluginManager
6
 */
7
8
namespace Drupal\service_container\Plugin;
9
10
use Drupal\Component\Plugin\Exception\PluginException;
11
use Drupal\Component\Plugin\PluginManagerInterface;
12
use Drupal\service_container\DependencyInjection\ContainerAware;
13
14
/**
15
 * Base class for plugin managers.
16
 */
17
class ContainerAwarePluginManager extends ContainerAware implements PluginManagerInterface {
18
19
  /**
20
   * Constructs a ContainerAwarePluginManager object.
21
   *
22
   * @param string $service_prefix
23
   *   The service prefix used to get the plugin instances from the container.
24
   */
25
  public function __construct($service_prefix) {
26
    $this->servicePrefix = $service_prefix;
0 ignored issues
show
The property servicePrefix does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
  }
28
29
  /**
30
   * {@inheritdoc}
31
   */
32
  public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
33
    return $this->container->getDefinition($this->servicePrefix . $plugin_id, $exception_on_invalid);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Depend...tion\ContainerInterface as the method getDefinition() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, Drupal\Core\DependencyInjection\ContainerBuilder, Drupal\service_container...encyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...\Tests\ProjectContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
34
  }
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public function getDefinitions() {
40
    $definitions =  $this->container->getDefinitions();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Depend...tion\ContainerInterface as the method getDefinitions() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, Drupal\Core\DependencyInjection\ContainerBuilder, Drupal\service_container...encyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...\Tests\ProjectContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
41
    $prefix = $this->servicePrefix;
42
43
    // Note: ARRAY_FILTER_USE_BOTH is not supported in HHVM and PHP 5.4.
44
    $keys = array_filter(array_keys($definitions),
45
      function($key) use ($prefix) {
46
        return strpos($key, $prefix) === 0;
47
      });
48
    return array_intersect_key($definitions, array_flip($keys));
49
  }
50
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public function hasDefinition($plugin_id) {
55
    return $this->container->hasDefinition($this->servicePrefix . $plugin_id);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Depend...tion\ContainerInterface as the method hasDefinition() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, Drupal\Core\DependencyInjection\ContainerBuilder, Drupal\service_container...encyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...\Tests\ProjectContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
56
  }
57
58
  /**
59
   * {@inheritdoc}
60
   */
61
  public function createInstance($plugin_id, array $configuration = array()) {
62
    $plugin_definition_copy = $plugin_definition = $this->getDefinition($plugin_id);
63
    $plugin_class = static::getPluginClass($plugin_id, $plugin_definition);
64
65
    // If the plugin provides a factory method, pass the container to it.
66
    if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
67
      return $plugin_class::create($this->container, $configuration, $plugin_id, $plugin_definition);
68
    }
69
70
    $plugin_definition += array(
71
      'arguments' => array(),
72
    );
73
74
    array_unshift($plugin_definition['arguments'], $plugin_definition_copy);
75
    array_unshift($plugin_definition['arguments'], $plugin_id);
76
    array_unshift($plugin_definition['arguments'], $configuration);
77
78
    // Otherwise, create the plugin directly.
79
    return $this->container->createInstance($this->servicePrefix . $plugin_id, $plugin_definition);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Depend...tion\ContainerInterface as the method createInstance() does only exist in the following implementations of said interface: Drupal\service_container...encyInjection\Container.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
80
  }
81
82
  /**
83
   * {@inheritdoc}
84
   */
85
  public function getInstance(array $options) {
86
    // 90% of core does not use the generic $mapper functionality, so use a
87
    // sane default function.
88
    if (isset($options['id'])) {
89
      return $this->createInstance($options['id']);
90
    }
91
    return FALSE;
92
  }
93
94
  /**
95
   * Finds the class relevant for a given plugin.
96
   *
97
   * @param string $plugin_id
98
   *   The id of a plugin.
99
   * @param mixed $plugin_definition
100
   *   The plugin definition associated with the plugin ID.
101
   * @param string $required_interface
102
   *   (optional) THe required plugin interface.
103
   *
104
   * @return string
105
   *   The appropriate class name.
106
   *
107
   * @throws \Drupal\Component\Plugin\Exception\PluginException
108
   *   Thrown when there is no class specified, the class doesn't exist, or
109
   *   the class does not implement the specified required interface.
110
   *
111
   */
112
  public static function getPluginClass($plugin_id, $plugin_definition = NULL, $required_interface = NULL) {
113
    if (empty($plugin_definition['class'])) {
114
      throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
115
    }
116
117
    $class = $plugin_definition['class'];
118
119
    if (!class_exists($class)) {
120
      throw new PluginException(sprintf('Plugin (%s) instance class "%s" does not exist.', $plugin_id, $class));
121
    }
122
123
    if ($required_interface && !is_subclass_of($plugin_definition['class'], $required_interface)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $required_interface of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
124
      throw new PluginException(sprintf('Plugin "%s" (%s) in %s should implement interface %s.', $plugin_id, $plugin_definition['class'], $plugin_definition['provider'], $required_interface));
125
    }
126
127
    return $class;
128
  }
129
}
130