Issues (2002)

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/EcommerceRestfulServer.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
 * extends the standard RestfulServer to provide better access to extended classes.
4
 *
5
 * see: http://api.silverstripe.org/2.4/sapphire/api/RestfulServer.html
6
 *
7
 * You can show JSON by hacking: RestfulServer::getDataFormatter
8
 * NOTE: JSON IS NOT AVAILABLE YET WITHIN RESTFUL SERVER
9
 *
10
 * @todo:
11
 * - fix http://site/api/ecommerce/v1/Order/123/BillingAddress.xml
12
 * - fix http://site/api/ecommerce/v1/Order/123/ShippingAddress.xml
13
 * - fix http://site/api/ecommerce/v1/Order/123/Member.xml
14
 *
15
 * <b>Test Post</b>
16
 * <code>
17
 * $baseURL = Director::absoluteBaseURL();
18
 * 	// 1) My Personal Data
19
 * 	$className = 'EcommerceClassWithEditableFields';
20
 * 	$fields = array(
21
 * 		'MyField' => 1
22
 * 	);
23
 * 	// 2) The Query
24
 * 	$url = "{$baseURL}/api/ecommerce/v1/{$className}.xml";
25
 * 	$body = $fields;
26
 * 	$c = curl_init($url);
27
 * 	curl_setopt($c, CURLOPT_POST, true);
28
 * 	curl_setopt($c, CURLOPT_POSTFIELDS, $body);
29
 * 	curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
30
 * 	$page = curl_exec($c);
31
 * 	curl_close($c);
32
33
 * 	// 3) The XML Result
34
35
 * 	return $page;
36
 * </code>
37
 *
38
 *
39
 * @authors: Romain [at] Sunny Side Up .co.nz
40
 * @package: ecommerce
41
 * @sub-package: api
42
 * @inspiration: Silverstripe Ltd, Jeremy
43
 **/
44
class EcommerceRestfulServer extends RestfulServer
45
{
46
    public function index()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
47
    {
48
        XMLDataFormatter::$api_base = 'api/ecommerce/v1/';
0 ignored issues
show
The property api_base cannot be accessed from this context as it is declared private in class XMLDataFormatter.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
49
        if (!isset($this->urlParams['ClassName'])) {
50
            return $this->notFound();
51
        }
52
        $className = $this->urlParams['ClassName'];
53
        $id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : null;
54
        $relation = (isset($this->urlParams['Relation'])) ? $this->urlParams['Relation'] : null;
55
56
        // Check input formats
57
        if (!class_exists($className)) {
58
            return $this->notFound();
59
        }
60
        if ($id && !is_numeric($id)) {
61
            return $this->notFound();
62
        }
63
        if ($relation && !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $relation)) {
64
            return $this->notFound();
65
        }
66
67
        // fix
68
        if ($id) {
69
            $obj = $className::get()->byID($id);
70
            if ($obj) {
71
                $className = $this->urlParams['ClassName'] = $obj->ClassName;
72
            } else {
73
                return $this->notFound();
74
            }
75
        }
76
77
        // if api access is disabled, don't proceed
78
        $apiAccess = singleton($className)->stat('api_access');
79
        if (!$apiAccess) {
80
            return $this->permissionFailure();
81
        }
82
83
        // authenticate through HTTP BasicAuth
84
        $this->member = $this->authenticate();
85
86
        // handle different HTTP verbs
87
        if ($this->request->isGET() || $this->request->isHEAD()) {
88
            return $this->getHandler($className, $id, $relation);
89
        }
90
        if ($this->request->isPOST()) {
91
            return $this->postHandler($className, $id, $relation);
92
        }
93
        if ($this->request->isPUT()) {
94
            return $this->putHandler($className, $id, $relation);
95
        }
96
        if ($this->request->isDELETE()) {
97
            return $this->deleteHandler($className, $id, $relation);
98
        }
99
100
        // if no HTTP verb matches, return error
101
        return $this->methodNotAllowed();
102
    }
103
}
104