Skip to content

v4.2.0 - security release

Latest

Choose a tag to compare

@github-actions github-actions released this 16 Nov 00:54

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: changePermissions validated 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 outside root_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 POST and a CSRF token, see the upgrade notes below.
  • Session hardening: the session cookie is now HttpOnly, SameSite=Lax and, 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-Disposition header 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 getConfig no longer exposes internal settings like tmp_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 use POST and send a CSRF token. Fetch it from api=getConfig (field csrf_token) and send it as X-IFM-CSRF header or csrf_token form field. Scripts can avoid this by authenticating each request via the X-IFM-AUTH header (Basic <base64> or bare <base64> of user:pass). Requests authenticated via the standard Authorization header 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 => 1 together with the default auth_source is refused; configure your own credentials.
  • .user.ini is now protected like .htaccess: it can only be shown and edited with showhtdocs enabled. The file listing, search and folder tree now hide all .ht* files and .user.ini (before, only .htaccess and .htpasswd were hidden from the listing).
  • When extracting archives, entries whose names are not allowed (e.g. .htaccess, .user.ini, hidden files with showhiddenfiles disabled) are skipped and listed in a warning. Target paths with .. behind a non-existent directory are rejected.
  • Archives created by zipnload and createArchive no 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 with open_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-AUTH accepts both Basic <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