Skip to content

Commit

Permalink
Avoid Arbitrary File Deletion abuse via Object Injection
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdruid committed Dec 3, 2024
1 parent a1e583f commit dd75c9d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/src/Grav/Framework/Cache/Adapter/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private function write($file, $data, $expiresAt = null)

try {
if ($this->tmp === null) {
$this->tmp = $this->directory . uniqid('', true);
$this->tmp = $this->directory . uniqid(__CLASS__, true);
}

file_put_contents($this->tmp, $data);
Expand Down Expand Up @@ -259,7 +259,7 @@ public static function throwError($type, $message, $file, $line)
#[\ReturnTypeWillChange]
public function __destruct()
{
if ($this->tmp !== null && file_exists($this->tmp)) {
if ($this->tmp !== null && (strpos(basename($this->tmp), __CLASS__) === 0) && file_exists($this->tmp)) {
unlink($this->tmp);
}
}
Expand Down

0 comments on commit dd75c9d

Please sign in to comment.