CVE-2015-10100 (published 2023-04-10T18:15Z)

A vulnerability, which was classified as critical, has been found in Dynamic Widgets Plugin up to 1.5.10 on WordPress. This issue affects some unknown processing of the file classes/dynwid_class.php. The manipulation leads to sql injection. The attack may be initiated remotely. Upgrading to version 1.5.11 is able to address this issue. The identifier of the patch is d0a19c6efcdc86d7093b369bc9e29a0629e57795. It is recommended to upgrade the affected component. The identifier VDB-225353 was assigned to this vulnerability.

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

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/wp-plugins/dynamic-widgets
commit_details: repo_url: https://github.com/wp-plugins/dynamic-widgets
author: qurl
author_date: 2015-08-14 10:40:56+00:00
msg: Change DB query methods to prevent SQL injection

git-svn-id: https://plugins.svn.wordpress.org/dynamic-widgets/trunk@1220789 b8457f37-d9ea-0310-8a92-e5e31aec5664
repository: repo_url: https://github.com/wp-plugins/dynamic-widgets
repo_name: wp-plugins/dynamic-widgets
description: WordPress.org Plugin Mirror
repo_language: PHP
owner: wp-plugins
file_changes: filename: dynwid_class.php
change_type: ModificationType.MODIFY
diff: @@ -119,18 +119,38 @@
 		 * @param array $dates Dates
 		 */
 		public function addDate($widget_id, $dates) {
+			$fields = array(
+				'widget_id'		=> $widget_id,
+				'maintype'		=> 'date',
+				'name'			=> 'default',
+				'value'			=> '0'
+			);
+			$this->wpdb->insert($this->dbtable, $fields);
+
+			/*
 			$query = "INSERT INTO " . $this->dbtable . "
                     (widget_id, maintype, name, value)
                   VALUES
                     ('" . $widget_id . "', 'date', 'default', '0')";
 			$this->wpdb->query($query);
+			*/
 
 			foreach ( $dates as $name => $date ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> 'date',
+					'name'			=> $name,
+					'value'			=> $date
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
                     (widget_id, maintype, name, value)
                   VALUES
                     ('" . esc_sql($widget_id) . "', 'date', '" . esc_sql($name) . "', '" . esc_sql($date) . "')";
 				$this->wpdb->query($query);
+				*/
 			}
 		}
 
@@ -143,19 +163,40 @@
 		 */
 		public function addIPs($widget_id, $default, $ips) {
 			$value = serialize($ips);
+
 			if ( $default == 'no' ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> 'ip',
+					'name'			=> 'default',
+					'value'			=> '0'
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'ip', 'default', '0')";
 				$this->wpdb->query($query);
+				*/
 			}
 
+			$fields = array(
+				'widget_id'		=> $widget_id,
+				'maintype'		=> 'ip',
+				'name'			=> 'ip',
+				'value'			=> $value
+			);
+			$this->wpdb->insert($this->dbtable, $fields);
+
+			/*
 			$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'ip', 'ip', '" . $value . "')";
 			$this->wpdb->query($query);
+			*/
 		}
 
 		public function addShortcode($widget_id, $default, $value, $match, $operator) {
@@ -163,18 +204,38 @@
 			$value = serialize($value);
 
 			if ( $default == 'no' ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> 'shortcode',
+					'name'			=> 'default',
+					'value'			=> '0'
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'shortcode', 'default', '0')";
 				$this->wpdb->query($query);
+				*/
 			}
 
+			$fields = array(
+				'widget_id'		=> $widget_id,
+				'maintype'		=> 'shortcode',
+				'name'			=> 'shortcode',
+				'value'			=> $value
+			);
+			$this->wpdb->insert($this->dbtable, $fields);
+
+			/*
 			$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'shortcode', 'shortcode', '" . $value . "')";
 			$this->wpdb->query($query);
+			*/
 		}
 
 		/**
@@ -187,18 +248,38 @@
 		public function addUrls($widget_id, $default, $urls) {
 			$value = serialize($urls);
 			if ( $default == 'no' ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> 'url',
+					'name'			=> 'default',
+					'value'			=> '0'
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'url', 'default', '0')";
 				$this->wpdb->query($query);
+				*/
 			}
 
+			$fields = array(
+				'widget_id'		=> $widget_id,
+				'maintype'		=> 'url',
+				'name'			=> 'url',
+				'value'			=> $value
+			);
+			$this->wpdb->insert($this->dbtable, $fields);
+
+			/*
 			$query = "INSERT INTO " . $this->dbtable . "
 										(widget_id, maintype, name, value)
 									VALUES
 										('" . esc_sql($widget_id) . "', 'url', 'url', '" . $value . "')";
 			$this->wpdb->query($query);
+			*/
 		}
 
 		/**
@@ -233,7 +314,8 @@
 			$post_types = array_merge( $types, array('single-post', 'single-tag') );
 
 			if ( in_array($maintype, $post_types) ) {
-				$query = "SELECT COUNT(1) AS total FROM " . $this->dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = '" . $maintype . "' AND name = 'default'";
+				$query = "SELECT COUNT(1) AS total FROM " . $this->dbtable . " WHERE widget_id = %s AND maintype = %s AND name = %s";
+				$query = $this->wpdb->prepare($query, $widget_id, $maintype, 'default');
 				$count = $this->wpdb->get_var($query);
 				if ( $count > 0 ) {
 					$insert = FALSE;
@@ -241,18 +323,38 @@
 			}
 
 			if ( $insert ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> $maintype,
+					'name'			=> 'default',
+					'value'			=> $opt_default
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
                       (widget_id, maintype, name, value)
                     VALUES
                       ('" . esc_sql($widget_id) . "', '" . esc_sql($maintype) . "', 'default', '" . esc_sql($opt_default) . "')";
 				$this->wpdb->query($query);
+				*/
 			}
 			foreach ( $act as $option ) {
+				$fields = array(
+					'widget_id'		=> $widget_id,
+					'maintype'		=> $maintype,
+					'name'			=> $option,
+					'value'			=> $opt_act
+				);
+				$this->wpdb->insert($this->dbtable, $fields);
+
+				/*
 				$query = "INSERT INTO " . $this->dbtable . "
                       (widget_id, maintype, name, value)
                     VALUES
                       ('" . esc_sql($widget_id) . "', '" . esc_sql($maintype) . "', '" . esc_sql($option) . "', '" . esc_sql($opt_act) . "')";
 				$this->wpdb->query($query);
+				*/
 			}
 		}
 
