CVE-2023-47635: Insufficient Information (NVD-CWE-noinfo)
value: Decidim is a participatory democracy framework. Starting in version 0.23.0 and prior to versions 0.27.5 and 0.28.0, the CSRF authenticity token check is disabled for the questionnaire templates preview. The issue does not imply a serious security thread as you need to have access also to the session cookie in order to see this resource. This URL does not allow modifying the resource but it may allow attackers to gain access to information which was not meant to be public. The issue is fixed in version 0.27.5 and 0.28.0. As a workaround, disable the templates functionality or remove all available templates.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-02-20T18:15Z
Repository: https://github.com/decidim/decidim
Language: JavaScript
Files changed: decidim-templates/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb, decidim-templates/app/packs/src/decidim/templates/admin/choose_template.js
Commit date: 2023-10-11 19:47:15 +0300
Commit message: Simplify the code related to questionnaire templates previews (#11743)


Diff: diff --git a/decidim-templates/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb b/decidim-templates/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb
index 9322c4a11..68969674b 100644
--- a/decidim-templates/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb
+++ b/decidim-templates/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb
@@ -6,12 +6,10 @@ module Decidim
       # Controller that allows managing templates.
       #
       class QuestionnaireTemplatesController < Decidim::Templates::Admin::ApplicationController
         include Decidim::TranslatableAttributes
 
-        skip_before_action :verify_authenticity_token, only: :preview
-
         helper_method :template
 
         def index
           enforce_permission_to :index, :templates
           @templates = collection
diff --git a/decidim-templates/app/packs/src/decidim/templates/admin/choose_template.js b/decidim-templates/app/packs/src/decidim/templates/admin/choose_template.js
index a363914c4..45299162b 100644
--- a/decidim-templates/app/packs/src/decidim/templates/admin/choose_template.js
+++ b/decidim-templates/app/packs/src/decidim/templates/admin/choose_template.js
@@ -11,20 +11,14 @@ $(() => {
     const previewURL = options.previewurl;
     if (!previewURL) {
       return;
     }
     const params = new URLSearchParams({ id: id });
-    fetch(`${previewURL}?${params.toString()}`, {
-      method: "GET",
-      headers: { "Content-Type": "application/json" }
-    }).then((response) => response.text()).then((data) => {
-      const script = document.createElement("script");
-      script.type = "text/javascript";
-      script.innerHTML = data;
-      document.getElementsByTagName("head")[0].appendChild(script);
-    }).catch((error) => {
-      console.error(error); // eslint-disable-line no-console
+    Rails.ajax({
+      url: `${previewURL}?${params.toString()}`,
+      type: "GET",
+      error: (data) => (console.error(data))
     });
   }
 
   datalistSelect(wrapper, preview)
 })

Vulnerable code:         skip_before_action :verify_authenticity_token, only: :preview

    fetch(`${previewURL}?${params.toString()}`, {
      method: "GET",
      headers: { "Content-Type": "application/json" }
    }).then((response) => response.text()).then((data) => {
      const script = document.createElement("script");
      script.type = "text/javascript";
      script.innerHTML = data;
      document.getElementsByTagName("head")[0].appendChild(script);
    }).catch((error) => {
      console.error(error); // eslint-disable-line no-console
Fixed code:     Rails.ajax({
      url: `${previewURL}?${params.toString()}`,
      type: "GET",
      error: (data) => (console.error(data))