Issues (524)

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.

code/jobs/DataTransferJob.php (5 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
 * Starts a capistrano script for either retrieving data from an environment,
5
 * or pushing data into an environment. Initiated by {@link DNDataTransfer}.
6
 *
7
 * @package deploynaut
8
 * @subpackage jobs
9
 */
10
class DataTransferJob extends DeploynautJob {
11
12
	/**
13
	 * set by a resque worker
14
	 */
15
	public $args = array();
16
17
	public function setUp() {
18
		$this->updateStatus('Started');
19
		chdir(BASE_PATH);
20
	}
21
22
	public function perform() {
23
		echo "[-] DataTransferJob starting" . PHP_EOL;
24
		$log = new DeploynautLogFile($this->args['logfile']);
25
		$dataTransfer = DNDataTransfer::get()->byID($this->args['dataTransferID']);
26
		$environment = $dataTransfer->Environment();
27
		$backupDataTransfer = null;
28
29 View Code Duplication
		if(
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...
30
			!empty($this->args['backupBeforePush'])
31
			&& $this->args['backupBeforePush'] !== 'false'
32
			&& $dataTransfer->Direction == 'push'
33
		) {
34
			$backupDataTransfer = DNDataTransfer::create();
35
			$backupDataTransfer->EnvironmentID = $environment->ID;
36
			$backupDataTransfer->Direction = 'get';
37
			$backupDataTransfer->Mode = $dataTransfer->Mode;
38
			$backupDataTransfer->ResqueToken = $dataTransfer->ResqueToken;
39
			$backupDataTransfer->AuthorID = $dataTransfer->AuthorID;
40
			$backupDataTransfer->write();
41
42
			$dataTransfer->BackupDataTransferID = $backupDataTransfer->ID;
43
			$dataTransfer->write();
44
		}
45
46
		try {
47
			// Disallow concurrent jobs (don't rely on queuing implementation to restrict this)
48
			// Only consider data transfers started in the last 30 minutes (older jobs probably got stuck)
49
			$runningTransfers = DNDataTransfer::get()
50
				->filter(array(
51
					'EnvironmentID' => $environment->ID,
52
					'Status' => array('Queued', 'Started'),
53
					'Created:GreaterThan' => strtotime('-30 minutes')
54
				))
55
				->exclude('ID', $dataTransfer->ID);
56
			if($runningTransfers->count()) {
57
				$runningTransfer = $runningTransfers->first();
58
				$message = sprintf(
59
					'Error: another transfer is in progress (started at %s by %s)',
60
					$runningTransfer->dbObject('Created')->Nice(),
61
					$runningTransfer->Author()->Title
62
				);
63
				$log->write($message);
64
				throw new \RuntimeException($message);
65
			}
66
67
			$this->performBackup($backupDataTransfer, $log);
68
			$environment->Backend()->dataTransfer($dataTransfer, $log);
69
		} catch(Exception $e) {
70
			echo "[-] DataTransferJob failed" . PHP_EOL;
71
			throw $e;
72
		}
73
74
		$this->updateStatus('Finished');
75
		echo "[-] DataTransferJob finished" . PHP_EOL;
76
	}
77
78 View Code Duplication
	protected function performBackup($backupDataTransfer, \DeploynautLogFile $log) {
0 ignored issues
show
This method seems to be duplicated in 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...
79
		if (!$backupDataTransfer) {
80
			return false;
81
		}
82
83
		$log->write('Backing up existing data');
84
		try {
85
			$backupDataTransfer->Environment()->Backend()->dataTransfer($backupDataTransfer, $log);
86
			global $databaseConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
87
			DB::connect($databaseConfig);
88
			$backupDataTransfer->Status = 'Finished';
89
			$backupDataTransfer->write();
90
		} catch(Exception $e) {
91
			global $databaseConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
92
			DB::connect($databaseConfig);
93
			$backupDataTransfer->Status = 'Failed';
94
			$backupDataTransfer->write();
95
			throw $e;
96
		}
97
	}
98
99
	/**
100
	 * @param string $status
101
	 * @global array $databaseConfig
102
	 */
103
	protected function updateStatus($status) {
104
		global $databaseConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
105
		DB::connect($databaseConfig);
106
		$transfer = DNDataTransfer::get()->byID($this->args['dataTransferID']);
107
		$transfer->Status = $status;
108
		$transfer->write();
109
	}
110
111
	/**
112
	 * @return DNData
113
	 */
114
	protected function DNData() {
115
		return DNData::inst();
116
	}
117
}
118