Repository navigation
Security release
This release fixes several security vulnerabilities. Most of them allow escaping the root_dir sandbox (reading, writing, creating or changing files outside of it, up to remote code execution) or bypassing the protection of files like .htaccess and .htpasswd. Upgrading is strongly recommended for everyone.
A note on the default configuration: IFM ships with "auth" => 0. It is meant to run locally or behind authentication, either its own (auth => 1) or the web server's. Without any authentication, everyone who can reach the IFM can manage all files in root_dir, by design. The vulnerabilities below matter because they break the boundaries that still apply then: the root_dir sandbox and the protected files. On installations without any authentication, they are exploitable by anyone who can reach the IFM.
Reported vulnerabilities
| Advisory | Severity | Issue |
|---|---|---|
| GHSA-hj69-3cr4-95qg | high | root_dir escape via copyMove: a non-existent destination passed the sandbox check, and files were copied to arbitrary paths, e.g. a PHP file into another web root (remote code execution). The same advisory covers two more issues: .user.ini could be created (on PHP-FPM/CGI it enables e.g. auto_prepend_file), and archive extraction didn't check the names of the archive's entries, so it could place .htaccess or .user.ini files. |
| GHSA-544p-f57q-h55p | high | root_dir escape via .. behind a non-existent directory in a path (e.g. a/missing/../../../outside): such paths passed the sandbox check. Via the extract target, this allowed creating directories outside root_dir, and writing files there on Windows or by racing a concurrent request. |
| GHSA-85hh-4mm7-pmq2 | high | File read outside root_dir via copyMove: invalid source paths were reported as errors, but copied anyway, and could then be read. |
| GHSA-w5rm-rmhw-g8x2 | high | SSRF filter bypass in remoteUpload: the URL was validated, but a URL-decoded variant was fetched, so internal addresses could be reached. A DNS rebinding window existed as well. |
| GHSA-rj38-gv9f-3cmx | medium | Archive downloads disclosed protected files: when the system zip binary was available (e.g. in the official Docker image), zipnload ignored the file restrictions, so a directory download contained e.g. .htpasswd, .htaccess and hidden files. The PHP fallback didn't filter directories, and createArchive didn't filter at all. |
Many thanks to the reporters: @KKonaNN, @thedevilhunter225, @p-w (who also contributed the isPathValid() fix), @TateYdq, @levanduy181, @campguyuz, @Shalistera, @Krystiaaan and @lanjianchun.
Further security fixes
These were found during our own review, partly prompted by the reports above. There are no separate advisories for them.
- chmod outside
root_dir:changePermissionsvalidated the directory and file name, but changed the permissions of the raw file name. An absolute file name thus changed the permissions of arbitrary files outsideroot_dir. Thanks to @TateYdq for pointing at this code. - LDAP authentication bypass: a login with an existing user name and an empty password was accepted, because most LDAP servers treat such a bind as an anonymous bind, which succeeds. Additionally, the user name is now escaped when building the LDAP DN.
- CSRF: previous versions had no CSRF protection at all. A malicious website could make the browser of a logged-in user (also when logged in via the web server's Basic auth) perform actions like deleting files. State-changing API calls now require
POSTand a CSRF token, see the upgrade notes below. - Session hardening: the session cookie is now
HttpOnly,SameSite=Laxand, on HTTPS,Secure. The session ID is regenerated on login (session fixation), and logout destroys the session completely. - XSS and header injection via file names: file names in error messages (copy, move, delete) were not escaped, and the file name in the
Content-Dispositionheader of downloads was not sanitized. - With
auth => 1, the IFM refuses to run with the publicly known default credentials. - Internal error details (e.g. paths) are no longer sent to the client, and
getConfigno longer exposes internal settings liketmp_dir. - Symlink loops can no longer make search, the folder tree or archive creation recurse endlessly.
Upgrade notes (changed behaviour)
- API clients: state-changing calls (
createDir,saveFile,delete,rename,extract,upload,copyMove,changePermissions,remoteUpload,createArchive) must usePOSTand send a CSRF token. Fetch it fromapi=getConfig(fieldcsrf_token) and send it asX-IFM-CSRFheader orcsrf_tokenform field. Scripts can avoid this by authenticating each request via theX-IFM-AUTHheader (Basic <base64>or bare<base64>ofuser:pass). Requests authenticated via the standardAuthorizationheader need the token too, because browsers send cached Basic credentials automatically. The web UI handles all of this itself. See Authentication in the README. auth => 1together with the defaultauth_sourceis refused; configure your own credentials..user.iniis now protected like.htaccess: it can only be shown and edited withshowhtdocsenabled. The file listing, search and folder tree now hide all.ht*files and.user.ini(before, only.htaccessand.htpasswdwere hidden from the listing).- When extracting archives, entries whose names are not allowed (e.g.
.htaccess,.user.ini, hidden files withshowhiddenfilesdisabled) are skipped and listed in a warning. Target paths with..behind a non-existent directory are rejected. - Archives created by
zipnloadandcreateArchiveno longer contain files which can't be downloaded directly. - Copy/move requires an existing destination directory, and a directory can no longer be copied or moved into itself.
Other changes
- Performance: MIME types of well-known extensions are resolved from a static table instead of reading every file, which speeds up large directory listings considerably (2000 files: ~780 ms → ~3 ms).
- Performance: downloads support HTTP conditional requests (
ETag,Last-Modified,304), and the Docker image enables opcache (#215, thanks @novashdima). - Fixed: the
[ up ]entry was shown at the root directory withopen_basedir(#225). - Fixed: the Docker image couldn't be built anymore (#218, thanks @novashdima).
- Fixed: a crash in the timing-attack mitigation of the htpasswd authentication.
- Fixed: copying a directory into itself nested it until the maximum path length was reached.
- The README documents API authentication;
X-IFM-AUTHaccepts bothBasic <base64>and bare<base64>(#217, thanks @novashdima). - Build: the version is derived from the git tag, and releases are built by CI.
- Development: a PHPUnit test suite with more than 200 tests, including regression tests for all of the above, PHPStan, CI for PHP 8.1 to 8.5, a
SECURITY.md.
Known issue: tar archives with ./-prefixed entries can't be extracted, and file names containing * can't be put into tar archives (#227).
Upgrading
Replace your ifm.php with the one attached below (or ifm.min.php, cdn.ifm.php, cdn.ifm.min.php, depending on which variant you use). If you use Docker, rebuild your image.
Full changelog: v4.1.2...v4.2.0