WebP Express - Version 0.14.16

Version Description

(released: 26 jun 2019)

  • Fixed conversion errors using Bulk convert or Test convert on systems with symlinked folders
Download this release

Release Info

Developer rosell.dk
Plugin Icon 128x128 WebP Express
Version 0.14.16
Comparing to
See all releases

Code changes from version 0.14.15 to 0.14.16

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://ko-fi.com/rosell
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
- Stable tag: 0.14.15
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -608,6 +608,11 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
608
 
609
  == Changelog ==
610
 
 
 
 
 
 
611
  = 0.14.15 =
612
  *(released: 26 jun 2019)*
613
 
@@ -886,6 +891,9 @@ For older releases, check out changelog.txt
886
 
887
  == Upgrade Notice ==
888
 
 
 
 
889
  = 0.14.15 =
890
  * Fixed errors with "redirect to conversion script"
891
 
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 0.14.16
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
608
 
609
  == Changelog ==
610
 
611
+ = 0.14.16 =
612
+ *(released: 26 jun 2019)*
613
+
614
+ * Fixed conversion errors using Bulk convert or Test convert on systems with symlinked folders
615
+
616
  = 0.14.15 =
617
  *(released: 26 jun 2019)*
618
 
891
 
892
  == Upgrade Notice ==
893
 
894
+ = 0.14.16 =
895
+ * Fixed more errors on systems with symlinked folders
896
+
897
  = 0.14.15 =
898
  * Fixed errors with "redirect to conversion script"
899
 