@@ -264,11 +366,20 @@
 		 * @param integer $value Default setting
 		 */
 		public function addSingleOption($widget_id, $maintype, $value = '0') {
+			$fields = array(
+				'widget_id'		=> $widget_id,
+				'maintype'		=> $maintype,
+				'value'			=> $value
+			);
+			$this->wpdb->insert($this->dbtable, $fields);
+
+			/*
 			$query = "INSERT INTO " . $this->dbtable . "
                     (widget_id, maintype, value)
                   VALUES
                     ('" . esc_sql($widget_id) . "', '" . esc_sql($maintype) . "', '" . esc_sql($value) . "')";
 			$this->wpdb->query($query);
+			*/
 		}
 
 		/**
@@ -320,10 +431,14 @@
 		 * @param string $name Name of option
 		 */
 		public function deleteOption($widget_id, $maintype, $name = '') {
-			$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = '" . $widget_id . "' AND maintype = '" . $maintype ."'";
+			$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = %s AND maintype = %s";
 			if (! empty($name) ) {
-				$query .= " AND name = '" . $name . "'";
+				$query .= " AND name = %s";
+				$query = $this->wpdb->prepare($query, $widget_id, $maintype, $name);
+			} else {
+				$query = $this->wpdb->prepare($query, $widget_id, $maintype);
 			}
+
 			$this->wpdb->query($query);
 		}
 
@@ -430,7 +545,7 @@
 			}
 
 			$query = "SELECT DISTINCT widget_id FROM " . $this->dbtable . "
-                     WHERE  maintype LIKE '" . $whereami . "%'";
+                     WHERE  maintype LIKE '" . esc_sql($whereami) . "%'";
 
 			if ( count($this->overrule_maintype) > 0 ) {
 				$query .= " OR maintype IN ";
@@ -489,8 +604,8 @@
 			}
 
 			$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
-                 WHERE widget_id LIKE '" . $widget_id . "'
-                   AND maintype LIKE '" . $maintype . "%'
+                 WHERE widget_id LIKE '" . esc_sql($widget_id) . "'
+                   AND maintype LIKE '" . esc_sql($maintype) . "%'
                  ORDER BY maintype, name";
 			$results = new DWOpts($this->wpdb->get_results($query), $maintype);
 			return $results;
@@ -588,8 +703,8 @@
 
 			if ( $admin ) {
 				$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
-                  WHERE widget_id LIKE '" . $widget_id . "'
-                    AND maintype LIKE '" . $maintype . "%'
+                  WHERE widget_id LIKE '" . esc_sql($widget_id) . "'
+                    AND maintype LIKE '" . esc_sql($maintype) . "%'
                   ORDER BY maintype, name";
 
 			} else {
@@ -597,14 +712,14 @@
 					$maintype = 'page';
 				}
 				$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
-                  WHERE widget_id LIKE '" . $widget_id . "'
-                    AND (maintype LIKE '" . $maintype . "%'";
+                  WHERE widget_id LIKE '" . esc_sql($widget_id) . "'
+                    AND (maintype LIKE '" . esc_sql($maintype) . "%'";
 
 				if ( count($this->overrule_maintype) > 0 ) {
 					$query .= " OR maintype IN (";
 					$q = array();
 					foreach ( $this->overrule_maintype as $omt ) {
-						$q[ ] = "'" . $omt . "'";
+						$q[ ] = "'" . esc_sql($omt) . "'";
 					}
 					$query .= implode(', ', $q);
 					$query .= ")";
@@ -714,8 +829,9 @@
 		 */
 		public function hasOptions($widget_id) {
 			$query = "SELECT COUNT(1) AS total FROM " . $this->dbtable . "
-                  WHERE widget_id = '" . $widget_id . "' AND
-                        maintype != 'individual'";
+                  WHERE widget_id = %s AND
+                        maintype != %s";
+			$query = $this->wpdb->prepare($query, $widget_id, 'individual');
 			$count = $this->wpdb->get_var($query);
 
 			if ( $count > 0 ) {
@@ -895,7 +1011,8 @@
 		 * @param string $widget_id ID of the widget
 		 */
 		public function resetOptions($widget_id) {
-			$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = '" . $widget_id . "'";
+			$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = %s";
+			$query = $this->wpdb->prepare($query, $widget_id);
 			$this->wpdb->query($query);
 		}
 	}

programming_language: PHP