CVE-2006-10001: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: A vulnerability, which was classified as problematic, was found in Subscribe to Comments Plugin up to 2.0.7 on WordPress. This affects an unknown part of the file subscribe-to-comments.php. The manipulation leads to cross site scripting. It is possible to initiate the attack remotely. Upgrading to version 2.0.8 is able to address this issue. The identifier of the patch is 9683bdf462fcac2f32b33be98f0b96497fbd1bb6. It is recommended to upgrade the affected component. The identifier VDB-222321 was assigned to this vulnerability.
CWE description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
CVSS v3 base score: 5.4
Published: 2023-03-05T21:15Z
Repository: https://github.com/wp-plugins/subscribe-to-comments
Language: PHP
Files changed: subscribe-to-comments.php
Commit date: 2006-09-17 06:38:32 +0000
Commit message: version 2.0.8, XSS fix thanks to MustLive, more fixes for addresses with + symbols

git-svn-id: https://plugins.svn.wordpress.org/subscribe-to-comments/trunk@6401 b8457f37-d9ea-0310-8a92-e5e31aec5664

Diff: diff --git a/subscribe-to-comments.php b/subscribe-to-comments.php
index 1aa6ba0..a66b4f2 100644
--- a/subscribe-to-comments.php
+++ b/subscribe-to-comments.php
@@ -1,9 +1,9 @@
 <?php
 /*
 Plugin Name: Subscribe To Comments
-Version: 2.0.7
+Version: 2.0.8
 Plugin URI: http://txfx.net/code/wordpress/subscribe-to-comments/
 Description: Allows readers to recieve notifications of new comments that are posted to an entry.  Based on version 1 from <a href="http://scriptygoddess.com/">Scriptygoddess</a>
 Author: Mark Jaquith
 Author URI: http://txfx.net/
 */
@@ -85,14 +85,14 @@ if ( !$sg_subscribe->current_viewer_subscription_status() ) :
 
 <?php /* ------------------------------------------------------------------- */ ?>
 <?php /* This is the text that is displayed for users who are NOT subscribed */ ?>
 <?php /* ------------------------------------------------------------------- */ ?>
 
-	<form action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ?>" method="post">
+	<form action="http://<?php echo $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI']); ?>" method="post">
 	<input type="hidden" name="solo-comment-subscribe" value="solo-comment-subscribe" />
 	<input type="hidden" name="postid" value="<?php echo $id; ?>" />
-	<input type="hidden" name="ref" value="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" />
+	<input type="hidden" name="ref" value="<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI'])); ?>" />
 
 	<p class="solo-subscribe-to-comments">
 	<?php _e('Subscribe without commenting', 'subscribe-to-comments'); ?>
 	<br />
 	<label for="solo-subscribe-email"><?php _e('E-Mail:', 'subscribe-to-comments'); ?>
@@ -289,13 +289,18 @@ class sg_subscribe {
 			$this->footer = str_replace('[theme_path]', get_template_directory(), stripslashes($this->settings['footer']));
 			$this->before_manager = stripslashes($this->settings['before_manager']);
 			$this->after_manager = stripslashes($this->settings['after_manager']);
 		}
 
+		// version 2.0.8 -- allow plugin file to be renamed or placed in a subdirectory
+		if ( 'edit.php?page=subscribe-to-comments.php' == $this->form_action )
+			$this->form_action = 'edit.php?page=' . STC_PLUGIN_BASENAME;
+
+
 		foreach (array('email', 'key', 'ref', 'new_email') as $var) {
 			if ( isset($_REQUEST[$var]) && !empty($_REQUEST[$var]) )
-				$this->{$var} = trim($_REQUEST[$var]);
+				$this->{$var} = wp_specialchars(trim($_REQUEST[$var]));
 		}
 		if ( !$this->key )
 			$this->key = 'unset';
 	}
 
@@ -637,11 +642,11 @@ class sg_subscribe {
 			return false;
 
 		$subject = __('E-mail change confirmation', 'subscribe-to-comments');
 		$message = sprintf(__("You are receiving this message to confirm a change of e-mail address for your subscriptions at \"%s\"\n\n", 'subscribe-to-comments'), get_bloginfo('blogname'));
 		$message .= sprintf(__("To change your e-mail address to %s, click this link:\n\n", 'subscribe-to-comments'), $this->new_email);
-		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . $this->email . "&new_email=" . $this->new_email . "&key=" . $this->generate_key($this->email . $this->new_email) . ".\n\n";
+		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . urlencode($this->email) . "&new_email=" . urlencode($this->new_email) . "&key=" . $this->generate_key($this->email . $this->new_email) . ".\n\n";
 		$message .= __('If you did not request this action, please disregard this message.', 'subscribe-to-comments');
 		return $this->send_mail($this->email, $subject, $message);
 	}
 
 
