Issues (175)

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.

Facebook/FileUpload/FacebookResumableUploader.php (1 issue)

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
 * Copyright 2016 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\FileUpload;
25
26
use Facebook\Authentication\AccessToken;
27
use Facebook\Exceptions\FacebookResponseException;
28
use Facebook\Exceptions\FacebookResumableUploadException;
29
use Facebook\Exceptions\FacebookSDKException;
30
use Facebook\FacebookApp;
31
use Facebook\FacebookClient;
32
use Facebook\FacebookRequest;
33
34
/**
35
 * Class FacebookResumableUploader
36
 *
37
 * @package Facebook
38
 */
39
class FacebookResumableUploader
40
{
41
    /**
42
     * @var FacebookApp
43
     */
44
    protected $app;
45
46
    /**
47
     * @var string
48
     */
49
    protected $accessToken;
50
51
    /**
52
     * @var FacebookClient The Facebook client service.
53
     */
54
    protected $client;
55
56
    /**
57
     * @var string Graph version to use for this request.
58
     */
59
    protected $graphVersion;
60
61
    /**
62
     * @param FacebookApp             $app
63
     * @param FacebookClient          $client
64
     * @param AccessToken|string|null $accessToken
65
     * @param string                  $graphVersion
66
     */
67
    public function __construct(FacebookApp $app, FacebookClient $client, $accessToken, $graphVersion)
68
    {
69
        $this->app = $app;
70
        $this->client = $client;
71
        $this->accessToken = $accessToken;
0 ignored issues
show
Documentation Bug introduced by
It seems like $accessToken can also be of type object<Facebook\Authentication\AccessToken>. However, the property $accessToken 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...
72
        $this->graphVersion = $graphVersion;
73
    }
74
75
    /**
76
     * Upload by chunks - start phase
77
     *
78
     * @param string $endpoint
79
     * @param FacebookFile $file
80
     *
81
     * @return FacebookTransferChunk
82
     *
83
     * @throws FacebookSDKException
84
     */
85
    public function start($endpoint, FacebookFile $file)
86
    {
87
        $params = [
88
            'upload_phase' => 'start',
89
            'file_size' => $file->getSize(),
90
        ];
91
        $response = $this->sendUploadRequest($endpoint, $params);
92
93
        return new FacebookTransferChunk($file, $response['upload_session_id'], $response['video_id'], $response['start_offset'], $response['end_offset']);
94
    }
95
96
    /**
97
     * Upload by chunks - transfer phase
98
     *
99
     * @param string $endpoint
100
     * @param FacebookTransferChunk $chunk
101
     * @param boolean $allowToThrow
102
     *
103
     * @return FacebookTransferChunk
104
     *
105
     * @throws FacebookResponseException
106
     */
107
    public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow = false)
108
    {
109
        $params = [
110
            'upload_phase' => 'transfer',
111
            'upload_session_id' => $chunk->getUploadSessionId(),
112
            'start_offset' => $chunk->getStartOffset(),
113
            'video_file_chunk' => $chunk->getPartialFile(),
114
        ];
115
116
        try {
117
            $response = $this->sendUploadRequest($endpoint, $params);
118
        } catch (FacebookResponseException $e) {
119
            $preException = $e->getPrevious();
120
            if ($allowToThrow || !$preException instanceof FacebookResumableUploadException) {
121
                throw $e;
122
            }
123
124
            // Return the same chunk entity so it can be retried.
125
            return $chunk;
126
        }
127
128
        return new FacebookTransferChunk($chunk->getFile(), $chunk->getUploadSessionId(), $chunk->getVideoId(), $response['start_offset'], $response['end_offset']);
129
    }
130
131
    /**
132
     * Upload by chunks - finish phase
133
     *
134
     * @param string $endpoint
135
     * @param string $uploadSessionId
136
     * @param array $metadata The metadata associated with the file.
137
     *
138
     * @return boolean
139
     *
140
     * @throws FacebookSDKException
141
     */
142
    public function finish($endpoint, $uploadSessionId, $metadata = [])
143
    {
144
        $params = array_merge($metadata, [
145
            'upload_phase' => 'finish',
146
            'upload_session_id' => $uploadSessionId,
147
        ]);
148
        $response = $this->sendUploadRequest($endpoint, $params);
149
150
        return $response['success'];
151
    }
152
153
    /**
154
     * Helper to make a FacebookRequest and send it.
155
     *
156
     * @param string $endpoint The endpoint to POST to.
157
     * @param array $params The params to send with the request.
158
     *
159
     * @return array
160
     */
161
    private function sendUploadRequest($endpoint, $params = [])
162
    {
163
        $request = new FacebookRequest($this->app, $this->accessToken, 'POST', $endpoint, $params, null, $this->graphVersion);
164
165
        return $this->client->sendRequest($request)->getDecodedBody();
166
    }
167
}
168