Issues (10)

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.

Bootstrap/ContextTrait/SqsContextTrait.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 AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait;
4
5
use Abacaphiliac\AwsSdk\ClaimCheck\Exception\ExceptionInterface;
6
use Abacaphiliac\AwsSdk\ClaimCheck\ClaimCheckFactory;
7
use Abacaphiliac\AwsSdk\ClaimCheck\Sqs\SqsExtendedClientConfiguration;
8
use Abacaphiliac\AwsSdk\ClaimCheck\Sqs\SqsExtendedClient;
9
use Aws\Result;
10
use Aws\S3\S3Client;
11
use Aws\Sqs\SqsClient;
12
13
trait SqsContextTrait
14
{
15
    /** @var  SqsClient */
16
    private $sqsClient;
17
    
18
    /** @var  SqsExtendedClientConfiguration */
19
    private $sqsExtendedClientConfiguration;
20
    
21
    /** @var  string */
22
    private $queueUrl;
23
    
24
    /** @var  string[] */
25
    private $queueUrls = [];
26
27
    /**
28
     * @return S3Client
29
     */
30
    abstract public function getS3Client();
31
32
    /**
33
     * @return string
34
     */
35
    abstract public function getBucketName();
36
37
    /**
38
     * @return string
39
     */
40
    abstract public function getMessage();
41
42
    /**
43
     * @return mixed[]
44
     */
45
    abstract public function getAwsServiceConfig();
46
47
    /**
48
     * @return ClaimCheckFactory
49
     */
50
    abstract public function createClaimCheckFactory();
51
52
    /**
53
     * @return SqsClient
54
     * @throws ExceptionInterface
55
     */
56
    public function getSqsClient()
57
    {
58
        if (!$this->sqsClient) {
59
            $config = $this->getAwsServiceConfig();
60
            $client = new SqsClient($config);
61
            $this->sqsClient = new SqsExtendedClient($client, $this->getSqsExtendedClientConfiguration());
62
        }
63
64
        return $this->sqsClient;
65
    }
66
67
    /**
68
     * @return SqsExtendedClientConfiguration
69
     * @throws ExceptionInterface
70
     */
71
    public function getSqsExtendedClientConfiguration()
72
    {
73
        if (!$this->sqsExtendedClientConfiguration) {
74
            $s3Client = $this->getS3Client();
75
76
            $s3BucketName = $this->getBucketName();
77
78
            $this->sqsExtendedClientConfiguration = new SqsExtendedClientConfiguration($s3Client, $s3BucketName);
79
        }
80
        
81
        return $this->sqsExtendedClientConfiguration;
82
    }
83
84
    /**
85
     * @Given /^a queue named "([^"]*)"$/
86
     * @param string $name
87
     * @return string
88
     * @throws ExceptionInterface
89
     */
90
    public function getQueueFixture($name)
91
    {
92
        $this->queueUrl = $this->getQueueUrl($name);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getQueueUrl($name) can also be of type boolean. However, the property $queueUrl is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
93
        
94
        return $this->queueUrl;
95
    }
96
97
    /**
98
     * @param string $name
99
     * @return string|bool
100
     * @throws ExceptionInterface
101
     */
102
    public function getQueueUrl($name)
103
    {
104
        if (array_key_exists($name, $this->queueUrls)) {
105
            return $this->queueUrls[$name];
106
        }
107
        
108
        $result = $this->getSqsClient()->getQueueUrl([
109
            'QueueName' => $name,
110
        ]);
111
112
        $this->queueUrls[$name] = $result->get('QueueUrl');
113
        
114
        return $this->queueUrls[$name];
115
    }
116
117
    /**
118
     * @param string $name
119
     * @return string
120
     * @throws ExceptionInterface
121
     */
122
    public function getQueueArn($name)
123
    {
124
        $queueUrl = $this->getQueueUrl($name);
125
        
126
        return $this->getSqsClient()->getQueueArn($queueUrl);
0 ignored issues
show
It seems like $queueUrl defined by $this->getQueueUrl($name) on line 124 can also be of type boolean; however, Aws\Sqs\SqsClient::getQueueArn() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
127
    }
128
129
    /**
130
     * @When /^I send the message to a queue named "([^"]*)"$/
131
     * @param string $name
132
     * @return Result
133
     * @throws ExceptionInterface
134
     */
135
    public function iSendTheMessageToQueue($name)
136
    {
137
        $sqsClient = $this->getSqsClient();
138
        $queueUrl = $this->getQueueUrl($name);
139
        $message = $this->getMessage();
140
141
        return $sqsClient->sendMessage([
142
            'QueueUrl' => $queueUrl,
143
            'MessageBody' => $message,
144
        ]);
145
    }
146
147
    /**
148
     * @Then /^I can fetch the message from a queue named "([^"]*)"$/
149
     * @param string $name
150
     * @return Result
151
     * @throws ExceptionInterface
152
     * @throws \RuntimeException
153
     * @throws \PHPUnit_Framework_AssertionFailedError
154
     */
155
    public function iCanFetchTheMessageFromQueue($name)
156
    {
157
        $expectedMessage = $this->getMessage();
158
        \PHPUnit_Framework_Assert::assertNotEmpty($expectedMessage);
159
160
        $sqsClient = $this->getSqsClient();
161
        
162
        $queueUrl = $this->getQueueUrl($name);
163
        
164
        $result = $sqsClient->receiveMessage([
165
            'QueueUrl' => $queueUrl,
166
            'MaxNumberOfMessages' => 1,
167
        ]);
168
        
169
        $actualMessage = $result->search('Messages[].Body|[0]');
170
        \PHPUnit_Framework_Assert::assertNotEmpty($actualMessage);
171
        
172
        \PHPUnit_Framework_Assert::assertEquals(
173
            $expectedMessage,
174
            $actualMessage,
175
            'Purge the queues before running the feature suite.'
176
        );
177
178
        $sqsClient->deleteMessage([
179
            'QueueUrl' => $queueUrl,
180
            'ReceiptHandle' => $result->search('Messages[].ReceiptHandle|[0]'),
181
        ]);
182
        
183
        return $result;
184
    }
185
}
186