Skip to content

Conversation

@mcdruid
Copy link

@mcdruid mcdruid commented Dec 3, 2024

As discussed with @rhukster this simple change should avoid \Grav\Framework\Cache\Adapter\FileCache::__destruct being abused via Object Injection to achieve Arbitrary File Deletion.

I've used strpos rather than str_starts_with as it looks like Grav supports PHP 7.

@rhukster
Copy link
Member

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines 202 to 205
try {
if ($this->tmp === null) {
$this->tmp = $this->directory . uniqid('', true);
$this->tmp = $this->directory . uniqid(__CLASS__, true);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sanitize temp-file prefix on Windows

The new temp filename uses uniqid(__CLASS__, true), but __CLASS__ contains backslashes. On Windows these are treated as path separators, so the prefix Grav\Framework\Cache\Adapter\FileCache... expands into nested directories under $this->directory that are never created. As soon as file_put_contents($this->tmp, $data) runs, cache writes will fail with "No such file or directory" and the cache backend becomes unusable on Windows installations. Consider stripping namespace separators or using a simple prefix like FileCache.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants