Skip to content

CLI server: prevent using symlinks to escape the docroot - #23975

Open
DanielEScherzer wants to merge 3 commits into
php:PHP-8.6from
DanielEScherzer:cli-server-symlinks
Open

DanielEScherzer wants to merge 3 commits into
php:PHP-8.6from
DanielEScherzer:cli-server-symlinks

Conversation

@DanielEScherzer

Copy link
Copy Markdown
Member

No description provided.

@iluuu1994

Copy link
Copy Markdown
Member

Is this mitigation needed? I personally wouldn't think so. The built-in web server is documented to be a development tool only.

@DanielEScherzer

DanielEScherzer commented Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Is this mitigation needed? I personally wouldn't think so. The built-in web server is documented to be a development tool only.

Not strictly needed, but mythos flagged it as a footgun and it seems harmless to fix it so that the development tool is more secure

But because it is a development tool I didn't file a security report and send a patch for 8.2 (or even 8.4), just 8.6

@Sjord Sjord left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure whether this is a good idea. Using symlinks can be a bug or a feature. I think it can be useful to symlink other directories into the webroot. I imagine it being used quite often, so making it impossible can break people's workflows. I would like to see an RFC or at least a mailing list discussion on this.

Comment thread sapi/cli/tests/php_cli_server_024.phpt Outdated
Comment thread sapi/cli/php_cli_server.c
Comment thread sapi/cli/tests/php_cli_server_024.phpt Outdated
@DanielEScherzer

Copy link
Copy Markdown
Member Author

I imagine it being used quite often, so making it impossible can break people's workflows.

This is for the CLI server, which is explicitly a development only tool, and is documented as an experimental feature, https://www.php.net/manual/en/features.commandline.webserver.php

@iluuu1994

Copy link
Copy Markdown
Member

@DanielEScherzer Just to clarify: I don't object to this change. But I'll need some more time for the review, unless somebody beats me to it.

The server properly prevents escaping the document root with path traversal,
but does not account for escaping through the use of existing symlinks under
the document root. Add a test so that when the behavior changes it is visible.
In `php_cli_server_request_translate_vpath()`, after translating the requested
path, confirm that `realpath()` returns a path that is contained in the
document root.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants