Issues (3)

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.

src/AbstractCouchbaseBucketFactory.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 WebPT\ZendCouchbaseModule;
4
5
use Assert\Assertion;
6
use Zend\ServiceManager\AbstractFactoryInterface;
7
use Zend\ServiceManager\ServiceLocatorInterface;
8
9
class AbstractCouchbaseBucketFactory implements AbstractFactoryInterface
10
{
11
    /**
12
     * Determine if we can create a service with name
13
     *
14
     * @param ServiceLocatorInterface $serviceLocator
15
     * @param $name
16
     * @param $requestedName
17
     * @return bool
18
     */
19 1
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
20
    {
21 1
        return stripos($requestedName, 'couchbase.') === 0 && substr_count($requestedName, '.') === 2;
22
    }
23
    
24
    /**
25
     * Create service with name
26
     *
27
     * @param ServiceLocatorInterface $serviceLocator
28
     * @param string $name
29
     * @param string $requestedName
30
     * @return \CouchbaseBucket
31
     * @throws \RuntimeException
32
     * @throws \Assert\AssertionFailedException
33
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
34
     */
35
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
36
    {
37
        $components = explode('.', $requestedName);
38
        Assertion::count($components, 3);
39
        
40
        $moduleConfig = $this->getModuleConfig($serviceLocator);
41
        
42
        $clusterOptions = $this->getClusterOptions($moduleConfig, $components[1]);
43
        
44
        $bucketOptions = $this->getBucketOptions($moduleConfig, $components[2]);
45
        
46
        $cluster = $this->createCouchbaseCluster($clusterOptions);
47
        
48
        return $this->createCouchbaseBucket($cluster, $bucketOptions);
49
    }
50
    
51
    /**
52
     * @param \CouchbaseCluster $cluster
53
     * @param BucketOptions $options
54
     * @return \CouchbaseBucket
55
     */
56
    public function createCouchbaseBucket(\CouchbaseCluster $cluster, BucketOptions $options)
57
    {
58
        return $cluster->openBucket($options->getBucket(), $options->getPassword());
59
    }
60
    
61
    /**
62
     * @param ClusterOptions $options
63
     * @return \CouchbaseCluster
64
     * @throws \RuntimeException
65
     */
66
    public function createCouchbaseCluster(ClusterOptions $options)
67
    {
68
        if (class_exists('\Couchbase\Cluster', true)) {
69
            $class = '\Couchbase\Cluster';
70
            return new $class($options->getDsn());
71
        }
72
        
73
        if (class_exists('\CouchbaseCluster', true)) {
74
            return new \CouchbaseCluster($options->getDsn(), $options->getUsername(), $options->getPassword());
75
        }
76
        
77
        throw new \RuntimeException('Extension couchbase is required.');
78
    }
79
    
80
    /**
81
     * @param ServiceLocatorInterface $serviceLocator
82
     * @return array
83
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
84
     * @throws \Assert\AssertionFailedException
85
     */
86 3
    public function getModuleConfig(ServiceLocatorInterface $serviceLocator)
87
    {
88 3
        $config = $serviceLocator->get('config');
89 3
        Assertion::isArray($config);
90
    
91 3
        Assertion::keyExists($config, 'webpt/zend-couchbase-module');
92 3
        $moduleConfig = $config['webpt/zend-couchbase-module'];
93 3
        Assertion::isArray($moduleConfig);
94
        
95 3
        return $moduleConfig;
96
    }
97
    
98
    /**
99
     * @param array $moduleConfig
100
     * @param string $bucketConfigName
101
     * @return BucketOptions
102
     * @throws \Assert\AssertionFailedException
103
     */
104 1 View Code Duplication
    public function getBucketOptions(array $moduleConfig, $bucketConfigName)
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...
105
    {
106 1
        Assertion::keyExists($moduleConfig, 'buckets');
107
        
108 1
        $bucketsConfig = $moduleConfig['buckets'];
109 1
        Assertion::isArray($bucketsConfig);
110
    
111 1
        Assertion::keyExists($bucketsConfig, $bucketConfigName);
112 1
        $bucketConfig = $bucketsConfig[$bucketConfigName];
113 1
        Assertion::isArray($bucketConfig);
114
        
115 1
        return new BucketOptions($bucketConfig);
116
    }
117
    
118
    /**
119
     * @param array $moduleConfig
120
     * @param string $clusterName
121
     * @return ClusterOptions
122
     * @throws \Assert\AssertionFailedException
123
     */
124 1 View Code Duplication
    public function getClusterOptions(array $moduleConfig, $clusterName)
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...
125
    {
126 1
        Assertion::keyExists($moduleConfig, 'clusters');
127
        
128 1
        $clustersConfig = $moduleConfig['clusters'];
129 1
        Assertion::isArray($clustersConfig);
130
    
131 1
        Assertion::keyExists($clustersConfig, $clusterName);
132 1
        $clusterConfig = $clustersConfig[$clusterName];
133 1
        Assertion::isArray($clusterConfig);
134
        
135 1
        return new ClusterOptions($clusterConfig);
136
    }
137
}
138