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/api/nouns/APIEnvironment.php (9 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
class APIEnvironment extends APINoun {
0 ignored issues
show
The property $allowed_actions is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
4
5
	/**
6
	 * @var array
7
	 */
8
	private static $allowed_actions = array(
9
		'ping',
10
		'deploy'
11
	);
12
13
	/**
14
	 * @param \SS_HTTPRequest $request
15
	 * @return \SS_HTTPResponse
16
	 */
17
	public function index(\SS_HTTPRequest $request) {
18
		if(!$this->record->canView($this->getMember())) {
19
			return $this->message('You are not authorized to view this environment', 403);
20
		}
21
		switch($request->httpMethod()) {
22
			case 'GET':
23
				$href = Director::absoluteURL($this->record->Project()->APILink($this->record->Name));
24
				return $this->getAPIResponse(array(
25
					"name" => $this->record->Name,
26
					"project" => $this->record->Project()->Name,
27
					"href" => $href,
28
					"created" => $this->record->Created,
29
					"last-edited" => $this->record->LastEdited,
30
31
					// Stolen from https://github.com/kevinswiber/siren spec
32
					"actions" => array(
33
						array(
34
							"name" => "deploy",
35
							"method" =>  "POST",
36
							"href" => "$href/deploy",
37
							"type" => "application/json",
38
							"fields" => array(
39
								array("name" => "release", "type" => "text"),
40
							),
41
						)
42
					)
43
				));
44
			default:
45
				return $this->message('API not found', 404);
46
		}
47
	}
48
49
	/**
50
	 * @param \SS_HTTPRequest $request
51
	 * @return \SS_HTTPResponse
52
	 */
53 View Code Duplication
	public function ping(\SS_HTTPRequest $request) {
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...
54
		if(!$this->record->canView($this->getMember())) {
55
			return $this->message('You are not authorized to do that on this environment', 403);
56
		}
57
		switch($request->httpMethod()) {
58
			case 'GET':
59
				return $this->getPing($this->getRequest()->param('ID'));
60
			case 'POST':
61
				return $this->createPing();
62
			default:
63
				return $this->message('API not found', 404);
64
		}
65
	}
66
67
	/**
68
	 * @deprecated 2.0.0 - moved to DeployDispatcher
69
	 *
70
	 * @param \SS_HTTPRequest $request
71
	 * @return \SS_HTTPResponse
72
	 */
73 View Code Duplication
	public function deploy(\SS_HTTPRequest $request) {
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...
74
		if(!$this->record->canView($this->getMember())) {
75
			return $this->message('You are not authorized to do that on this environment', 403);
76
		}
77
		switch($request->httpMethod()) {
78
			case 'GET':
79
				return $this->getDeploy($this->getRequest()->param('ID'));
0 ignored issues
show
Deprecated Code introduced by
The method APIEnvironment::getDeploy() has been deprecated with message: 2.0.0 - moved to DeployDispatcher

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
80
			case 'POST':
81
				return $this->createDeploy();
0 ignored issues
show
Deprecated Code introduced by
The method APIEnvironment::createDeploy() has been deprecated with message: 2.0.0 - moved to DeployDispatcher

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
82
			default:
83
				return $this->message('API not found', 404);
84
		}
85
	}
86
87
	/**
88
	 * @return string
89
	 */
90
	public function Link() {
91
		return Controller::join_links(
92
			$this->parent->Link(),
93
			$this->record->Project()->Name,
94
			$this->record->Name
95
		);
96
	}
97
98
	/**
99
	 * @return SS_HTTPResponse
100
	 */
101
	protected function showRecord() {
102
		return $this->getAPIResponse($this->record->toMap());
103
	}
104
105
	/**
106
	 * @return SS_HTTPResponse
107
	 */
108
	protected function createPing() {
109
		if(!$this->record->canDeploy($this->getMember())) {
110
			return $this->message('You are not authorized to do that on this environment', 403);
111
		}
112
		$ping = DNPing::create();
113
		$ping->EnvironmentID = $this->record->ID;
114
		$ping->write();
115
		$ping->start();
116
117
		$location = Director::absoluteBaseURL() . $this->Link() . '/ping/' . $ping->ID;
118
		$output = array(
119
			'message' => 'Ping queued as job ' . $ping->ResqueToken,
120
			'href' => $location,
121
		);
122
123
		$response = $this->getAPIResponse($output);
124
		$response->setStatusCode(201);
125
		$response->addHeader('Location', $location);
126
		return $response;
127
	}
128
129
	/**
130
	 * @param int $ID
131
	 * @return SS_HTTPResponse
132
	 */
133 View Code Duplication
	protected function getPing($ID) {
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...
134
		$ping = DNPing::get()->byID($ID);
135
		if(!$ping) {
136
			return $this->message('Ping not found', 404);
137
		}
138
		$output = array(
139
			'status' => $ping->ResqueStatus(),
140
			'message' => $ping->LogContent()
141
		);
142
143
		return $this->getAPIResponse($output);
144
	}
145
146
	/**
147
	 * @deprecated 2.0.0 - moved to DeployDispatcher
148
	 *
149
	 * @return SS_HTTPResponse
150
	 */
151
	protected function createDeploy() {
152
		if(!$this->record->canDeploy($this->getMember())) {
153
			return $this->message('You are not authorized to do that on this environment', 403);
154
		}
155
156
		$reqBody = $this->getRequestBody();
157
158
		if($reqBody === null) {
159
			return $this->message('the request body did not contain a valid JSON object.', 400);
160
		}
161
162
		if(empty($reqBody['release'])) {
163
			return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400);
164
		}
165
166
		$strategy = new DeploymentStrategy($this->record, array(
0 ignored issues
show
$this->record of type object<DataObject> is not a sub-type of object<DNEnvironment>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
167
			'sha' => $reqBody['release']
168
		));
169
		$deploy = $strategy->createDeployment();
170
		$deploy->start();
0 ignored issues
show
Documentation Bug introduced by
The method start does not exist on object<DNDeployment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
171
		$location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID;
172
		$output = array(
173
			'message' => 'Deploy queued as job ' . $deploy->ResqueToken,
174
			'href' => $location,
175
		);
176
		$response = $this->getAPIResponse($output);
177
		$response->setStatusCode(201);
178
		$response->addHeader('Location', $location);
179
		return $response;
180
	}
181
182
	/**
183
	 * @deprecated 2.0.0 - moved to DeployDispatcher
184
	 *
185
	 * @param int $id
186
	 * @return SS_HTTPResponse
187
	 */
188 View Code Duplication
	protected function getDeploy($id) {
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...
189
		$deploy = DNDeployment::get()->byID($id);
190
		if(!$deploy) {
191
			return $this->message('Deploy not found', 404);
192
		}
193
		$output = array(
194
			'status' => $deploy->ResqueStatus(),
195
			'message' => $deploy->LogContent()
196
		);
197
198
		return $this->getAPIResponse($output);
199
	}
200
}
201