Issues (81)

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/GatewayFieldsFactory.php (4 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
 * Helper for generating gateway fields, based on best practices.
5
 *
6
 * @package payment
7
 */
8
class GatewayFieldsFactory{
9
10
	protected $fieldgroups = array(
11
		'Card',
12
		'Billing',
13
		'Shipping',
14
		'Company',
15
		'Email'
16
	);
17
18
	protected $gateway;
19
	protected $groupdatefields = true;
20
21
	public function __construct($gateway = null, $fieldgroups = null) {
22
		$this->gateway = $gateway;
23
		$this->setFieldGroups($fieldgroups);
24
	}
25
26
	public function setFieldGroups($groups) {
27
		if (is_array($groups)) {
28
			$this->fieldgroups = $groups;
29
		}
30
31
		return $this;
32
	}
33
34
	public function setGateway($gateway) {
35
		$this->gateway = $gateway;
36
37
		return $this;
38
	}
39
40
	public function getFields() {
41
		$fields = new FieldList();
42
		foreach ($this->fieldgroups as $group) {
43
			if (method_exists($this, "get".$group."Fields")) {
44
				$fields->merge($this->{"get".$group."Fields"}());
45
			}
46
		}
47
48
		return $fields;
49
	}
50
51
	public function getCardFields() {
52
		$months = array();
53
		//generate list of months
54
		for ($x = 1; $x <= 12; $x++) {
55
			$months[$x] = date('m - F', mktime(0, 0, 0, $x, 1));
56
		}
57
		$year = date("Y");
58
		$range = 5;
59
		$startrange = range(date("Y", strtotime("-$range years")), $year);
60
		$expiryrange = range($year, date("Y", strtotime("+$range years")));
61
62
		$fields = array(
63
			"type" => DropdownField::create('type', _t("PaymentForm.TYPE", "Type"), $this->getCardTypes()),
64
			"name" => TextField::create('name', _t("PaymentForm.NAME", "Name on Card")),
65
			"number" => TextField::create('number', _t("PaymentForm.NUMBER", "Card Number"))
66
							->setDescription(_t("PaymentForm.NUMBERDESCRIPTION", "no dashes or spaces")),
67
			"startMonth" => DropdownField::create('startMonth', _t("PaymentForm.STARTMONTH", "Month"), $months),
68
			"startYear" => DropdownField::create('startYear', _t("PaymentForm.STARTYEAR", "Year"),
69
								array_combine($startrange, $startrange), $year
70
							),
71
			"expiryMonth" => DropdownField::create('expiryMonth', _t("PaymentForm.EXPIRYMONTH", "Month"), $months),
72
			"expiryYear" => DropdownField::create('expiryYear', _t("PaymentForm.EXPIRYYEAR", "Year"),
73
								array_combine($expiryrange, $expiryrange), $year
74
							),
75
			"cvv" => TextField::create('cvv', _t("PaymentForm.CVV", "Security Code"))
76
							->setMaxLength(5),
77
			"issueNumber" => TextField::create('issueNumber', _t("PaymentForm.ISSUENUMBER", "Issue Number"))
78
		);
79
		
80
		$this->cullForGateway($fields);
81
		//optionally group date fields
82
		if ($this->groupdatefields) {
83 View Code Duplication
			if (isset($fields['startMonth']) && isset($fields['startYear'])) {
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...
84
				$fields['startMonth'] = new FieldGroup(_t("PaymentForm.START", "Start"),
85
					$fields['startMonth'], $fields['startYear']
86
				);
87
				$fields['startMonth']->addExtraClass('card_startyear');
88
				unset($fields['startYear']);
89
			}
90 View Code Duplication
			if (isset($fields['expiryMonth']) && isset($fields['expiryYear'])) {
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...
91
				$fields['expiryMonth'] = new FieldGroup(_t("PaymentForm.EXPIRY", "Expiry"),
92
					$fields['expiryMonth'], $fields['expiryYear']
93
				);
94
				$fields['expiryMonth']->addExtraClass('card_expiry');
95
				unset($fields['expiryYear']);
96
			}
97
		}
98
99
		return FieldList::create($fields);
100
	}
101
102
	public function getCardTypes() {
103
		$card = new Omnipay\Common\CreditCard();
104
		$brands = $card->getSupportedBrands();
105
		foreach ($brands as $brand => $x) {
106
			$brands[$brand] = _t("PaymentForm.".strtoupper($brand), $brand);
107
		}
108
109
		return $brands;
110
	}
111
112 View Code Duplication
	public function getBillingFields() {
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...
113
		$fields = array(
114
			"billingAddress1" => TextField::create('billingAddress1', _t("PaymentForm.BILLINGADDRESS1", "")),
115
			"billingAddress2" => TextField::create('billingAddress2', _t("PaymentForm.BILLINGADDRESS2", "")),
116
			"city" => TextField::create('billingCity', _t("PaymentForm.BILLINGCITY", "City")),
117
			"postcode" => TextField::create('billingPostcode', _t("PaymentForm.BILLINGPOSTCODE", "Postcode")),
118
			"state" => TextField::create('billingState', _t("PaymentForm.BILLINGSTATE", "State")),
119
			"country" => TextField::create('billingCountry', _t("PaymentForm.BILLINGCOUNTRY", "Country")),
120
			"phone" => PhoneNumberField::create('billingPhone', _t("PaymentForm.BILLINGPHONE", "Phone"))
121
		);
122
		$this->cullForGateway($fields);
123
124
		return FieldList::create($fields);
125
	}
126
127 View Code Duplication
	public function getShippingFields() {
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...
128
		$fields = array(
129
			"shippingAddress1" => TextField::create(
130
				'shippingAddress1', _t("PaymentForm.SHIPPINGADDRESS1", "Shipping Address")
131
			),
132
			"shippingAddress2" => TextField::create(
133
				'shippingAddress2', _t("PaymentForm.SHIPPINGADDRESS2", "Shipping Address 2")
134
			),
135
			"city" => TextField::create('shippingCity', _t("PaymentForm.SHIPPINGCITY", "Shipping City")),
136
			"postcode" => TextField::create('shippingPostcode', _t("PaymentForm.SHIPPINGPOSTCODE", "Shipping Postcode")),
137
			"state" => TextField::create('shippingState', _t("PaymentForm.SHIPPINGSTATE", "Shipping State")),
138
			"country" => TextField::create('shippingCountry', _t("PaymentForm.SHIPPINGCOUNTRY", "Shipping Country")),
139
			"phone" => PhoneNumberField::create('shippingPhone', _t("PaymentForm.SHIPPINGPHONE", "Shipping Phone"))
140
		);
141
		$this->cullForGateway($fields);
142
143
		return FieldList::create($fields);
144
	}
145
146
	public function getEmailFields() {
147
		$fields = array(
148
			"email" => EmailField::create('email', _t("PaymentForm.EMAIL", "Email"))
149
		);
150
		$this->cullForGateway($fields);
151
152
		return FieldList::create($fields);
153
	}
154
155
	public function getCompanyFields() {
156
		$fields = array(
157
			"company" => TextField::create('company', _t("PaymentForm.COMPANY", "Company"))
158
		);
159
		$this->cullForGateway($fields);
160
161
		return FieldList::create($fields);
162
	}
163
164
	protected function cullForGateway(&$fields, $defaults = array()) {
165
		$selected = array_merge($defaults, GatewayInfo::required_fields($this->gateway));
166
		foreach ($fields as $name => $field) {
167
			if (!in_array($name, $selected)) {
168
				unset($fields[$name]);
169
			}
170
		}
171
	}
172
173
}
174