CVE-2023-30607 (published 2023-07-05T18:15Z)

icingaweb2-module-jira provides integration with Atlassian Jira. Starting in version 1.3.0 and prior to version 1.3.2, template and field configuration forms perform the deletion action before user input is validated, including the cross site request forgery token. This issue is fixed in version 1.3.2. There are no known workarounds.

CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-352
cwe_name: Cross-Site Request Forgery (CSRF)
description: The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request.
extended_description: When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in exposure of data or unintended code execution.
         

Fix information:
repo_url: https://github.com/Icinga/icingaweb2-module-jira
commit_details: repo_url: https://github.com/Icinga/icingaweb2-module-jira
author: raviks789
author_date: 2023-04-18 11:28:46+02:00
msg: Do not perform deletion before user input is validated in `FieldConfigForm` and `TemplateConfigForm`

This fixes susceptibility to CSRF attacks.
repository: repo_url: https://github.com/Icinga/icingaweb2-module-jira
repo_name: Icinga/icingaweb2-module-jira
repo_language: PHP
owner: Icinga
file_changes: filename: FieldConfigForm.php
change_type: ModificationType.MODIFY
diff: @@ -31,9 +31,6 @@ class FieldConfigForm extends CompatForm
     /** @var string */
     protected $templateName;
 
-    /** @var bool Hack used for delete button */
-    protected $callOnSuccess;
-
     /** @var string */
     protected $fieldId;
 
@@ -47,8 +44,9 @@ class FieldConfigForm extends CompatForm
         $this->templateName = $templateName;
 
         if ($fieldId !== null) {
+            // obtain field key in case the fieldId is field label
             if (! array_key_exists($fieldId, $this->fields)) {
-                $this->fieldId = array_search($fieldId, $this->fields);
+                $this->fieldId = array_search($fieldId, $this->fields) ?: $fieldId;
             } else {
                 $this->fieldId = $fieldId;
             }
@@ -118,6 +116,7 @@ class FieldConfigForm extends CompatForm
                     'Callback' => function ($value, $validator) {
                         /** @var CallbackValidator $validator */
                         $templateFieldKeys = $this->templateConfig->getSection($this->templateName)->keys();
+
                         $selected = $this->fields[$value];
 
                         if (
@@ -337,23 +336,31 @@ class FieldConfigForm extends CompatForm
             $this->getElement('submit')
                 ->getWrapper()
                 ->prepend($deleteButton);
+        }
+    }
 
-            if ($deleteButton->hasBeenPressed()) {
-                $templateFields =  $this->templateConfig->getSection($this->templateName)->toArray();
-
-                $field = isset($templateFields[$this->fieldId]) ? $this->fieldId : $this->fields[$this->fieldId];
-
-                unset($templateFields[$field]);
+    public function hasBeenSubmitted()
+    {
+        if ($this->getPressedSubmitElement() !== null && $this->getPressedSubmitElement()->getName() === 'delete') {
+            return true;
+        }
 
-                $this->templateConfig->setSection($this->templateName, $templateFields);
-                $this->templateConfig->saveIni();
-                $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel());
+        return parent::hasBeenSubmitted();
+    }
 
-                $this->callOnSuccess = false;
+    public function isValid()
+    {
+        if ($this->getPressedSubmitElement()->getName() === 'delete') {
+            $csrfElement = $this->getElement('CSRFToken');
 
-                return;
+            if (! $csrfElement->isValid()) {
+                return false;
             }
+
+            return true;
         }
+
+        return parent::isValid();
     }
 
     /**
@@ -375,8 +382,15 @@ class FieldConfigForm extends CompatForm
 
     public function onSuccess()
     {
-        if ($this->callOnSuccess === false) {
-            $this->getPressedSubmitElement()->setValue($this->getElement('delete')->getLabel());
+        if ($this->getPressedSubmitElement()->getName() === 'delete') {
+            $templateFields =  $this->templateConfig->getSection($this->templateName)->toArray();
+
+            $field = isset($templateFields[$this->fieldId]) ? $this->fieldId : $this->fields[$this->fieldId];
+
+            unset($templateFields[$field]);
+
+            $this->templateConfig->setSection($this->templateName, $templateFields);
+            $this->templateConfig->saveIni();
 
             return;
         }

programming_language: PHP
filename: TemplateConfigForm.php
change_type: ModificationType.MODIFY
diff: @@ -21,9 +21,6 @@ class TemplateConfigForm extends CompatForm
     /** @var string|null */
     protected $templateName;
 
-    /** @var bool Hack used for delete button */
-    protected $callOnSuccess;
-
     public function __construct($templateName = null)
     {
         $this->config = Config::module('jira', 'templates');
@@ -84,25 +81,42 @@ class TemplateConfigForm extends CompatForm
             );
 
             $this->registerElement($deleteButton);
-            $this->getElement('submit')->getWrapper()->prepend($deleteButton);
+            $this->getElement('submit')
+                ->getWrapper()
+                ->prepend($deleteButton);
+        }
+    }
 
-            if ($deleteButton->hasBeenPressed()) {
-                $this->config->removeSection($this->templateName);
-                $this->config->saveIni();
+    public function hasBeenSubmitted()
+    {
+        if ($this->getPressedSubmitElement() !== null && $this->getPressedSubmitElement()->getName() === 'delete') {
+            return true;
+        }
 
-                // Stupid cheat because ipl/html is not capable of multiple submit buttons
-                $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel());
-                $this->callOnSuccess = false;
+        return parent::hasBeenSubmitted();
+    }
 
-                return;
+    public function isValid()
+    {
+        if ($this->getPressedSubmitElement()->getName() === 'delete') {
+            $csrfElement = $this->getElement('CSRFToken');
+
+            if (! $csrfElement->isValid()) {
+                return false;
             }
+
+            return true;
         }
+
+        return parent::isValid();
     }
 
     public function onSuccess()
     {
-        if ($this->callOnSuccess === false) {
-            $this->getSubmitButton()->setValue($this->getElement('delete')->getButtonLabel());
+        if ($this->getPressedSubmitElement()->getName() === 'delete') {
+            $this->config->removeSection($this->templateName);
+            $this->config->saveIni();
+
             return;
         }
 

programming_language: PHP