Feature Wiki
Tabs
Filesystem Service
Page Overview
[Hide]1 Initial Problem
Currently there are several ways to access the local filesystem within ILIAS. Because of the different access method there is lot of space for security issues. A good example is the import functionality provided by various ILIAS modules. Furthermore there is currently no way to extend ILIAS to access other filesystems like an Amazone S3 Bucket.
1.1 Security
The ILIAS 5.2 import functionality havy relies on XML which contains relative filepaths, which are concatinated while the import is running. Each modul has its own import logic which copy the files directly with the help of build in php functions or the help of the utility class ilUtil. Therefore each module needs to sanitize every concatenated path which leads to an insecure import.
The table below shows an incomplete list of file operations done by ILIAS, which are roughly 500 in total. The data below were collected with the help of dicto.
Filesystem Access | Count |
---|---|
fopen | 156 |
file_get_contents | 106 |
file_put_contents | 43 |
copy | 195 |
1.1.1 Example
ILIAS 5.2 had a bug which allowed a user with rights to import a FileObject to move files to arbitrary locations. This bug was possible because the destination and source path was not validated at all. Because of that, it was possible to move files out of the ILIAS webroot (denial of service, Line 6) or copy files into the webroot (remote code execution, Line 10).
The paths in the example below are only for illustration and point to invalid locations.
1 | <?xml version="1.0" encoding="utf-8"?> |
2 Conceptual Summary
To eleminate security issues like path traversal, we would like to introduce a new Filesystem Service which streamlines the filesystem access for ILIAS. The service provides a modular way for extension, which enables the ILIAS community to seamless extend the service with additional supported filesystem types.
There are four directories which should be accessed via the new service:
- Data directory within the ILIAS webroot
- ILIAS data directory
- Customizing directory
- Temporary directory
2.1 Interface
The interface provides the following functionality
1 | //Write Files |
2.1.1 Filesystem access right management
The Filesystem Service interface shows a way to change the access right of a file or folder.
But is it really needed to manage the access rights? This point needs some further clarifications.
2.2 ILIAS DI Integration
To use the new filesystem service we need to introduce a new key to the DIC named "filesystem".
It's possible to access the 4 storage locations via the methods described bellow. Each of the 4 Methods return a filesystem object which satiffies the interface described in the section 2.1.
1 | //new filesystem service key |
2.3 ilUtil method deprication
The following ilUtil methods should be depreciated with the new filesystem service.
ilUtil method | replacement |
---|---|
makeDir | createDir |
makeDirParents | createDir |
delDir | deleteDir |
getDir | listContents |
getWebspaceDir | $DIC["filesystem"]->web() |
getDataDir | $DIC["filesystem"]->storage() |
createDirectory | createDir |
2.4 Dicto
We propose to create dicto rules to aid the refactoring process. The new dicto rules should report direct access of php filesystem functions and the listed ilUtil methods described in section 2.3.
The table below contains all php function which should no longer be used.
php function blacklist |
---|
chgrp |
chmod |
chown |
clearstatcache |
copy |
delete |
disk_free_space |
disk_total_space |
diskfreespace |
file_exists |
file_get_contents |
file_put_contents |
file |
fileatime |
filectime |
filegroup |
fileinode |
filemtime |
fileowner |
fileperms |
filesize |
filetype |
flock |
fnmatch |
glob |
is_dir |
is_executable |
is_file |
is_link |
is_readable |
is_uploaded_file |
is_writeable |
is_writable |
lchgrp |
lchown |
link |
linkinfo |
lstat |
mkdir |
move_uploaded_file |
parse_ini_file |
pathinfo |
readfile |
readlink |
realpath_cache_get |
realpath_cache_size |
realpath |
rename |
rmdir |
set_file_buffer |
stat |
symlink |
tempnam |
tmpfile |
touch |
umask |
unlink |
3 User Interface Modifications
4 Technical Information
The technical information is arleady described in "Conceptual Summary". The FileSystemService comes with a great benefit for ILIAS in general. The migration will take some time but from the security-POV this should be done.
5 Contact
- Author of the Request: (studer+raimann ag)
- Maintainer: Schmid, Fabian [fschmid]
- Implementation of the feature is done by: Schmid, Fabian [fschmid]
6 Funding
If you are interest in funding this feature, please add your name and institution to this list.
7 Discussion
Kunkel, Matthias [mkunkel], May 02, 2017: I added this suggestion to the next Jour Fixe agenda. Just one question: does this suggestion also include to change all current implementations of local file system accesses in all components? Or is it a concept to be used for new implemented features that need file system access?
Amstutz, Timon [amstutz], May 04, 2017: I like this and look forward to the PR describing the complete interface of this new addition to the src folder. We definitely need such a library. One feature I would strongly recommend is to add some xcopy function to recursively copy the content of a complete folder.
Schmid, Fabian [fschmid], May 8, 2017: @Matthias: Since there are many accesses to the FileSystem, the conversion would probably take place over two releases, unless sufficient funding is available. For the file objects, we would adjust the necessary places.
@Timon: Thanks for the good note with xcopy, we will add thisd to the interface.
As the Maintainer a highly support this FR.
Klees, Richard [rklees], May 8, 2017: I really like this.
Killing, Alexander [alex], 8 May 2017: It will be great to have something like this. Some points:
- $filesystem->setVisibility('data/dir/example.txt', 'public'); Does what exactly? "public" seems to be some magic string we usually would like to avoid.
- Since the feature already "has knowledge" of the web data and "storage" data directories, I think it should take care of the components subdirectories, too. The naming of these directories still suffers from inconsistencies. Also the ID to subdirectory mapping should imo be provided by the service. So basically I think it should provide enough functionality that it can replace ilFileSystemStorage (under Services/File) completely. It would be strange to have these things being split up in two services.
JourFixe, ILIAS [jourfixe], May 08, 2017: We highly appreciate this suggestion and schedule it for 5.3. We would like to have a pull request for the file system interface and a strategy how to migrate existing ilFileSystemStorage related code
- Roadmap for 5.3: implementation of new file system service, setting file access methods in ilUtil to deprecated (2.3), implement Dicto rules
- Roadmap for 5.4: complete substitution of ilUtil and native PHP function
8 Implementation
This features is mainly dedicated for developers, the relevant information on the interface is available here: https://github.com/ILIAS-eLearning/ILIAS/blob/release_5-3/src/Filesystem/FilesystemFacade.php
The methods provided by ilUtil have been marked as deprecated and use the new service internally.
An example how to use the new FileSystemService is described here:
1 | global $DIC; |
A full description of the service can be found here: https://github.com/ILIAS-eLearning/ILIAS/blob/release_5-3/src/Filesystem/README.md
Test Cases
FileSystem-Service is a core-service which many Modules and Features rely on. Testing is done implicitly by many Testcases.
Approval
Approved at 28.8.2017 by Amstutz, Timon [amstutz].
Last edited: 15. Dec 2021, 09:09, Schmid, Fabian [fschmid]