Issues (34)

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/activities/BasicActivity.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
/*
4
 *   This class serves as a skeleton for Cloud Transcode classes implementing actual activities
5
 *
6
 *   Copyright (C) 2016  BFan Sports - Sport Archive Inc.
7
 *
8
 *   This program is free software; you can redistribute it and/or modify
9
 *   it under the terms of the GNU General Public License as published by
10
 *   the Free Software Foundation; either version 2 of the License, or
11
 *   (at your option) any later version.
12
 *
13
 *   This program is distributed in the hope that it will be useful,
14
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *   GNU General Public License for more details.
17
 *
18
 *   You should have received a copy of the GNU General Public License along
19
 *   with this program; if not, write to the Free Software Foundation, Inc.,
20
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
23
require_once __DIR__."/../../vendor/autoload.php";
24
require_once __DIR__.'/../utils/S3Utils.php';
25
26
use SA\CpeSdk;
27
28
class BasicActivity extends CpeSdk\CpeActivity
29
{
30
    public $tmpInputPath;    // Path to directory containing TMP file
31
    public $inputFilePath;   // Path to input file locally
32
    public $s3Utils;         // Used to manipulate S3. Download/Upload
33
  
34
    // Constants
35
    const TMP_FOLDER_FAIL      = "TMP_FOLDER_FAIL";
36
    const UNKOWN_INPUT_TYPE    = "UNKOWN_INPUT_TYPE";
37
38
    // JSON checks
39
    const FORMAT_INVALID       = "FORMAT_INVALID";
40
41
    // Types
42
    const VIDEO                = "VIDEO";
43
    const THUMB                = "THUMB";
44
    const AUDIO                = "AUDIO";
45
    const DOC                  = "DOC";
46
    const IMAGE                = "IMAGE";
47
48
    // XXX Use EFS for storage
49
    // Nico: Expensive though.
50
    // This is where we store temporary files for transcoding for now
51
    // Make sure your partition is big enough!
52
    const TMP_FOLDER = "/tmp/CloudTranscode/";
53
    
54
    public function __construct($client = null, $params, $debug, $cpeLogger)
55
    {
56
        parent::__construct($client, $params, $debug, $cpeLogger);
57
        
58
        // S3 utils
59
        $this->s3Utils = new S3Utils($this->cpeLogger);
60
    }
61
62
    // Perform the activity
63
    public function process($task)
64
    {
65
        // Use workflowID to generate a unique TMP folder localy.
66
        $this->tmpInputPath = self::TMP_FOLDER 
67
                            . $this->logKey."/" 
68
                            . "input";
69
        
70
        $inputFileInfo = null;
71
        if (isset($this->input->{'input_asset'}->{'file'})) {
72
            $this->input->{'input_asset'}->{'file'} = ltrim($this->input->{'input_asset'}->{'file'}, "/");
73
            $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'});
74
        }
75
        
76
        // Create the tmp folder if doesn't exist
77
        if (!file_exists($this->tmpInputPath)) 
78
        {
79 View Code Duplication
            if ($this->debug)
0 ignored issues
show
This code seems to be duplicated across 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...
80
                $this->cpeLogger->logOut("DEBUG", basename(__FILE__), 
81
                                         "Creating TMP input folder '".$this->tmpInputPath."'",
82
                                         $this->logKey);
83
            
84
            if (!mkdir($this->tmpInputPath, 0750, true))
85
                throw new CpeSdk\CpeException(
86
                    "Unable to create temporary folder '$this->tmpInputPath' !",
87
                    self::TMP_FOLDER_FAIL
88
                );
89
        }
90
        
91
        $this->inputFilePath = null;
92
        if (isset($this->input->{'input_asset'}->{'http'}))
93
        {
94
            // Pad HTTP input so it is cached in case of full encodes
95
            $this->inputFilePath = 'cache:' . $this->input->{'input_asset'}->{'http'};
96
        }
97
        else if (isset($this->input->{'input_asset'}->{'bucket'}) &&
98
                 isset($this->input->{'input_asset'}->{'file'}))
99
        {
100
            // Download input file and store it in TMP folder
101
            $saveFileTo = $this->tmpInputPath."/".$inputFileInfo['basename'];
102
            $this->inputFilePath = $this->getFileToProcess(
103
                $task, 
104
                $this->input->{'input_asset'}->{'bucket'},
105
                $this->input->{'input_asset'}->{'file'},
106
                $saveFileTo
107
            );
108
        }
109
    }
110
    
111
    /**
112
     * Custom code for Cloud Transcode
113
     */
114
    
115
    // Create TMP folder and download file to process
116
    public function getFileToProcess($task, $inputBuket, $inputFile, $saveFileTo)
0 ignored issues
show
The parameter $task is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
    {        
118
        // Get file from S3 or local copy if any
119
        $this->cpeLogger->logOut("INFO", 
120
                                 basename(__FILE__), 
121
                                 "Downloading '$inputBuket/$inputFile' to '$saveFileTo' ...",
122
                                 $this->logKey);
123
        
124
        // Use the S3 utils to initiate the download
125
        $s3Output = $this->s3Utils->get_file_from_s3(
126
            $inputBuket, 
127
            $inputFile, 
128
            $saveFileTo,
129
            array($this, "activityHeartbeat"), 
130
            null,
131
            $this->logKey
132
        );
133
        
134
        $this->cpeLogger->logOut("INFO", basename(__FILE__), 
135
                                 $s3Output['msg'],
136
                                 $this->logKey);
137
        
138
        $this->cpeLogger->logOut("INFO", basename(__FILE__), 
139
                                 "Input file successfully downloaded into local TMP folder '$saveFileTo' !",
140
                                 $this->logKey);
141
        
142
        return $saveFileTo;
143
    }
144
}
145
146