Issues (23)

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.

application/src/Kineo/Component/ApiResponse.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
namespace Kineo\Component;
3
4
use Silex\Application;
5
use Symfony\Component\HttpFoundation\Response;
6
7
class ApiResponse extends Response
8
{
9
	public static function error($code, $customMessage = null)
10
	{		
11
		return self::responseFactory($code, 'error', $customMessage);
12
	}
13
14
	public static function success($code, $customMessage = null)
15
	{
16
		return self::responseFactory($code, 'success', $customMessage);
17
	}
18
19
	private static function responseFactory($code, $status, $customMessage = null)
20
	{
21
		$response = self::create();
22
23
		$content = self::generateResponseBody($code, $status, $customMessage);
24
		$response->setContent($content);
25
26
		self::setResponseStatusCode($response, $code);
27
28
		return $response;
29
	}
30
31
	private static function generateResponseBody($code, $status, $customMessage = null)
32
	{
33
		$message = (isset($customMessage)) ? $customMessage : self::fetchErrorMessage($code);
34
35
		return self::encodeResponse(array('code' => $code, 'status' => $status, 'message' => $message));
36
	}
37
38
	private static function fetchErrorMessage($code)
39
	{
40
		return constant("\Kineo\Component\ApiResponseMessageDefinition::$code");
41
	}
42
43
	private static function encodeResponse(array $response)
44
	{
45
		return json_encode($response);
46
	}
47
48
	private static function setResponseStatusCode($response, $code)
49
	{
50
		switch($code) {
51
			case 'SESSION_CHECK':
52
			case 'DEFAULT_RESPONSE_SUCCESS':
53
				// 200 - Success
54
				$response->setStatusCode(Response::HTTP_OK);
55
				break;
56
57
			case 'USER_EXISTS':
58
			case 'USER_SAVE_FAIL':
59
			case 'NO_CANDIDATES_FOUND':
60
			case 'NO_CONSTITUENCIES_FOUND';
0 ignored issues
show
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
61
				// 400 - Bad Request
62
				$response->setStatusCode(Response::HTTP_BAD_REQUEST);
63
				break;
64
65
			case 'SESSION_EXPIRED':
66
			case 'PASSWORD_INVALID':
67
			case 'USER_UNVERIFIED':
68
			case 'INVALID_VERIFICATION_CODE':
69
				// 403 - Unauthorized
70
				$response->setStatusCode(Response::HTTP_FORBIDDEN);
71
				break;
72
73
			default:
74
				// 200 - Success
75
				$response->setStatusCode(Response::HTTP_OK);
76
				break;
77
		}
78
	}
79
}
80
81
class ApiResponseMessageDefinition
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
82
{
83
	const DEFAULT_RESPONSE_SUCCESS = 'The API action was succesfully completed.';
84
85
	const SESSION_EXPIRED = 'Authenticated session required.';
86
87
	const PASSWORD_INVALID = 'The password provided is incorrect.';
88
	const USER_UNVERIFIED = 'This user account has not yet been verified.';
89
	const INVALID_VERIFICATION_CODE = 'The supplied verification code is invalid.';
90
	
91
	const NO_CONSTITUENCIES_FOUND = 'Sorry, we couldn\'t find any constituencies.';
92
	const NO_CANDIDATES_FOUND = 'Sorry, we couldn\'t find any candidates for this constituency.';
93
	const USER_SAVE_FAIL = 'Sorry, there was a problem saving your details to the system.';
94
	const USER_EXISTS = 'This email address has already been used to cast a vote.';
95
}