CVE-2023-27577: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (CWE-22)
value: flarum is a forum software package for building communities. In versions prior to 1.7.0 an admin account which has already been compromised by an attacker may use a vulnerability in the `LESS` parser which can be exploited to read sensitive files on the server through the use of path traversal techniques. An attacker can achieve this by providing an absolute path to a sensitive file in the custom `LESS` setting, which the `LESS` parser will then read. For example, an attacker could use the following code to read the contents of the `/etc/passwd` file on a linux machine. The scope of what files are vulnerable will depend on the permissions given to the running flarum process. The vulnerability has been addressed in version `1.7`. Users should upgrade to this version to mitigate the vulnerability. Users unable to upgrade may mitigate the vulnerability by ensuring that their admin accounts are secured with strong passwords and follow other best practices for account security. Additionally, users can limit the exposure of sensitive files on the server by implementing appropriate file permissions and access controls at the operating system level.

CWE description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
CVSS v3 base score: 4.9
Published: 2023-03-10T21:15Z
Repository: https://github.com/flarum/framework
Language: PHP
Files changed: framework/core/locale/core.yml, framework/core/src/Forum/ValidateCustomLess.php
Commit date: 2023-03-04 20:38:19 +0100
Commit message: fix: disallow certain dangerous LESS features

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>

Diff: diff --git a/framework/core/locale/core.yml b/framework/core/locale/core.yml
index c41df6366..dcf824c5c 100644
--- a/framework/core/locale/core.yml
+++ b/framework/core/locale/core.yml
@@ -16,10 +16,11 @@ core:
       colors_text: "Choose two colors to theme your forum with. The first will be used as a highlight color, while the second will be used to style background elements."
       custom_footer_heading: Custom Footer
       custom_footer_text: => core.ref.custom_footer_text
       custom_header_heading: Custom Header
       custom_header_text: => core.ref.custom_header_text
+      custom_styles_cannot_use_less_features: "The @import and data-uri features are not allowed in custom LESS."
       custom_styles_heading: Custom Styles
       custom_styles_text: Customize your forum's appearance by adding your own Less/CSS code to be applied on top of Flarum's default styles.
       dark_mode_label: Dark Mode
       description: "Customize your forum's colors, logos, and other variables."
       edit_css_button: Edit Custom CSS
diff --git a/framework/core/src/Forum/ValidateCustomLess.php b/framework/core/src/Forum/ValidateCustomLess.php
index 85cfd8b95..430d35ae1 100644
--- a/framework/core/src/Forum/ValidateCustomLess.php
+++ b/framework/core/src/Forum/ValidateCustomLess.php
@@ -19,10 +19,11 @@ use Flarum\Settings\SettingsRepositoryInterface;
 use Illuminate\Contracts\Container\Container;
 use Illuminate\Filesystem\FilesystemAdapter;
 use League\Flysystem\Adapter\NullAdapter;
 use League\Flysystem\Filesystem;
 use Less_Exception_Parser;
+use Symfony\Contracts\Translation\TranslatorInterface;
 
 /**
  * @internal
  */
 class ValidateCustomLess
@@ -59,10 +60,19 @@ class ValidateCustomLess
     {
         if (! isset($event->settings['custom_less']) && ! $this->hasDirtyCustomLessSettings($event)) {
             return;
         }
 
+        // Restrict what features can be used in custom LESS
+        if (preg_match('/@import|data-uri\s*\(/i', $event->settings['custom_less'])) {
+            $translator = $this->container->make(TranslatorInterface::class);
+
+            throw new ValidationException([
+                'custom_less' => $translator->trans('core.admin.appearance.custom_styles_cannot_use_less_features')
+            ]);
+        }
+
         // We haven't saved the settings yet, but we want to trial a full
         // recompile of the CSS to see if this custom LESS will break
         // anything. In order to do that, we will temporarily override the
         // settings repository with the new settings so that the recompile
         // is effective. We will also use a dummy filesystem so that nothing

Fixed code:       custom_styles_cannot_use_less_features: "The @import and data-uri features are not allowed in custom LESS."
use Symfony\Contracts\Translation\TranslatorInterface;
        // Restrict what features can be used in custom LESS
        if (preg_match('/@import|data-uri\s*\(/i', $event->settings['custom_less'])) {
            $translator = $this->container->make(TranslatorInterface::class);

            throw new ValidationException([
                'custom_less' => $translator->trans('core.admin.appearance.custom_styles_cannot_use_less_features')
            ]);
        }