Skip to content

[13.x] Block phar:// stream wrapper in Filesystem::exists() and isFile() - #62164

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
AsahiSoftWareEngineer:fix/filesystem-phar-stream-wrapper
Oct 24, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
AsahiSoftWareEngineer:fix/filesystem-phar-stream-wrapper

Conversation

@AsahiSoftWareEngineer

@AsahiSoftWareEngineer AsahiSoftWareEngineer commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

There are a few reasons why I think this should be addressed at the framework level.

First, methods like Filesystem::exists() and isFile() pass paths directly to PHP's native filesystem functions without checking for the phar:// scheme. This can potentially introduce a deserialization risk.

Interestingly, Storage:: doesn't have the same behavior because Flysystem's path normalizer happens to modify the phar:// URI. However, this seems to be an implementation detail rather than an intentional security measure, and Filesystem:: doesn't provide equivalent protection.

Laravel 13 has already introduced protections against PHP deserialization gadget chains in its cache and session handling. I think it would make sense to apply the same security considerations to filesystem operations for consistency.

The proposed fix is also fairly small. Adding a scheme check to the relevant filesystem methods should be straightforward, without affecting normal filesystem operations.

Changes

  • Filesystem::exists() returns false for phar:// paths
  • Filesystem::isFile() returns false for phar:// paths
  • Filesystem::get() throws FileNotFoundException for phar:// paths (via isFile())
  • Three tests added for the above behaviors

PHP filesystem functions automatically deserialize the PHAR manifest when
passed a phar:// URI, which can execute arbitrary code through gadget chains
present in vendor dependencies. Filesystem::exists() and isFile() now return
false for phar:// paths, preventing deserialization. Filesystem::get() is
protected transitively because it calls isFile() internally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AsahiSoftWareEngineer pushed a commit to AsahiSoftWareEngineer/docs that referenced this pull request Oct 23, 2026
…#62164

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@taylorotwell
taylorotwell merged commit a21f9d1 into laravel:13.x Oct 24, 2026
62 checks passed
taylorotwell pushed a commit to laravel/docs that referenced this pull request Oct 24, 2026
… upload risk (#11422)

* [13.x] Warn against user-controlled filenames in storeAs and polyglot file risk in mimes

* [13.x] Warn against PHAR deserialization via File:: facade and response()->download()

PHP filesystem functions trigger PHAR archive deserialization when passed a
phar:// URI. File::exists(), File::get(), and related methods call these
functions directly without scheme validation, as do response()->download()
and response()->file() internally via Symfony's BinaryFileResponse. An
attacker who can upload a polyglot PHAR file and influence a path argument
can exploit this to execute arbitrary code through gadget chains present in
vendor dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Remove PHAR deserialization warnings — addressed in laravel/framework#62164

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Asahi <asahi@AsahinoMacBook-Air.local>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
albertcht pushed a commit to hypervel/filesystem that referenced this pull request Nov 1, 2026
Port laravel/framework#62164 (a21f9d110a4b957defa0e14f6e43924b54470c58) together with required follow-up #62174 (02e2f700a3d8d43e55fc1878a593e7cf853c43da).

Apply the guard at exists/isFile so dependent file and require helpers reject foreign archives, while applications packaged in a running PHAR retain access to their own files. Compare only the protocol prefix and document the executable-file boundary without relying on obsolete automatic metadata-deserialization behavior.

Validation: all upstream cases, real archive rejection and bounded running-archive subprocess coverage pass (91 tests, 233 assertions); source/type analysis and formatting pass.
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