Issues (85)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Config/ClientConfig.php (2 issues)

1
<?php
2
3
/**
4
 * Copyright 2017 American Express Travel Related Services Company, Inc.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15
 * or implied. See the License for the specific language governing
16
 * permissions and limitations under the License.
17
 */
18
19
declare(strict_types=1);
20
21
namespace AmericanExpress\HyperledgerFabricClient\Config;
22
23
use AmericanExpress\HyperledgerFabricClient\Exception\BadMethodCallException;
24
use AmericanExpress\HyperledgerFabricClient\Exception\InvalidArgumentException;
25
use AmericanExpress\HyperledgerFabricClient\HashAlgorithm;
26
use AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptions;
27
use AmericanExpress\HyperledgerFabricClient\Organization\OrganizationOptionsInterface;
28
use function igorw\get_in;
0 ignored issues
show
The function igorw\get_in was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
30
final class ClientConfig implements ClientConfigInterface
31
{
32
    /**
33
     * @var array
34
     */
35
    private $config;
36
37
    /**
38
     * ClientConfig constructor.
39
     * @param array $config
40
     * @throws InvalidArgumentException
41
     */
42 16
    public function __construct(array $config)
43
    {
44 16
        $this->config = array_merge(
45
            [
46 16
                'timeout' => 5000,
47
                'epoch' => 0,
48
                'crypto-hash-algo' => 'sha256',
49
                'nonce-size'  => 24,
50
                'organizations' => [],
51
            ],
52 16
            $config
53
        );
54
55 16
        $hash = $this->getIn(['crypto-hash-algo']);
56
57 16
        if (!$hash instanceof HashAlgorithm) {
58
            try {
59 16
                $this->config['crypto-hash-algo'] = new HashAlgorithm((string) $hash);
60 1
            } catch (InvalidArgumentException $e) {
61 1
                throw new InvalidArgumentException(
62 1
                    "Unable to create ClientConfig; Invalid 'crypto-hash-algo' supplied",
63 1
                    $e->getCode(),
64 1
                    $e
65
                );
66
            }
67
        }
68
69 16
        $this->config['organizations'] = array_map(function (array $data) {
70
            try {
71 3
                return new OrganizationOptions($data);
72 1
            } catch (BadMethodCallException $e) {
73 1
                throw new InvalidArgumentException('Cannot create ClientConfig; invalid organizations key', 0, $e);
74
            }
75 16
        }, $this->config['organizations']);
76 16
    }
77
78
    /**
79
     * @param string[] $keys
80
     * @param mixed $default
81
     * @return mixed|null
82
     */
83 16
    public function getIn(array $keys = [], $default = null)
84
    {
85 16
        return get_in($this->config, $keys, $default);
86
    }
87
88
    /**
89
     * @return int
90
     */
91 2
    public function getNonceSize(): int
92
    {
93 2
        return (int) $this->getIn(['nonce-size']);
94
    }
95
96
    /**
97
     * @return HashAlgorithm
98
     */
99 2
    public function getHashAlgorithm(): HashAlgorithm
100
    {
101 2
        return $this->getIn(['crypto-hash-algo']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getIn(array('crypto-hash-algo')) returns the type array which is incompatible with the type-hinted return AmericanExpress\Hyperled...ricClient\HashAlgorithm.
Loading history...
102
    }
103
104
    /**
105
     * @return int
106
     */
107 2
    public function getTimeout(): int
108
    {
109 2
        return (int) $this->getIn(['timeout']);
110
    }
111
112
    /**
113
     * @return int
114
     */
115 2
    public function getEpoch(): int
116
    {
117 2
        return (int) $this->getIn(['epoch']);
118
    }
119
120
    /**
121
     * @param string $name
122
     * @return OrganizationOptionsInterface|null
123
     * @throws \AmericanExpress\HyperledgerFabricClient\Exception\BadMethodCallException
124
     */
125 2
    public function getOrganizationByName(string $name): ?OrganizationOptionsInterface
126
    {
127 2
        $organizations = array_filter(
128 2
            $this->getIn(['organizations'], []),
129 2
            function (OrganizationOptionsInterface $organization) use ($name) {
130 1
                return $organization->getName() === $name;
131 2
            }
132
        );
133
134 2
        return \count($organizations) > 0 ? \reset($organizations) : null;
135
    }
136
137
    /**
138
     * @return OrganizationOptionsInterface
139
     */
140 1
    public function getDefaultOrganization(): OrganizationOptionsInterface
141
    {
142 1
        $organizations = $this->getIn(['organizations']);
143
144 1
        return \reset($organizations);
145
    }
146
}
147