lib/classes/Convert.php CHANGED
@@ -32,8 +32,9 @@ class Convert
32
  try {
33
  // Check source
34
  // ---------------
35
- $checking = 'filename';
36
- $filename = SanityCheck::absPathExistsAndIsFileInDocRoot($source);
 
37
  // PS: No need to check mime type as the WebPConvert library does that (it only accepts image/jpeg and image/png)
38
 
39
 
@@ -49,6 +50,7 @@ class Convert
49
 
50
  // Check convert options
51
  // -------------------------------
 
52
  if (is_null($convertOptions)) {
53
  $wodOptions = Config::generateWodOptionsFromConfigObj($config);
54
  if (!isset($wodOptions['webp-convert']['convert'])) {
@@ -63,12 +65,14 @@ class Convert
63
 
64
  // Check destination
65
  // -------------------------------
 
66
  $destination = self::getDestination($source, $config);
67
- $destination = SanityCheck::absPathIsInDocRoot($destination);
68
 
 
69
 
70
  // Check log dir
71
  // -------------------------------
 
72
  $logDir = SanityCheck::absPathIsInDocRoot(Paths::getWebPExpressContentDirAbs() . '/log');
73
 
74
 
@@ -142,7 +146,7 @@ class Convert
142
  $checking = '"filename" argument';
143
  Validate::postHasKey('filename');
144
  $filename = sanitize_text_field($_POST['filename']);
145
- $filename = SanityCheck::absPathExistsAndIsFileInDocRoot($filename);
146
  // PS: No need to check mime version as webp-convert does that.
147
 
148
 
32
  try {
33
  // Check source
34
  // ---------------
35
+ $checking = 'filename!';
36
+ $filename = $source;
37
+ //$filename = SanityCheck::absPathExistsAndIsFileInDocRoot($source);
38
  // PS: No need to check mime type as the WebPConvert library does that (it only accepts image/jpeg and image/png)
39
 
40
 
50
 
51
  // Check convert options
52
  // -------------------------------
53
+ $checking = 'configuration file (options)';
54
  if (is_null($convertOptions)) {
55
  $wodOptions = Config::generateWodOptionsFromConfigObj($config);
56
  if (!isset($wodOptions['webp-convert']['convert'])) {
65
 
66
  // Check destination
67
  // -------------------------------
68
+ $checking = 'destination';
69
  $destination = self::getDestination($source, $config);
 
70
 
71
+ $destination = SanityCheck::absPathIsInDocRoot($destination);
72
 
73
  // Check log dir
74
  // -------------------------------
75
+ $checking = 'conversion log dir';
76
  $logDir = SanityCheck::absPathIsInDocRoot(Paths::getWebPExpressContentDirAbs() . '/log');
77
 
78
 
146
  $checking = '"filename" argument';
147
  Validate::postHasKey('filename');
148
  $filename = sanitize_text_field($_POST['filename']);
149
+ //$filename = SanityCheck::absPathExistsAndIsFileInDocRoot($filename);
150
  // PS: No need to check mime version as webp-convert does that.
151
 
152
 
lib/classes/ConvertHelperIndependent.php CHANGED
@@ -329,7 +329,7 @@ APACHE
329
 
330
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
331
 
332
- $text = 'WebP Express 0.14.15. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
333
 
334
  $logFile = self::getLogFilename($source, $logDir);
335
 
329
 
330
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
331
 
332
+ $text = 'WebP Express 0.14.16. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
333
 
334
  $logFile = self::getLogFilename($source, $logDir);
335
 
lib/classes/SanityCheck.php CHANGED
@@ -115,13 +115,47 @@ class SanityCheck
115
  return $input;
116
  }
117
 
118
- public static function absPath($input)
119
  {
 
 
 
120
  return self::path($input);
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  public static function absPathIsInDocRoot($input, $errorMsg = 'Path is outside document root')
124
  {
 
 
125
  $docRoot = self::absPath($_SERVER["DOCUMENT_ROOT"]);
126
  $docRoot = rtrim($docRoot, '/');
127
  $docRoot = self::absPathExistsAndIsDir($docRoot);
@@ -137,11 +171,10 @@ class SanityCheck
137
 
138
  try {
139
  // try without symlinks expanded
 
140
  self::pathBeginsWith($input, $docRoot . '/', $errorMsg);
141
  } catch (SanityException $e) {
142
-
143
- // if that fails, check with symlinks expanded
144
- self::pathBeginsWith(realpath($input), $docRootSymLinksExpanded . '/', $errorMsg);
145
  }
146
 
147
  return $input;
115
  return $input;
116
  }
117
 
118
+ public static function absPath($input, $errorMsg = 'Not an absolute path')
119
  {
120
+ if ((strpos($input, '/') !== 0)) {
121
+ throw new SanityException($errorMsg . $input);
122
+ }
123
  return self::path($input);
124
  }
125
 
126
+ private static function findClosestExistingFolderSymLinksExpanded($input) {
127
+ // Get closest existing folder with symlinks expanded.
128
+ // this is a bit complicated, as the input path may not yet exist.
129
+ // in case of realpath failure, we must try with one folder pealed off at the time
130
+
131
+ $levelsUp = 1;
132
+ while (true) {
133
+ $dir = dirname($input, $levelsUp);
134
+ $realPathResult = realpath($dir);
135
+ if ($realPathResult !== false) {
136
+ return $realPathResult;
137
+ }
138
+ if (($dir == '/') || (strlen($dir) < 4)) {
139
+ return $dir;
140
+ }
141
+ $levelsUp++;
142
+ }
143
+ }
144
+
145
+ public static function pathBeginsWithSymLinksExpanded($input, $beginsWith, $errorMsg = 'Path is outside allowed path') {
146
+ $closestExistingFolder = self::findClosestExistingFolderSymLinksExpanded($input);
147
+ self::pathBeginsWith($closestExistingFolder, $beginsWith, $errorMsg);
148
+ }
149
+
150
+ /**
151
+ * Test that absolute path is in document root.
152
+ *
153
+ * It is acceptable if the absolute path does not exist
154
+ */
155
  public static function absPathIsInDocRoot($input, $errorMsg = 'Path is outside document root')
156
  {
157
+ self::absPath($input);
158
+
159
  $docRoot = self::absPath($_SERVER["DOCUMENT_ROOT"]);
160
  $docRoot = rtrim($docRoot, '/');
161
  $docRoot = self::absPathExistsAndIsDir($docRoot);
171
 
172
  try {
173
  // try without symlinks expanded
174
+ throw new SanityException('Cannot find document root');
175
  self::pathBeginsWith($input, $docRoot . '/', $errorMsg);
176
  } catch (SanityException $e) {
177
+ self::pathBeginsWithSymLinksExpanded($input, $docRootSymLinksExpanded . '/', $errorMsg);
 
 
178
  }
179
 
180
  return $input;
webp-express.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
- * Version: 0.14.15
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
+ * Version: 0.14.16
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2