php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74758 \Closure::call allows full access to private properties
Submitted: 2017-06-14 08:53 UTC Modified: 2017-06-14 19:27 UTC
From: martijn at openbsd dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.0.20 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
36 + 9 = ?
Subscribe to this entry?

 
 [2017-06-14 08:53 UTC] martijn at openbsd dot org
Description:
------------
\Closure::call allows full access to private properties when the closure contains $this->...

Test script:
---------------
<?php
class A {
        private $C = 1;
        private function B() {
                return "B";
        }
}

$a = new A;

$b = function() {
        return $this->B();
};

$c = function() {
        $this->C = 2;
};

var_dump($b->call($a));
$c->call($a);
var_dump($a);
?>


Expected result:
----------------
PHP Fatal error:  Uncaught Error: Call to private method A::B() from context '' in /tmp/test.php:22

Actual result:
--------------
string(1) "B"
object(A)#1 (1) {
  ["C":"A":private]=>
  int(2)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-14 19:16 UTC] stas@php.net
-Type: Security +Type: Bug
 [2017-06-14 19:16 UTC] stas@php.net
Not a security issue, PPP is not a security measure.
 [2017-06-14 19:27 UTC] kelunik@php.net
-Status: Open +Status: Not a bug
 [2017-06-14 19:27 UTC] kelunik@php.net
This is expected behavior, see http://php.net/manual/en/closure.bindto.php.

> The “bound object” determines the value $this will have in the function body and the “class scope” represents a class which determines which private and protected members the anonymous function will be able to access.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC