Skip to content

Commit 582a2a9

Browse files
committed
Completely disallow serialization of SensitiveParameterValue
1 parent 348ca3c commit 582a2a9

File tree

6 files changed

+22
-57
lines changed

6 files changed

+22
-57
lines changed

Zend/tests/function_arguments/sensitive_parameter_value.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ echo "# var_export()", PHP_EOL;
1414
echo var_export($v, true), PHP_EOL;
1515
echo PHP_EOL;
1616

17-
echo "# (array) / serialize() / json_encode()", PHP_EOL;
17+
echo "# (array) / json_encode()", PHP_EOL;
1818
var_dump((array)$v);
19-
var_dump(serialize($v));
2019
var_dump(json_encode($v));
2120
echo PHP_EOL;
2221

@@ -35,10 +34,9 @@ object(SensitiveParameterValue)#%d (%d) refcount(%d){
3534
SensitiveParameterValue::__set_state(array(
3635
))
3736

38-
# (array) / serialize() / json_encode()
37+
# (array) / json_encode()
3938
array(0) {
4039
}
41-
string(35) "O:23:"SensitiveParameterValue":0:{}"
4240
string(2) "{}"
4341

4442
# ->getValue()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
A SensitiveParameterValue may not be serialized.
3+
--FILE--
4+
<?php
5+
6+
$v = new SensitiveParameterValue('secret');
7+
8+
var_dump(serialize($v));
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Exception: Serialization of 'SensitiveParameterValue' is not allowed in %ssensitive_parameter_value_serialize.php:5
13+
Stack trace:
14+
#0 %ssensitive_parameter_value_serialize.php(5): serialize(Object(SensitiveParameterValue))
15+
#1 {main}
16+
thrown in %ssensitive_parameter_value_serialize.php on line 5

Zend/tests/function_arguments/sensitive_parameter_value_unserialize.phpt

Lines changed: 0 additions & 17 deletions
This file was deleted.

Zend/zend_attributes.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,6 @@ ZEND_METHOD(SensitiveParameterValue, __debugInfo)
126126
RETURN_EMPTY_ARRAY();
127127
}
128128

129-
ZEND_METHOD(SensitiveParameterValue, __serialize)
130-
{
131-
ZEND_PARSE_PARAMETERS_NONE();
132-
133-
RETURN_EMPTY_ARRAY();
134-
}
135-
136-
ZEND_METHOD(SensitiveParameterValue, __unserialize)
137-
{
138-
HashTable *data;
139-
140-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
141-
RETURN_THROWS();
142-
}
143-
144-
zend_throw_exception(NULL, "Unserializing objects of class SensitiveParameterValue is not supported.", 0);
145-
RETURN_THROWS();
146-
}
147-
148129
static zend_object *attributes_sensitive_parameter_value_new(zend_class_entry *ce)
149130
{
150131
zend_object *object;

Zend/zend_attributes.stub.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct() {}
2929

3030
/**
3131
* @strict-properties
32+
* @not-serializable
3233
*/
3334
final class SensitiveParameterValue
3435
{
@@ -38,9 +39,5 @@ public function __construct(mixed $value) {}
3839

3940
public function getValue(): mixed {}
4041

41-
public function __serialize(): array {}
42-
43-
public function __unserialize(array $data): void {}
44-
4542
public function __debugInfo(): array {}
4643
}

Zend/zend_attributes_arginfo.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: c29c4a0e2df3e7975553c819743befd97bfd4070 */
2+
* Stub hash: 5d9a092c1f0da5f32d9a161cc5166ed794ffe8e9 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Attribute___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "Attribute::TARGET_ALL")
@@ -19,24 +19,16 @@ ZEND_END_ARG_INFO()
1919
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SensitiveParameterValue_getValue, 0, 0, IS_MIXED, 0)
2020
ZEND_END_ARG_INFO()
2121

22-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SensitiveParameterValue___serialize, 0, 0, IS_ARRAY, 0)
22+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SensitiveParameterValue___debugInfo, 0, 0, IS_ARRAY, 0)
2323
ZEND_END_ARG_INFO()
2424

25-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SensitiveParameterValue___unserialize, 0, 1, IS_VOID, 0)
26-
ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
27-
ZEND_END_ARG_INFO()
28-
29-
#define arginfo_class_SensitiveParameterValue___debugInfo arginfo_class_SensitiveParameterValue___serialize
30-
3125

3226
ZEND_METHOD(Attribute, __construct);
3327
ZEND_METHOD(ReturnTypeWillChange, __construct);
3428
ZEND_METHOD(AllowDynamicProperties, __construct);
3529
ZEND_METHOD(SensitiveParameter, __construct);
3630
ZEND_METHOD(SensitiveParameterValue, __construct);
3731
ZEND_METHOD(SensitiveParameterValue, getValue);
38-
ZEND_METHOD(SensitiveParameterValue, __serialize);
39-
ZEND_METHOD(SensitiveParameterValue, __unserialize);
4032
ZEND_METHOD(SensitiveParameterValue, __debugInfo);
4133

4234

@@ -67,8 +59,6 @@ static const zend_function_entry class_SensitiveParameter_methods[] = {
6759
static const zend_function_entry class_SensitiveParameterValue_methods[] = {
6860
ZEND_ME(SensitiveParameterValue, __construct, arginfo_class_SensitiveParameterValue___construct, ZEND_ACC_PUBLIC)
6961
ZEND_ME(SensitiveParameterValue, getValue, arginfo_class_SensitiveParameterValue_getValue, ZEND_ACC_PUBLIC)
70-
ZEND_ME(SensitiveParameterValue, __serialize, arginfo_class_SensitiveParameterValue___serialize, ZEND_ACC_PUBLIC)
71-
ZEND_ME(SensitiveParameterValue, __unserialize, arginfo_class_SensitiveParameterValue___unserialize, ZEND_ACC_PUBLIC)
7262
ZEND_ME(SensitiveParameterValue, __debugInfo, arginfo_class_SensitiveParameterValue___debugInfo, ZEND_ACC_PUBLIC)
7363
ZEND_FE_END
7464
};
@@ -129,7 +119,7 @@ static zend_class_entry *register_class_SensitiveParameterValue(void)
129119

130120
INIT_CLASS_ENTRY(ce, "SensitiveParameterValue", class_SensitiveParameterValue_methods);
131121
class_entry = zend_register_internal_class_ex(&ce, NULL);
132-
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
122+
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE;
133123

134124
zval property_value_default_value;
135125
ZVAL_UNDEF(&property_value_default_value);

0 commit comments

Comments
 (0)