CVE-2021-25972 (published 2021-10-20T12:15Z)

In Camaleon CMS, versions 2.1.2.0 to 2.6.0, are vulnerable to Server-Side Request Forgery (SSRF) in the media upload feature, which allows admin users to fetch media files from external URLs but fails to validate URLs referencing to localhost or other internal servers. This allows attackers to read files stored in the internal server.

Severity: MEDIUM
CVSS v2 base score: 4.0 (AV:N/AC:L/Au:S/C:P/I:N/A:N)
CVSS v3 base score: 4.9, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-918
cwe_name: Server-Side Request Forgery (SSRF)
description: The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.
extended_description: By providing URLs to unexpected hosts or ports, attackers can make it appear that the server is sending the request, possibly bypassing access controls such as firewalls that prevent the attackers from accessing the URLs directly. The server can be used as a proxy to conduct port scanning of hosts in internal networks, use other URLs such as that can access documents on the system (using file://), or use other protocols such as gopher:// or tftp://, which may provide greater control over the contents of requests.
         

Fix information:
repo_url: https://github.com/owen2345/camaleon-cms
commit_details: repo_url: https://github.com/owen2345/camaleon-cms
author: Brian Kephart
author_date: 2021-10-12 00:02:51-05:00
msg: Disallow uploads from localhost
repository: repo_url: https://github.com/owen2345/camaleon-cms
repo_name: owen2345/camaleon-cms
description: Camaleon CMS is a dynamic and advanced content management system based on Ruby on Rails
repo_language: Ruby
owner: owen2345
file_changes: filename: media_controller.rb
change_type: ModificationType.MODIFY
diff: @@ -4,6 +4,15 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
   skip_before_action :verify_authenticity_token, only: :upload, raise: false
   before_action :init_media_vars, except: :download_private_file
 
+  LOCALHOST_DOMAIN_MATCHER = %r{
+    localhost|
+    127\.0\.0\.1|
+    0\.0\.0\.0|
+    0x7f\.0x0\.0x0\.0x1| # hex encoding
+    0177\.0\.0\.01| # octal encoding
+    2130706433 # dword encoding
+  }x
+
   # render media section
   def index
     authorize! :manage, :media
@@ -67,7 +76,11 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
         unless params[:url].start_with?('data:')
           params[:url] = (params[:url].start_with?('http') ? '' : current_site.the_url(locale: nil)) + params[:url]
         end
-        r = cama_tmp_upload( params[:url], formats: params[:formats], name: params[:name])
+        r = if local_url?(params[:url])
+              { error: t("camaleon_cms.admin.media.local_upload_denied") }
+            else
+              cama_tmp_upload( params[:url], formats: params[:formats], name: params[:name])
+            end
         unless r[:error].present?
           params[:file_upload] = r[:file_path]
           sett = {remove_source: true}
@@ -80,6 +93,10 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
     end
   end
 
+  def local_url?(url)
+    url.try :match?, LOCALHOST_DOMAIN_MATCHER
+  end
+
   # upload files from media uploader
   def upload(settings = {})
     params[:dimension] = nil if params[:skip_auto_crop].present?

programming_language: Ruby
filename: en.yml
change_type: ModificationType.MODIFY
diff: @@ -212,6 +212,7 @@ en:
         reload: 'Reload'
         clear_cache: 'Clear Cache'
         name_required: 'File name is required'
+        local_upload_denied: 'Cannot upload from localhost'
       menus:
         menus: Menus
         link_url: 'Link URL'

programming_language: CoffeeScript