Skip to content
Memory corruption Disclosed report Advanced

Use After Free Vulnerability in array_walk()/array_walk_recursive()

A use-after-free can occur in PHP's array_walk() when the callback modifies the array being walked, and the reporter says it can still be triggered remotely in some real-world apps.

ryat Follow

Originally disclosed on HackerOne

  • Fixed in 45 hours
  • Paid in 45 hours
  • Disclosed after 3.2 years

https://bugs.php.net/bug.php?id=70713

I think this bugs is still security issue since this bug can be still triggered remotely in some real world&apps.

Example: https://github.com/zendframework/zend-loader/blob/ceb32b5129525e1f19b01f37dbbcc6398b0a9635/src/ClassMapAutoloader.php#L210-L215

        array_walk($parts, function ($value, $key) use (&$parts) {
            if ($value === '..') {
                unset($parts[$key], $parts[$key-1]);
                $parts = array_values($parts);  <==  ['x', 'y', '..'] will be changed into ['x'] from the memory, it is possible to lead to use-after-free.
            }
        });

The original report as published on HackerOne, by ryat. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the internal pointer used by array_walk() is not updated when the callback modifies the array, so it later accesses freed memory.

Impact

This could allow remote attackers to trigger a use-after-free in applications that pass user-controlled arrays to these functions.

What the attacker needed

Application uses array_walk with user input; callback modifies the array

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program walks through an array and the callback changes that same array, it can end up using memory that has already been freed. This is a use-after-free bug. The PHP function array_walk is affected when the callback removes items from the array.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by ryat

View all

43 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.