Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/unbounce/UBConfig.php
+++ b/unbounce/UBConfig.php
@@ -7,8 +7,8 @@
const UB_PLUGIN_NAME = 'ub-wordpress';
const UB_CACHE_TIMEOUT_ENV_KEY = 'UB_WP_ROUTES_CACHE_EXP';
- const UB_USER_AGENT = 'Unbounce WP Plugin 1.1.6';
- const UB_VERSION = '1.1.6';
+ const UB_USER_AGENT = 'Unbounce WP Plugin 1.1.7';
+ const UB_VERSION = '1.1.7';
// WP Admin Pages
const UB_ADMIN_PAGE_MAIN = 'unbounce-pages';
--- a/unbounce/UBDiagnostics.php
+++ b/unbounce/UBDiagnostics.php
@@ -127,7 +127,7 @@
return array(
'PHP Version' => phpversion(),
'WordPress Version' => UBDiagnostics::wordpress_version(),
- 'Unbounce Plugin Version' => '1.1.6',
+ 'Unbounce Plugin Version' => '1.1.7',
'Checks' => self::pp(UBDiagnostics::checks($domain, $domain_info)),
'Options' => self::pp(UBDiagnostics::ub_options()),
'Permalink Structure' => get_option('permalink_structure', ''),
@@ -205,7 +205,7 @@
return array(
'php' => phpversion(),
'wordpress' => UBDiagnostics::wordpress_version(),
- 'plugin_version' => '1.1.6',
+ 'plugin_version' => '1.1.7',
'curl_installed' => self::is_curl_installed(),
'xml_installed' => self::is_xml_installed(),
'sni_support' => self::has_sni(),
--- a/unbounce/UBHTTP.php
+++ b/unbounce/UBHTTP.php
@@ -59,11 +59,7 @@
$join_cookie_values = function ($k, $v) {
return $k . '=' . $v;
};
- $cookie_strings = array_map(
- $join_cookie_values,
- array_keys($cookies),
- $cookies
- );
+ $cookie_strings = array_map($join_cookie_values, array_keys($cookies), $cookies);
return join('; ', $cookie_strings);
}
@@ -171,15 +167,8 @@
public static function determine_protocol($server_global, $wp_is_ssl)
{
$forwarded_proto = UBUtil::array_fetch($server_global, 'HTTP_X_FORWARDED_PROTO');
- $first_valid_forwarded_proto = UBUtil::array_fetch(
- array_values(
- array_filter(
- UBHTTP::split_header_values($forwarded_proto),
- array('UBHTTP', 'is_valid_protocol')
- )
- ),
- 0
- );
+ $valid_forwarded_protos = array_filter(UBHTTP::split_header_values($forwarded_proto), array('UBHTTP', 'is_valid_protocol'));
+ $first_valid_forwarded_proto = UBUtil::array_fetch(array_values($valid_forwarded_protos), 0);
$request_scheme = UBUtil::array_fetch($server_global, 'REQUEST_SCHEME');
$script_uri = UBUtil::array_fetch($server_global, 'SCRIPT_URI');
@@ -282,7 +271,7 @@
$resp = wp_remote_request($target_url, $args);
if (is_wp_error($resp)) {
- $message = "Error proxying to '" . $target_url . "': " . $resp->get_error_message();
+ $message = UBHTTP::proxy_error_message($target_url, $resp->get_error_message());
UBLogger::warning($message);
http_response_code(500);
return array(false, $message);
@@ -359,7 +348,7 @@
{
$headers = array(
'host' => UBConfig::page_server_domain(),
- 'x-ub-wordpress-plugin-version' => '1.1.6'
+ 'x-ub-wordpress-plugin-version' => '1.1.7'
);
try {
@@ -479,7 +468,10 @@
curl_setopt_array($curl, $curl_options);
$resp = curl_exec($curl);
if (!$resp) {
- $message = "Error proxying to '" . $target_url . "': " . curl_error($curl) . " - Code: " . curl_errno($curl);
+ $message = UBHTTP::proxy_error_message(
+ $target_url,
+ curl_error($curl) . " - Code: " . curl_errno($curl)
+ );
UBLogger::warning($message);
if (UBHTTP::is_location_response_header_set()) {
UBLogger::debug("The location header was set despite the cURL error. Assuming it's safe to let the response flow back");
@@ -566,6 +558,45 @@
);
}
+ /**
+ * The message for a failed proxy request. It is stored in the
+ * ub-proxy-error-message option and shown on the Diagnostics page, so it
+ * must not carry the visitor's query string: the target URL is the page
+ * server plus the raw REQUEST_URI, and an anonymous visitor controls the
+ * query string, so markup placed there was stored and then ran in the
+ * admin's session when they opened Diagnostics (BD-13834).
+ *
+ * The path is kept because it says which page failed, which is what
+ * support uses the message for. The Diagnostics page escapes it on output
+ * anyway; dropping the query string means the most convenient place to
+ * put a payload is never stored.
+ *
+ * Control characters and non-ASCII bytes in the path are percent-encoded.
+ * REQUEST_URI is raw, so a visitor can send a byte that is not valid
+ * UTF-8, and esc_textarea() returns '' for invalid UTF-8, which would
+ * blank the whole Options entry on the Diagnostics page.
+ */
+ public static function proxy_error_message($target_url, $detail)
+ {
+ $url_without_query = preg_replace('/[?#].*$/s', '', (string) $target_url);
+ $percent_encode = function ($byte) {
+ return rawurlencode($byte[0]);
+ };
+ $printable_url = preg_replace_callback('/[x00-x20x7F-xFF]/', $percent_encode, $url_without_query);
+ return "Error proxying to '" . $printable_url . "': " . $detail;
+ }
+
+ /**
+ * True when a request target is an origin-form path ("/..."), the only form
+ * the proxy can safely append to the page-server URL. Absolute-form
+ * ("http:/...", "http://host/...") and anything else would be read by curl
+ * as part of the host or scheme.
+ */
+ public static function is_origin_form_path($request_uri)
+ {
+ return is_string($request_uri) && strpos($request_uri, '/') === 0 && strpos($request_uri, '//') !== 0;
+ }
+
public static function get_url_purpose($proxyable_url_set, $http_method, $url)
{
$host = parse_url($url, PHP_URL_HOST);
--- a/unbounce/Unbounce-Page.php
+++ b/unbounce/Unbounce-Page.php
@@ -3,7 +3,7 @@
Plugin Name: Unbounce Landing Pages
Plugin URI: http://unbounce.com
Description: Unbounce is the most powerful standalone landing page builder available.
-Version: 1.1.6
+Version: 1.1.7
Author: Unbounce
Author URI: http://unbounce.com
License: GPLv2
@@ -55,6 +55,16 @@
$current_protocol = UBHTTP::get_current_protocol($_SERVER, is_ssl());
$current_method = UBUtil::array_fetch($_SERVER, 'REQUEST_METHOD');
$current_path = UBUtil::array_fetch($_SERVER, 'REQUEST_URI');
+
+ // The target URL is the page server plus this path, so it has to be a path.
+ // Apache accepts a request target such as "http:/_ub/x", which turned the
+ // page-server host into "proxy.unbouncepages.comhttp" and let any visitor
+ // force a failed proxy call carrying their markup (BD-13834).
+ if (!UBHTTP::is_origin_form_path($current_path)) {
+ UBLogger::debug("ignoring request target that is not a path: " . var_export($current_path, true));
+ return;
+ }
+
$current_url = $current_protocol . '://' . $domain . $current_path;
$current_user_agent = UBUtil::array_fetch($_SERVER, 'HTTP_USER_AGENT');
@@ -173,6 +183,14 @@
if (version_compare($saved_version, '1.1.0', '<')) {
update_option(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY, UBConfig::default_page_server_domain());
}
+
+ // Before 1.1.7 the stored proxy error kept the visitor's query string,
+ // which could carry markup into the Diagnostics page (BD-13834). The
+ // page now escapes it, but there is no reason to keep text an
+ // anonymous visitor chose, so installs upgrading past the fix drop it.
+ if (version_compare($saved_version, '1.1.7', '<')) {
+ update_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, '', false);
+ }
}
UBUtil::clear_flash();
--- a/unbounce/templates/authorize_button.php
+++ b/unbounce/templates/authorize_button.php
@@ -6,7 +6,7 @@
<input type="hidden" name="domain_uuid" />
<input type="hidden" name="client_id" />
<?php if (isset($outer_text)) { ?>
- <?php echo $outer_text; ?>
+ <?php echo esc_html($outer_text); ?>
<?php } ?>
<?php $style = isset($outer_text) ? 'vertical-align: baseline' : ''; ?>
<?php
--- a/unbounce/templates/diagnostics.php
+++ b/unbounce/templates/diagnostics.php
@@ -1,6 +1,6 @@
<?php
-$domain_is_authorized = "<p>The plugin is not able to verify that your domain ({$domain}) is added to your account in Unbounce.</p>
+$domain_is_authorized = "<p>The plugin is not able to verify that your domain (" . esc_html($domain) . ") is added to your account in Unbounce.</p>
<p>Possible causes:</p>
<ul class="causes">
<li>Log in & out of Unbounce. It s possible that your session has expired</li>
@@ -28,7 +28,7 @@
$permalink_structure = "<p>By default WordPress uses web URLs which have question marks and lots of numbers in them; however, this default structure will not work with the Unbounce Plugin. </p>
- <p>Please update your <a href="{$permalink_url}" target="_blank">WordPress Permalink Structure</a> (link to: yourdomain.com/wp-admin/options-permalink) and change to anything other than the default WordPress setting.</p>";
+ <p>Please update your <a href="" . esc_url($permalink_url) . "" target="_blank">WordPress Permalink Structure</a> (link to: yourdomain.com/wp-admin/options-permalink) and change to anything other than the default WordPress setting.</p>";
$supported_php_version = 'The Unbounce Pages plugin is supported when using PHP version 8.0 or higher, please contact your hosting provider or IT professional and update to a supported version.';
@@ -53,6 +53,16 @@
"Domain UUID" => $domain_uuid,
);
+// The descriptions are markup written here, with the only variables escaped
+// where they are interpolated above. wp_kses is the second layer, limited to the
+// tags they actually use rather than everything a post may contain.
+$description_allowed_html = array(
+ 'p' => array(),
+ 'ul' => array('class' => true),
+ 'li' => array(),
+ 'a' => array('href' => true, 'target' => true),
+);
+
?>
<div class="wrap">
@@ -63,12 +73,14 @@
<li>
<span class='dashicons <?php echo $css_class; ?>'></span>
<?php
- echo $check;
+ echo esc_html($check);
if (!$success) {
foreach ($diagnostic_descriptions as $title => $description) {
if ($title == $check) {
- echo '<p class="ub-diagnostics-check-description">' . $description . '</p>';
+ echo '<p class="ub-diagnostics-check-description">'
+ . wp_kses($description, $description_allowed_html)
+ . '</p>';
}
}
}
@@ -119,7 +131,13 @@
<textarea id="ub-diagnostics-text" rows="10" cols="100">
<?php
foreach ($details as $detail_name => $detail) {
- echo "[{$detail_name}] {$detail}n";
+ // Every value is escaped: the dump includes stored options, one of
+ // which (ub-proxy-error-message) is written from public proxy
+ // traffic, and other plugins' header text. A "</textarea>" in any
+ // of them would otherwise end the textarea and inject markup.
+ // Escaping on output also neutralises a value stored before this
+ // fix.
+ echo esc_textarea("[{$detail_name}] {$detail}n");
}
?>
</textarea>
--- a/unbounce/templates/main_authorized_footer.php
+++ b/unbounce/templates/main_authorized_footer.php
@@ -22,4 +22,4 @@
<a class="ub-diagnostics-link" href="<?php echo $diagnostics_url ?>">
Click here for troubleshooting and plugin diagnostics
</a>
-<p class="ub-version">Unbounce Version 1.1.6</p>
+<p class="ub-version">Unbounce Version 1.1.7</p>
--- a/unbounce/templates/main_failed_authorization.php
+++ b/unbounce/templates/main_failed_authorization.php
@@ -1,10 +1,10 @@
<div class="error">
- <p>It looks like <strong><?php echo $domain; ?></strong> has not been added as a WordPress domain
+ <p>It looks like <strong><?php echo esc_html($domain); ?></strong> has not been added as a WordPress domain
in your Unbounce account.</p>
</div>
<form method="get" action="https://app.unbounce.com/add_wordpress_domain" target="_blank">
- <input type="hidden" name="domain_name" value="<?php echo $domain; ?>" />
+ <input type="hidden" name="domain_name" value="<?php echo esc_attr($domain); ?>" />
<?php
get_submit_Button(
--- a/unbounce/templates/main_unauthorized_footer.php
+++ b/unbounce/templates/main_unauthorized_footer.php
@@ -4,4 +4,4 @@
<a class="ub-diagnostics-link" href="<?php echo admin_url('admin.php?page='.UBConfig::UB_ADMIN_PAGE_DIAGNOSTICS); ?>">
Click here for troubleshooting and plugin diagnostics
</a>
-<p class="ub-version">Unbounce Version 1.1.6</p>
+<p class="ub-version">Unbounce Version 1.1.7</p>