Skip to content

Commit c838ae3

Browse files
Advise trusting the input in the allow_named_closures refusal message
deepclone_to_array() refuses to serialize a closure over a named callable unless allow_named_closures is set. The message now quotes the option and adds that it should be enabled only for trusted input, since a by-name payload can mint a Closure over any function or method of that name. This mirrors the polyfill's wording (symfony/polyfill#635), which additionally points at this extension; the extension does not suggest installing itself.
1 parent badf84e commit c838ae3

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

deepclone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ static void dc_copy_value(dc_ctx *ctx, zval *src, zval *dst, zval *mask_dst)
21002100
* ends must enable. */
21012101
if (func && (func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE)) {
21022102
if (!ctx->allow_named_closures) {
2103-
zend_value_error("deepclone_to_array(): serializing a closure over the named callable \"%s\" requires enabling the allow_named_closures option", ZSTR_VAL(func->common.function_name));
2103+
zend_value_error("deepclone_to_array(): serializing a closure over the named callable \"%s\" requires enabling the \"allow_named_closures\" option; do it only if you trust the input", ZSTR_VAL(func->common.function_name));
21042104
return;
21052105
}
21062106
if (!dc_class_allowed(ctx->allowed_ht, zend_ce_closure->name)) {

tests/deepclone_attribute_provenance.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ bool(true)
9999
bool(true)
100100
bool(true)
101101
== 5. a callable no attribute declares stays by-name (needs the opt-in) ==
102-
uncaptured: ValueError: deepclone_to_array(): serializing a closure over the named callable "loose" requires enabling the allow_named_closures option
102+
uncaptured: ValueError: deepclone_to_array(): serializing a closure over the named callable "loose" requires enabling the "allow_named_closures" option; do it only if you trust the input
103103
Done

tests/deepclone_from_array.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ try {
7070
deepclone_to_array(strlen(...));
7171
echo "no throw\n";
7272
} catch (ValueError $e) {
73-
var_dump($e->getMessage() === 'deepclone_to_array(): serializing a closure over the named callable "strlen" requires enabling the allow_named_closures option');
73+
var_dump($e->getMessage() === 'deepclone_to_array(): serializing a closure over the named callable "strlen" requires enabling the "allow_named_closures" option; do it only if you trust the input');
7474
}
7575
$clone = deepclone_from_array(deepclone_to_array(strlen(...), allow_named_closures: true), allow_named_closures: true);
7676
var_dump($clone('hello') === 5);

tests/deepclone_named_closure_optin.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ bool(true)
8989
bool(true)
9090
bool(true)
9191
== 3. a runtime named closure refuses to_array without the opt-in ==
92-
strlen: ValueError: deepclone_to_array(): serializing a closure over the named callable "strlen" requires enabling the allow_named_closures option
93-
Helper::pub: ValueError: deepclone_to_array(): serializing a closure over the named callable "pub" requires enabling the allow_named_closures option
92+
strlen: ValueError: deepclone_to_array(): serializing a closure over the named callable "strlen" requires enabling the "allow_named_closures" option; do it only if you trust the input
93+
Helper::pub: ValueError: deepclone_to_array(): serializing a closure over the named callable "pub" requires enabling the "allow_named_closures" option; do it only if you trust the input
9494
== 4. with the opt-in on both ends it round-trips by name ==
9595
bool(true)
9696
bool(true)

0 commit comments

Comments
 (0)