CVE-2024-23654 (published 2024-02-21T21:15Z)

discourse-ai is the AI plugin for the open-source discussion platform Discourse. Prior to commit 94ba0dadc2cf38e8f81c3936974c167219878edd, interactions with different AI services are vulnerable to admin-initiated SSRF attacks. Versions of the plugin that include commit 94ba0dadc2cf38e8f81c3936974c167219878edd contain a patch. As a workaround, one may disable the discourse-ai plugin.\n


Weakness information:
cwe_id: NVD-CWE-noinfo
cwe_name: Insufficient Information
description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
extended_description: Insufficient Information

Fix information:
repo_url: https://github.com/discourse/discourse-ai
commit_details: repo_url: https://github.com/discourse/discourse-ai
author: Roman Rizzi
author_date: 2024-02-21 17:14:50-03:00
msg: SECURITY: Place a SSRF protection when calling services from the plugin. (#485)

The Faraday adapter and `FinalDestionation::HTTP` will protect us from admin-initiated SSRF attacks when interacting with the external services powering this plugin features.:
repository: repo_url: https://github.com/discourse/discourse-ai
repo_name: discourse/discourse-ai
repo_language: Ruby
owner: discourse
file_changes: filename: base.rb
change_type: ModificationType.MODIFY
diff: @@ -69,7 +69,7 @@ module DiscourseAi
 
           prompt = dialect.translate
 
-          Net::HTTP.start(
+          FinalDestination::HTTP.start(
             model_uri.host,
             model_uri.port,
             use_ssl: true,

programming_language: Ruby
filename: cloudflare_workers_ai.rb
change_type: ModificationType.MODIFY
diff: @@ -14,7 +14,8 @@ module ::DiscourseAi
 
         endpoint = "#{base_url}#{model}"
 
-        response = Faraday.post(endpoint, content.to_json, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post(endpoint, content.to_json, headers)
 
         raise Net::HTTPBadResponse if ![200].include?(response.status)
 

programming_language: Ruby
filename: discourse_classifier.rb
change_type: ModificationType.MODIFY
diff: @@ -8,7 +8,8 @@ module ::DiscourseAi
 
         headers["X-API-KEY"] = api_key if api_key.present?
 
-        response = Faraday.post(endpoint, { model: model, content: content }.to_json, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post(endpoint, { model: model, content: content }.to_json, headers)
 
         raise Net::HTTPBadResponse if ![200, 415].include?(response.status)
 

programming_language: Ruby
filename: discourse_reranker.rb
change_type: ModificationType.MODIFY
diff: @@ -8,8 +8,9 @@ module ::DiscourseAi
 
         headers["X-API-KEY"] = api_key if api_key.present?
 
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
         response =
-          Faraday.post(
+          conn.post(
             endpoint,
             { model: model, content: content, candidates: candidates }.to_json,
             headers,

programming_language: Ruby
filename: gemini_embeddings.rb
change_type: ModificationType.MODIFY
diff: @@ -11,7 +11,8 @@ module ::DiscourseAi
 
         body = { content: { parts: [{ text: content }] } }
 
-        response = Faraday.post(url, body.to_json, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post(url, body.to_json, headers)
 
         raise Net::HTTPBadResponse if ![200].include?(response.status)
 

programming_language: Ruby
filename: hugging_face_text_embeddings.rb
change_type: ModificationType.MODIFY
diff: @@ -18,7 +18,8 @@ module ::DiscourseAi
           headers["X-API-KEY"] = SiteSetting.ai_hugging_face_tei_api_key
         end
 
-        response = Faraday.post(api_endpoint, body, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post(api_endpoint, body, headers)
 
         raise Net::HTTPBadResponse if ![200].include?(response.status)
 

programming_language: Ruby
filename: open_ai_embeddings.rb
change_type: ModificationType.MODIFY
diff: @@ -15,7 +15,8 @@ module ::DiscourseAi
         payload = { model: model, input: content }
         payload[:dimensions] = dimensions if dimensions.present?
 
-        response = Faraday.post(SiteSetting.ai_openai_embeddings_url, payload.to_json, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post(SiteSetting.ai_openai_embeddings_url, payload.to_json, headers)
 
         case response.status
         when 200

programming_language: Ruby
filename: open_ai_image_generator.rb
change_type: ModificationType.MODIFY
diff: @@ -28,7 +28,7 @@ module ::DiscourseAi
           response_format: "b64_json",
         }
 
-        Net::HTTP.start(
+        FinalDestination::HTTP.start(
           uri.host,
           uri.port,
           use_ssl: uri.scheme == "https",

programming_language: Ruby
filename: stability_generator.rb
change_type: ModificationType.MODIFY
diff: @@ -57,7 +57,8 @@ module ::DiscourseAi
 
         endpoint = "v1/generation/#{engine}/text-to-image"
 
-        response = Faraday.post("#{api_url}/#{endpoint}", payload.to_json, headers)
+        conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
+        response = conn.post("#{api_url}/#{endpoint}", payload.to_json, headers)
 
         if response.status != 200
           Rails.logger.error(

programming_language: Ruby
filename: endpoint_compliance.rb
change_type: ModificationType.MODIFY
diff: @@ -99,13 +99,13 @@ class EndpointMock
 
   def with_chunk_array_support
     mock = mocked_http
-    @original_net_http = ::Net.send(:remove_const, :HTTP)
-    ::Net.send(:const_set, :HTTP, mock)
+    @original_net_http = ::FinalDestination.send(:remove_const, :HTTP)
+    ::FinalDestination.send(:const_set, :HTTP, mock)
 
     yield
   ensure
-    ::Net.send(:remove_const, :HTTP)
-    ::Net.send(:const_set, :HTTP, @original_net_http)
+    ::FinalDestination.send(:remove_const, :HTTP)
+    ::FinalDestination.send(:const_set, :HTTP, @original_net_http)
   end
 
   protected
@@ -113,7 +113,7 @@ class EndpointMock
   # Copied from https://github.com/bblimke/webmock/issues/629
   # Workaround for stubbing a streamed response
   def mocked_http
-    Class.new(::Net::HTTP) do
+    Class.new(FinalDestination::HTTP) do
       def request(*)
         super do |response|
           response.instance_eval do

programming_language: Ruby