|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use \Common\ContainerMagic; |
|
4
|
|
|
use \Common\IPropertyContainer; |
|
5
|
|
|
|
|
6
|
|
|
class V2PropertyContainer extends ContainerMagic implements IPropertyContainer { |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Property descriptions |
|
10
|
|
|
* |
|
11
|
|
|
* @var array[] |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $properties = array(); |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Array of accessors - getters/setters/etc |
|
17
|
|
|
* |
|
18
|
|
|
* Getter is a callable like |
|
19
|
|
|
* function () use ($that) {} |
|
20
|
|
|
* or Pimple-like (P_CONTAINER_GETTER_PIMPLE) |
|
21
|
|
|
* function ($this) {} |
|
22
|
|
|
* |
|
23
|
|
|
* Setter is a callable like |
|
24
|
|
|
* function ($value) use ($that) {} |
|
25
|
|
|
* |
|
26
|
|
|
* Importer is a callable like |
|
27
|
|
|
* function (&$row) use ($this) {} |
|
28
|
|
|
* |
|
29
|
|
|
* Exporter is a callable like |
|
30
|
|
|
* function (&$row) use ($this) {} |
|
31
|
|
|
* |
|
32
|
|
|
* @var callable[][] |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $accessors; |
|
35
|
|
|
|
|
36
|
|
|
public function setProperties($properties) { |
|
37
|
|
|
$this->properties = $properties; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Is container contains no data |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
|
|
public function isEmpty() { |
|
46
|
|
|
return empty($this->values); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function assignAccessor($varName, $type, $callable) { |
|
50
|
|
|
if (empty($callable)) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (is_callable($callable)) { |
|
55
|
|
|
$this->accessors[$type][$varName] = $callable; |
|
56
|
|
|
} else { |
|
57
|
|
|
throw new Exception('Error assigning callable in ' . get_called_class() . '! Callable typed [' . $type . '] is not a callable or not accessible in the scope'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function __set($name, $value) { |
|
62
|
|
|
|
|
63
|
|
|
if(is_callable($value)) { |
|
64
|
|
|
$this->accessors[P_CONTAINER_GETTER_PIMPLE][$name] = $value; |
|
65
|
|
|
} elseif (is_callable($this->accessors[P_CONTAINER_SETTER][$name])) { |
|
66
|
|
|
call_user_func($this->accessors[P_CONTAINER_SETTER][$name], $value); |
|
|
|
|
|
|
67
|
|
|
} else { |
|
68
|
|
|
$this->values[$name] = $value; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function __get($name) { |
|
73
|
|
|
if (is_callable($this->accessors[P_CONTAINER_GETTER_PIMPLE][$name])) { |
|
74
|
|
|
return call_user_func($this->accessors[P_CONTAINER_GETTER_PIMPLE][$name], $this); |
|
|
|
|
|
|
75
|
|
|
} elseif (is_callable($this->accessors[P_CONTAINER_GETTER][$name])) { |
|
76
|
|
|
return call_user_func($this->accessors[P_CONTAINER_GETTER][$name]); |
|
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
|
|
return $this->values[$name]; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function clear() { |
|
83
|
|
|
foreach ($this->properties as $propertyName => $propertyData) { |
|
84
|
|
|
unset($this->values[$propertyName]); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
$this->accessors[P_CONTAINER_SETTER][$name]can contain request data and is used in code execution context(s) leading to a potential security vulnerability.1 path for user data to reach this point
$_POSTin includes/general.php on line 258
$valueis assignedin includes/general.php on line 266
in includes/classes/Buddy/BuddyContainer.php on line 81
in includes/classes/Buddy/BuddyModel.php on line 237
$cBuddy->buddy_idis passed to V2PropertyContainer::__set()in includes/classes/Buddy/BuddyModel.php on line -1
in includes/classes/V2PropertyContainer.php on line 64
in includes/classes/V2PropertyContainer.php on line 66
General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) { throw new \InvalidArgumentException('This input is not allowed.'); }For numeric data, we recommend to explicitly cast the data: