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/Channel/Channel.php (1 issue)

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\Channel;
22
23
use AmericanExpress\HyperledgerFabricClient\Chaincode\Chaincode;
24
use AmericanExpress\HyperledgerFabricClient\Exception\InvalidArgumentException;
25
use AmericanExpress\HyperledgerFabricClient\Exception\RuntimeException;
26
use AmericanExpress\HyperledgerFabricClient\Exception\ExceptionInterface;
27
use AmericanExpress\HyperledgerFabricClient\Peer\PeerCollectionInterface;
28
use AmericanExpress\HyperledgerFabricClient\Peer\PeerInterface;
29
use AmericanExpress\HyperledgerFabricClient\Peer\PeerOptionsInterface;
30
use AmericanExpress\HyperledgerFabricClient\Proposal\ResponseCollection;
31
use AmericanExpress\HyperledgerFabricClient\Proposal\ProposalProcessorInterface;
32
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\ChannelHeaderFactory;
33
use AmericanExpress\HyperledgerFabricClient\ProtoFactory\ProposalFactory;
34
use AmericanExpress\HyperledgerFabricClient\Transaction\TransactionOptions;
35
use AmericanExpress\HyperledgerFabricClient\Identity\SerializedIdentityAwareHeaderGeneratorInterface;
36
use Assert\Assertion;
37
use Assert\AssertionFailedException;
38
use Hyperledger\Fabric\Protos\Peer\ChaincodeHeaderExtension;
39
use Hyperledger\Fabric\Protos\Peer\ChaincodeProposalPayload;
40
41
final class Channel implements ChannelInterface, PeerCollectionInterface
42
{
43
    /**
44
     * @var string
45
     */
46
    private $name;
47
48
    /**
49
     * @var ProposalProcessorInterface
50
     */
51
    private $client;
52
53
    /**
54
     * @var PeerInterface[] $peers
55
     */
56
    private $peers;
57
58
    /**
59
     * @var SerializedIdentityAwareHeaderGeneratorInterface
60
     */
61
    private $headerGenerator;
62
63
    /**
64
     * @param string $name
65
     * @param ProposalProcessorInterface $client
66
     * @param SerializedIdentityAwareHeaderGeneratorInterface $userAwareHeaderGenerator
67
     * @param PeerOptionsInterface[] $peers
68
     * @throws InvalidArgumentException
69
     */
70 13
    public function __construct(
71
        string $name,
72
        ProposalProcessorInterface $client,
73
        SerializedIdentityAwareHeaderGeneratorInterface $userAwareHeaderGenerator,
74
        array $peers = []
75
    ) {
76
        try {
77 13
            Assertion::allIsInstanceOf($peers, PeerInterface::class);
78 1
        } catch (AssertionFailedException $e) {
79 1
            throw new InvalidArgumentException(
80 1
                sprintf('Failed to create Channel `%s` due to invalid Peer collection.', $name),
81 1
                0,
82 1
                $e
83
            );
84
        }
85
86 13
        $this->name = $name;
87 13
        $this->client = $client;
88 13
        $this->headerGenerator = $userAwareHeaderGenerator;
89 13
        $this->peers = $peers;
0 ignored issues
show
Documentation Bug introduced by
$peers is of type array<mixed,AmericanExpr...OptionsInterface|mixed>, but the property $peers was declared to be of type AmericanExpress\Hyperled...nt\Peer\PeerInterface[]. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
90 13
    }
91
92
    /**
93
     *
94
     * Returns a named Chaincode for a channel
95
     *
96
     * @param string | array $nameOrVersionedName
97
     * @return Chaincode
98
     * @throws InvalidArgumentException
99
     */
100 2
    public function getChaincode($nameOrVersionedName): Chaincode
101
    {
102
        try {
103 2
            return new Chaincode($nameOrVersionedName, $this);
104 1
        } catch (ExceptionInterface $e) {
105 1
            throw new InvalidArgumentException('Can not create Chaincode as requested', 0, $e);
106
        }
107
    }
108
109
    /**
110
     * @param PeerInterface[] ...$peers
111
     * @return void
112
     */
113 3
    public function addPeers(PeerInterface ...$peers): void
114
    {
115 3
        $this->peers = array_merge($this->peers, $peers);
116 3
    }
117
118
    /**
119
     * @param PeerInterface[] $peers
120
     * @return void
121
     */
122 1
    public function setPeers(array $peers): void
123
    {
124 1
        $this->peers = [];
125 1
        $this->addPeers(...$peers);
126 1
    }
127
128
    /**
129
     * @return PeerInterface[]
130
     */
131 7
    public function getPeers(): array
132
    {
133 7
        return $this->peers;
134
    }
135
136
    /**
137
     * @param TransactionOptions|null $options
138
     * @return PeerInterface[]
139
     */
140 5
    private function resolvePeers(TransactionOptions $options): array
141
    {
142 5
        if ($options->hasPeers()) {
143 3
            return $options->getPeers();
144
        }
145
146 2
        return $this->getPeers();
147
    }
148
149
    /**
150
     * @param TransactionOptions|null $options
151
     * @return TransactionOptions
152
     */
153 5
    private function normalizeTransactionOptions(TransactionOptions $options = null): TransactionOptions
154
    {
155 5
        if ($options === null) {
156 2
            $options = new TransactionOptions();
157
        }
158
159 5
        return $options->withPeers(...$this->resolvePeers($options));
160
    }
161
162
    /**
163
     *
164
     * Envelopes a Chaincode function invocation from a Chaincode object
165
     *
166
     * @param ChaincodeProposalPayload $payload
167
     * @param ChaincodeHeaderExtension $extension
168
     * @param TransactionOptions|null $options
169
     * @return ResponseCollection
170
     * @throws RuntimeException
171
     */
172 5
    public function processChaincodeProposal(
173
        ChaincodeProposalPayload $payload,
174
        ChaincodeHeaderExtension $extension,
175
        TransactionOptions $options = null
176
    ): ResponseCollection {
177 5
        $channelHeader = ChannelHeaderFactory::create($this->name);
178 5
        $channelHeader->setExtension($extension->serializeToString());
179
180 5
        $options = $this->normalizeTransactionOptions($options);
181 5
        if (!$options->hasPeers()) {
182 1
            throw new RuntimeException('Could not determine peers for this transaction');
183
        }
184
185 4
        $header = $this->headerGenerator->generateHeader($channelHeader);
186 4
        $proposal = ProposalFactory::create($header, $payload->serializeToString());
187
188
        try {
189 4
            return $this->client->processProposal($proposal, $options);
190 1
        } catch (ExceptionInterface $e) {
191 1
            throw new RuntimeException(
192 1
                'Unable to process Chaincode proposal',
193 1
                0,
194 1
                $e
195
            );
196
        }
197
    }
198
}
199