Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/webp-express/lib/classes/ConvertHelperIndependent.php
+++ b/webp-express/lib/classes/ConvertHelperIndependent.php
@@ -571,7 +571,7 @@
$text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
// TODO: Put version number somewhere else. Ie WebPExpressVersionNumber::version
- $text = 'WebP Express 0.25.15. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "nrnr" . $text;
+ $text = 'WebP Express 0.25.16. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "nrnr" . $text;
$logFile = self::getLogFilename($source, $logDir);
--- a/webp-express/vendor/composer/installed.php
+++ b/webp-express/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'rosell-dk/webp-express',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => '9637ca4242e885f3d44b1382db5409fec8d5919d',
+ 'reference' => 'b5aba85e45f5c3a40987de3c96f1cbe43f8e99d5',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -29,9 +29,9 @@
'dev_requirement' => false,
),
'rosell-dk/dom-util-for-webp' => array(
- 'pretty_version' => '0.7.1',
- 'version' => '0.7.1.0',
- 'reference' => '4f9102e404ee137a781c8580b829a340c5a5d428',
+ 'pretty_version' => '0.7.2',
+ 'version' => '0.7.2.0',
+ 'reference' => 'a69c667eb7a2449e402147586d3863d932f3f660',
'type' => 'library',
'install_path' => __DIR__ . '/../rosell-dk/dom-util-for-webp',
'aliases' => array(),
@@ -112,7 +112,7 @@
'rosell-dk/webp-express' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => '9637ca4242e885f3d44b1382db5409fec8d5919d',
+ 'reference' => 'b5aba85e45f5c3a40987de3c96f1cbe43f8e99d5',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
--- a/webp-express/vendor/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php
+++ b/webp-express/vendor/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php
@@ -179,6 +179,23 @@
return '';
}
+ // The parser (simple_html_dom) lifts content out of the HTML (script, style, code, comments,
+ // CDATA, PHP tags...) and leaves placeholders starting with "___noise___" in its place. It
+ // restores them later, in text and in attribute values, without escaping, and it keeps
+ // expanding until no marker is left.
+ //
+ // Input that contains the marker, or that ends in the start of it right before something the
+ // parser replaces with a placeholder (ie "___noise<![CDATA[x]]>"), breaks that assumption:
+ // - an attacker can make the parser restore a <code> body into an attribute value, which
+ // breaks out of the quotes (stored XSS via comments)
+ // - a marker that cannot be resolved makes restore_noise() loop forever (denial of service)
+ //
+ // Real pages never contain "___noise", so leave such HTML untouched rather than risk it.
+ // This check mitigates the vulnerability discovered by Jakub Herman
+ if (stripos($html, '___noise') !== false) {
+ return $html;
+ }
+
// https://stackoverflow.com/questions/4812691/preserve-line-breaks-simple-html-dom-parser
// function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET,
--- a/webp-express/vendor/rosell-dk/webp-convert-cloud-service/src/AccessCheck.php
+++ b/webp-express/vendor/rosell-dk/webp-convert-cloud-service/src/AccessCheck.php
@@ -46,27 +46,53 @@
}
if (isset($_POST['salt']) && isset($_POST['api-key-crypted'])) {
- if (CRYPT_BLOWFISH == 1) {
- // Strip off the first 28 characters (the first 6 are always "$2y$10$". The next 22 is the salt)
- $cryptedKey = substr(crypt($whitelistItem['api-key'], '$2y$10$' . $_POST['salt'] . '$'), 28);
- if ($_POST['api-key-crypted'] == $cryptedKey) {
- // Access granted!
- return;
- }
- } else {
- // trouble...
- }
- } else {
+ if (CRYPT_BLOWFISH == 1) {
+ $salt = $_POST['salt'];
+ $apiKeyCrypted = $_POST['api-key-crypted'];
+
+ // Step 1: salt must be exactly 22 bcrypt-alphabet characters
+ if (!is_string($salt) || !preg_match('/^[./0-9A-Za-z]{22}$/D', $salt)) {
+ continue;
+ }
+
+ // Step 2a: the submitted crypted key must be a non-empty string
+ if (!is_string($apiKeyCrypted) || $apiKeyCrypted === '') {
+ continue;
+ }
+
+ $fullHash = crypt($whitelistItem['api-key'], '$2y$10$' . $salt . '$');
+
+ // Step 2b: crypt() must have returned a genuine bcrypt hash.
+ // (On failure it returns "*0" or "*1")
+ if (!is_string($fullHash) || strlen($fullHash) !== 60 || strpos($fullHash, '$2y$10$') !== 0) {
+ continue;
+ }
+
+ // Strip off the first 28 characters (7 for "$2y$10$", then the 22-char salt)
+ $cryptedKey = substr($fullHash, 28);
+ if (hash_equals($cryptedKey, $apiKeyCrypted)) {
+ // Access granted!
+ return;
+ }
+ } else {
+ // crypt_blowfish not available, access cannot be granted
+ // we fail silently
+ }
+ } else {
$hashingRequired = (
isset($whitelistItem['require-api-key-to-be-crypted-in-transfer']) &&
$whitelistItem['require-api-key-to-be-crypted-in-transfer']
);
if (!$hashingRequired && isset($_POST['api-key'])) {
- if ($_POST['api-key'] == $whitelistItem['api-key']) {
- // Access granted!
- return;
- }
- }
+ if (
+ is_string($_POST['api-key']) &&
+ is_string($whitelistItem['api-key']) &&
+ hash_equals($whitelistItem['api-key'], $_POST['api-key'])
+ ) {
+ // Access granted!
+ return;
+ }
+ }
}
}
}
--- a/webp-express/vendor/rosell-dk/webp-convert-cloud-service/src/Serve.php
+++ b/webp-express/vendor/rosell-dk/webp-convert-cloud-service/src/Serve.php
@@ -119,16 +119,24 @@
}
try {
- WebPConvert::convert($source, $destination, $convertOptions);
- header('Content-type: application/octet-stream');
- echo file_get_contents($destination);
-
- unlink($source);
- unlink($destination);
+ WebPConvert::convert($source, $destination, $convertOptions);
+ header('Content-type: application/octet-stream');
+ echo file_get_contents($destination);
} catch (Exception $e) {
- echo 'Conversion failed!';
- echo $e->getMessage();
- }
+ echo 'Conversion failed!';
+ //echo $e->getMessage(); // disabled, in order to be sure we dont leak server paths. TODO: provide a safe alternative
+ } finally {
+ // Always remove the uploaded file and any partial output,
+ // whether conversion succeeded, failed, or threw something
+ // other than Exception (e.g. a Throwable/Error on PHP 7+).
+ if (file_exists($source)) {
+ @unlink($source);
+ }
+ if (file_exists($destination)) {
+ @unlink($destination);
+ }
+ }
+
} else {
// Possible file upload attack!
self::configurationError('Failed to move uploaded file');
--- a/webp-express/webp-express.php
+++ b/webp-express/webp-express.php
@@ -3,7 +3,7 @@
* Plugin Name: WebP Express
* Plugin URI: https://github.com/rosell-dk/webp-express
* Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
- * Version: 0.25.15
+ * Version: 0.25.16
* Author: Bjørn Rosell
* Author URI: https://www.bitwise-it.dk
* License: GPL2