@@ -1753,6 +1753,23 @@ protected static function isPermittedPath($path)
17531753 return !preg_match ('#^[a-z]+://#i ' , $ path );
17541754 }
17551755
1756+ /**
1757+ * Check whether a file path is safe, accessible, and readable.
1758+ *
1759+ * @param string $path A relative or absolute path to a file
1760+ *
1761+ * @return bool
1762+ */
1763+ protected static function fileIsAccessible ($ path )
1764+ {
1765+ $ readable = file_exists ($ path );
1766+ //If not a UNC path (expected to start with \\), check read permission, see #2069
1767+ if (strpos ($ path , '\\\\' ) !== 0 ) {
1768+ $ readable = $ readable && is_readable ($ path );
1769+ }
1770+ return static ::isPermittedPath ($ path ) && $ readable ;
1771+ }
1772+
17561773 /**
17571774 * Send mail using the PHP mail() function.
17581775 *
@@ -2141,7 +2158,7 @@ public function setLanguage($langcode = 'en', $lang_path = '')
21412158 // There is no English translation file
21422159 if ('en ' !== $ langcode ) {
21432160 // Make sure language file path is readable
2144- if (!static ::isPermittedPath ( $ lang_file ) || ! file_exists ($ lang_file )) {
2161+ if (!static ::fileIsAccessible ($ lang_file )) {
21452162 $ foundlang = false ;
21462163 } else {
21472164 // Overwrite language-specific strings.
@@ -2970,7 +2987,7 @@ public function addAttachment(
29702987 $ disposition = 'attachment '
29712988 ) {
29722989 try {
2973- if (!static ::isPermittedPath ( $ path ) || !@ is_file ( $ path ) || ! is_readable ($ path )) {
2990+ if (!static ::fileIsAccessible ($ path )) {
29742991 throw new Exception ($ this ->lang ('file_access ' ) . $ path , self ::STOP_CONTINUE );
29752992 }
29762993
@@ -3144,7 +3161,7 @@ protected function attachAll($disposition_type, $boundary)
31443161 protected function encodeFile ($ path , $ encoding = self ::ENCODING_BASE64 )
31453162 {
31463163 try {
3147- if (!static ::isPermittedPath ( $ path ) || ! file_exists ( $ path ) || ! is_readable ($ path )) {
3164+ if (!static ::fileIsAccessible ($ path )) {
31483165 throw new Exception ($ this ->lang ('file_open ' ) . $ path , self ::STOP_CONTINUE );
31493166 }
31503167 $ file_buffer = file_get_contents ($ path );
@@ -3530,7 +3547,7 @@ public function addEmbeddedImage(
35303547 $ disposition = 'inline '
35313548 ) {
35323549 try {
3533- if (!static ::isPermittedPath ( $ path ) || !@ is_file ( $ path ) || ! is_readable ($ path )) {
3550+ if (!static ::fileIsAccessible ($ path )) {
35343551 throw new Exception ($ this ->lang ('file_access ' ) . $ path , self ::STOP_CONTINUE );
35353552 }
35363553
0 commit comments