@@ -649,11 +654,11 @@ class sg_subscribe {
 		if ( $this->is_blocked($email) )
 			return false;
 		$subject = __('E-mail block confirmation', 'subscribe-to-comments');
 		$message = sprintf(__("You are receiving this message to confirm that you no longer wish to receive e-mail comment notifications from \"%s\"\n\n", 'subscribe-to-comments'), get_bloginfo('name'));
 		$message .= __("To cancel all future notifications for this address, click this link:\n\n", 'subscribe-to-comments');
-		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . $email . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";
+		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . urlencode($email) . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";
 		$message .= __("If you did not request this action, please disregard this message.", 'subscribe-to-comments');
 		return $this->send_mail($email, $subject, $message);
 	}
 
 
@@ -750,24 +755,24 @@ class sg_subscribe {
 
 		$post_author = get_userdata($post->post_author);
 		if ( strtolower($post_author->user_email) == $email && $loggedin )
 			return 'admin';
 
-
 		if ( is_array($this->subscriptions_from_email($email)) )
 			if ( in_array($post->ID, $this->email_subscriptions) ) return $email;
 		return false;
 	}
 
 
 	function manage_link($email='', $html=true, $echo=true) {
 		$link  = get_bloginfo('wpurl') . '/wp-subscription-manager.php';
 		if ( $email != 'admin' ) {
-			$link = add_query_arg('email', urlencode($email), $link);
+			$link = add_query_arg('email', urlencode(urlencode($email)), $link);
 			$link = add_query_arg('key', $this->generate_key($email), $link);
 		}
-		$link = add_query_arg('ref', urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), $link);
+		$link = add_query_arg('ref', urlencode('http://' . $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI'])), $link);
+		$link = str_replace('+', '%2B', $link);
 		if ( $html )
 			$link = htmlentities($link);
 		if ( !$echo )
 			return $link;
 		echo $link;
@@ -827,6 +832,9 @@ add_action('admin_head', create_function('$a', 'global $sg_subscribe; sg_subscri
 add_action('init', create_function('$a','global $sg_subscribe; if ( $_POST[\'solo-comment-subscribe\'] == \'solo-comment-subscribe\' && is_numeric($_POST[\'postid\']) ) {
 	sg_subscribe_start();
 	$sg_subscribe->solo_subscribe($_POST[\'email\'], $_POST[\'postid\']);
 }')
 );
+
+define('STC_PLUGIN_BASENAME', plugin_basename(__FILE__));
+
 ?>
\ No newline at end of file

Vulnerable code: Version: 2.0.7
	<form action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ?>" method="post">
	<input type="hidden" name="ref" value="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" />
				$this->{$var} = trim($_REQUEST[$var]);
		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . $this->email . "&new_email=" . $this->new_email . "&key=" . $this->generate_key($this->email . $this->new_email) . ".\n\n";
		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . $email . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";

			$link = add_query_arg('email', urlencode($email), $link);
		$link = add_query_arg('ref', urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), $link);
Fixed code: Version: 2.0.8
	<form action="http://<?php echo $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI']); ?>" method="post">
	<input type="hidden" name="ref" value="<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI'])); ?>" />
		// version 2.0.8 -- allow plugin file to be renamed or placed in a subdirectory
		if ( 'edit.php?page=subscribe-to-comments.php' == $this->form_action )
			$this->form_action = 'edit.php?page=' . STC_PLUGIN_BASENAME;


				$this->{$var} = wp_specialchars(trim($_REQUEST[$var]));
		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . urlencode($this->email) . "&new_email=" . urlencode($this->new_email) . "&key=" . $this->generate_key($this->email . $this->new_email) . ".\n\n";
		$message .= get_bloginfo('wpurl') . "/wp-subscription-manager.php?email=" . urlencode($email) . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";
			$link = add_query_arg('email', urlencode(urlencode($email)), $link);
		$link = add_query_arg('ref', urlencode('http://' . $_SERVER['HTTP_HOST'] . wp_specialchars($_SERVER['REQUEST_URI'])), $link);
		$link = str_replace('+', '%2B', $link);

define('STC_PLUGIN_BASENAME', plugin_basename(__FILE__));