Skip to content

@strict-properties can be bypassed using unserialization #9186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimWolla opened this issue Jul 28, 2022 · 8 comments
Closed

@strict-properties can be bypassed using unserialization #9186

TimWolla opened this issue Jul 28, 2022 · 8 comments

Comments

@TimWolla
Copy link
Member

Description

The following code:

<?php

var_dump(unserialize('O:17:"Random\Randomizer":1:{i:0;a:2:{s:3:"foo";N;s:6:"engine";O:32:"Random\Engine\Xoshiro256StarStar":2:{i:0;a:0:{}i:1;a:4:{i:0;s:16:"7520fbc2d6f8de46";i:1;s:16:"84d2d2b9d7ba0a34";i:2;s:16:"d975f36db6490b32";i:3;s:16:"c19991ee16785b94";}}}}'));

Resulted in this output:

object(Random\Randomizer)#1 (2) {
  ["engine"]=>
  object(Random\Engine\Xoshiro256StarStar)#2 (1) {
    ["__states"]=>
    array(4) {
      [0]=>
      string(16) "7520fbc2d6f8de46"
      [1]=>
      string(16) "84d2d2b9d7ba0a34"
      [2]=>
      string(16) "d975f36db6490b32"
      [3]=>
      string(16) "c19991ee16785b94"
    }
  }
  ["foo"]=>
  NULL
}

But I expected an error instead, because the ->foo property should not exist in the Randomizer as per:

/**
* @strict-properties
*/

Not sure if this is a bug in the implementation of Randomizer or a more general unserialization bug.

PHP Version

Current git master

Operating System

No response

@TimWolla TimWolla changed the title @strict-properties can be bypassed using serialization @strict-properties can be bypassed using unserialization Jul 28, 2022
@cmb69
Copy link
Member

cmb69 commented Jul 29, 2022

The problem is

object_properties_load(&randomizer->std, Z_ARRVAL_P(members_zv));

That initializes any given property. We likely want to catch cases where undeclared properties are given.

@TimWolla
Copy link
Member Author

The problem is

I assumed as much. But I was not able to determine, whether ext/random should've used a different function (making this a bug in ext/random) or whether the function itself should be fixed (not making this a bug in ext/random).

@cmb69
Copy link
Member

cmb69 commented Jul 29, 2022

Good question! It seems to me that the dynamic properties deprecation missed unserialization and related things. E.g. https://3v4l.org/FUgco/rfc#output behaves unexpected for me.

I'm not sure whether we can "fix" this now (in the general case); might be a bit too late in the pre-release cycle.

@ramsey, @saundefined, @adoy, thoughts?

@iluuu1994
Copy link
Member

Was a decision made here whether this should be fixed in PHP 8.2?

@ramsey
Copy link
Member

ramsey commented Aug 12, 2022

We've not discussed it. I need to read up on it and understand it a bit more, and will see if we can make a decision soon.

@saundefined
Copy link
Member

@cmb69 we're probably a little late with this change, because RC1 is coming out soon,

but we can discuss whether to include it in PHP 8.2 (and maybe we can introduce Beta 4, so there won't be a big change in the RC cycle).

Let's discuss it in internals.

kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 17, 2022
kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 17, 2022
@kocsismate
Copy link
Member

As far as I see, this is a bug which should be fixed ASAP. For any case, I created a fix in #9354. It also deals with Tyson's suggestion in #9325 about triggering dynamic property deprecations. (The fix may be yet be exhaustive as I'm not very familiar with the unserialization code, but it is hopefully a good first step into the right direction)

kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 17, 2022
kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 25, 2022
kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 25, 2022
kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 29, 2022
kocsismate added a commit to kocsismate/php-src that referenced this issue Aug 29, 2022
@kocsismate
Copy link
Member

kocsismate commented Aug 30, 2022

There was not much discussion..., and I still firmly believe we should ship this fix as soon as possible, so I'll merge my fix in ~2 hours, before branching takes place, unless there is a strong resistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants