Closed zigmoo closed 1 year ago
Thank you for reporting. This is not a bug.
CodeIgniter autoloader does not allow special characters that are illegal in filenames on certain operating systems. The symbols that can be used are /, _, ., :, \ and space. So if you install CodeIgniter under the folder that contains the special characters like (, ), etc., CodeIgniter won’t work. https://codeigniter4.github.io/CodeIgniter4/installation/installing_composer.html#installation
php spark serve should start the application, no matter what characters are present in the path name.
Why do you think so? Are you sure this CodeIgniter sanitization process is absolutely unnecessary?
It came from: https://github.com/codeigniter4/CodeIgniter4/commit/62381f3c
The current code: https://github.com/codeigniter4/CodeIgniter4/blob/d8d52757b38c16a836e5296c331ecf9a6e9f324d/system/Autoloader/Autoloader.php#L302-L312 https://github.com/codeigniter4/CodeIgniter4/blob/d8d52757b38c16a836e5296c331ecf9a6e9f324d/system/Autoloader/Autoloader.php#L278-L289
@codeigniter4/core-team
At least, just using the sanitizeFilename()
method when autoloading a file is not good.
Because if a filename is sanitized, the autoloading will fail surely, but the error message is like:
Class "Config\App" not found
It does not tell why not found. It seems better throwing an exception with a proper message if a filename is sanitized.
Also, I'm not sure how much sense it makes to do this sanitization process during autoloading. But I also don't have a reason why it should be actively removed.
The code already states:
Modified to allow backslash and colons for on Windows machines.
I think we should just expand the regex to include non-initial tildes.
In the first place, why do we need to sanitize the filename prior to autoloading? What risks are we preventing? Path traversal attacks?
I think we need to separate the cases of autoloading and other cases.
Suppose the autoloader tries to load a class name from user input, what are the possible risks?
Possible vulnerability in autoloading is Local File Inclusion.
If an attacker is able to include a file with an arbitrary path on the server, s/he can execute arbitrary code on the server if s/he is able to upload a file to the server.
It seems .
is not permitted unless PHP 5.3.0 - 5.3.29, 5.4.0 - 5.4.23, 5.5.0 - 5.5.7
https://3v4l.org/SUUZe
The code already states:
Modified to allow backslash and colons for on Windows machines.
I think we should just expand the regex to include non-initial tildes.
Agreed!
BTW, I really appreciate the consideration you all have given to this issue!
I forgot that we have improved the error message since v4.3.
$ php spark serve
PHP Fatal error: Uncaught InvalidArgumentException: The file path contains special characters "~" that are not allowed: ".../~newApp/vendor/codeigniter4/framework/system/Autoloader/FileLocator.php" in /.../~newApp/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php:342
Stack trace:
In my opinion, the autoloader sanitization process should be removed. If we check, we should check only the classname.
Besides, I don't see the need for the public sanitizeFilename()
method to exist in the autoloader.
In my opinion, the autoloader sanitization process should be removed. If we check, we should check only the classname.
Besides, I don't see the need for the public
sanitizeFilename()
method to exist in the autoloader.
I agree. Looking at composer, I don't see being a security issue the absence of a sanitization method.
Hello All,
Are y'all feeling thumbs-up, or thumbs-down about the idea of changing Autoloader->sanitizeFilename() 's from its current state of disallowing all tildes in the path, to only negating a begins-with tilde?
$result = preg_match_all('/[^0-9\p{L}\s\/\-_.:\\\\]/u', $filename, $matches);
to
++++ +
$result = preg_match_all('/^[~]|[^0-9\p{L}\s\/\-_.:\\\\~]/u', $filename, $matches);
Naturally, I would certainly appreciate this change.
I think add ~
is the safer, In Laminas, there is~
in URI check as well as unreserved char https://github.com/laminas/laminas-uri/blob/663b050294945c7345cc3a61f3ca661d5f9e1f80/src/Uri.php#L45
This is not the case of URI. This is an issue in Autoloading.
I vote +1 to deprecate Autoloader->sanitizeFilename() and do not use it.
I sent a PR #7310
Closed by #7310
PHP Version
8.2
CodeIgniter4 Version
4.2.11
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Database
none
What happened?
When a fresh composer-created CodeIgniter 4 application has a tilde(~) in its path, it crashes when staring with "php spark serve".
This is a critical failure, because on MacOS in all filesystem areas synced to iCloud, tildes are present, like so:
/Users/moo/Library/Mobile Documents/com~apple~CloudDocs/Documents/development/swapper/vendor/codeigniter4
I moved the fresh new app out of the com~apple~CloudDocs directory tree to /Users/shared/dev/swapper, and it immediately starts up fine with "php spark serve".
After renaming the directory from "/Users/shared/dev/swapper" to "/Users/shared/dev/~swapper", the application immediately fails when started with "php spark serve".
CodeIgniter_4.2.11_tilde_bug.pdf
Steps to Reproduce
Expected Output
php spark serve should start the application, no matter what characters are present in the path name. And ESPECIALLY tildes should be accounted for, because all MacOS users should be using iCloud to sync their files.
Anything else?
The test log on my machine: