CVE-2017-20183: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: A vulnerability was found in External Media without Import Plugin up to 1.0.0 on WordPress. It has been declared as problematic. This vulnerability affects the function print_media_new_panel of the file external-media-without-import.php. The manipulation of the argument url/error/width/height/mime-type leads to cross site scripting. The attack can be initiated remotely. Upgrading to version 1.0.1 is able to address this issue. The patch is identified as 9d2ecd159a6e2e3f710b4f1c28e2714f66502746. It is recommended to upgrade the affected component. VDB-227950 is the identifier 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: 6.1
Published: 2023-05-05T01:15Z
Repository: https://github.com/zzxiang/external-media-without-import
Language: PHP
Files changed: external-media-without-import.php
Commit date: 2017-10-15 15:37:08 +0000
Commit message: Fixed XSS Security Vulnerabilities and bug with mime types including '+'.

See also: http://php.net/urldecode#refsect1-function.urldecode-notes

git-svn-id: https://plugins.svn.wordpress.org/external-media-without-import/trunk@1746853 b8457f37-d9ea-0310-8a92-e5e31aec5664

Diff: diff --git a/external-media-without-import.php b/external-media-without-import.php
index c095eb9..0dfc299 100644
--- a/external-media-without-import.php
+++ b/external-media-without-import.php
@@ -86,25 +86,25 @@ function print_media_new_panel( $is_in_upload_ui ) {
 ?>
 	<div id="emwi-media-new-panel" <?php if ( $is_in_upload_ui  ) : ?>style="display: none"<?php endif; ?>>
 	  <div class="url-row">
 		<label><?php echo __('Add a media from URL'); ?></label>
 		<span id="emwi-url-input-wrapper">
-		  <input id="emwi-url" name="url" type="url" required placeholder="<?php echo __('Image URL');?>" value="<?php echo urldecode( $_GET['url'] ); ?>">
+		  <input id="emwi-url" name="url" type="url" required placeholder="<?php echo __('Image URL');?>" value="<?php echo esc_url( $_GET['url'] ); ?>">
 		</span>
 	  </div>
 	  <div id="emwi-hidden" <?php if ( $is_in_upload_ui || empty( $_GET['error'] ) ) : ?>style="display: none"<?php endif; ?>>
 		<div>
-		  <span id="emwi-error"><?php echo urldecode( $_GET['error'] ); ?></span>
+		  <span id="emwi-error"><?php echo esc_html( $_GET['error'] ); ?></span>
 		  <?php echo _('Please fill in the following properties manually. If you leave the fields blank (or 0 for width/height), the plugin will try to resolve them automatically'); ?>
 		</div>
 		<div id="emwi-properties">
 		  <label><?php echo __('Width'); ?></label>
-		  <input id="emwi-width" name="width" type="number" value="<?php echo urldecode( $_GET['width'] ); ?>">
+		  <input id="emwi-width" name="width" type="number" value="<?php echo esc_html( $_GET['width'] ); ?>">
 		  <label><?php echo __('Height'); ?></label>
-		  <input id="emwi-height" name="height" type="number" value="<?php echo urldecode( $_GET['height'] ); ?>">
+		  <input id="emwi-height" name="height" type="number" value="<?php echo esc_html( $_GET['height'] ); ?>">
 		  <label><?php echo __('MIME Type'); ?></label>
-		  <input id="emwi-mime-type" name="mime-type" type="text" value="<?php echo urldecode( $_GET['mime-type'] ); ?>">
+		  <input id="emwi-mime-type" name="mime-type" type="text" value="<?php echo esc_html( $_GET['mime-type'] ); ?>">
 		</div>
 	  </div>
 	  <div id="emwi-buttons-row">
 		<input type="hidden" name="action" value="add_external_media_without_import">
 		<span class="spinner"></span>

Vulnerable code: 		  <input id="emwi-url" name="url" type="url" required placeholder="<?php echo __('Image URL');?>" value="<?php echo urldecode( $_GET['url'] ); ?>">
		  <span id="emwi-error"><?php echo urldecode( $_GET['error'] ); ?></span>
		  <input id="emwi-width" name="width" type="number" value="<?php echo urldecode( $_GET['width'] ); ?>">
		  <input id="emwi-height" name="height" type="number" value="<?php echo urldecode( $_GET['height'] ); ?>">
		  <input id="emwi-mime-type" name="mime-type" type="text" value="<?php echo urldecode( $_GET['mime-type'] ); ?>">
Fixed code: 		  <input id="emwi-url" name="url" type="url" required placeholder="<?php echo __('Image URL');?>" value="<?php echo esc_url( $_GET['url'] ); ?>">
		  <span id="emwi-error"><?php echo esc_html( $_GET['error'] ); ?></span>
		  <input id="emwi-width" name="width" type="number" value="<?php echo esc_html( $_GET['width'] ); ?>">
		  <input id="emwi-height" name="height" type="number" value="<?php echo esc_html( $_GET['height'] ); ?>">
		  <input id="emwi-mime-type" name="mime-type" type="text" value="<?php echo esc_html( $_GET['mime-type'] ); ?>">