Merge "Fix mime detection of easily-confused-with text/plain formats"
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index b8ca434..5defd45 100644 (file)
@@ -118,7 +118,7 @@ abstract class UploadBase {
         * Can be overridden by subclasses.
         *
         * @param User $user
-        * @return bool
+        * @return bool|string
         */
        public static function isAllowed( $user ) {
                foreach ( array( 'upload', 'edit' ) as $permission ) {
@@ -435,7 +435,7 @@ abstract class UploadBase {
                }
 
                $this->mFileProps = FSFile::getPropsFromPath( $this->mTempPath, $this->mFinalExtension );
-               $mime = $this->mFileProps['file-mime'];
+               $mime = $this->mFileProps['mime'];
 
                if ( $wgVerifyMimeType ) {
                        # XXX: Missing extension will be caught by validateName() via getTitle()
@@ -1390,12 +1390,19 @@ abstract class UploadBase {
                                return true;
                        }
 
-                       # href with javascript target
-                       if ( $stripped == 'href' && strpos( strtolower( $value ), 'javascript:' ) !== false ) {
-                               wfDebug( __METHOD__
-                                       . ": Found script in href attribute '$attrib'='$value' in uploaded file.\n" );
+                       # href with non-local target (don't allow http://, javascript:, etc)
+                       if ( $stripped == 'href'
+                               && strpos( $value, 'data:' ) !== 0
+                               && strpos( $value, '#' ) !== 0
+                       ) {
+                               if ( !( $strippedElement === 'a'
+                                       && preg_match( '!^https?://!im', $value ) )
+                               ) {
+                                       wfDebug( __METHOD__ . ": Found href attribute <$strippedElement "
+                                               . "'$attrib'='$value' in uploaded file.\n" );
 
-                               return true;
+                                       return true;
+                               }
                        }
 
                        # href with embedded svg as target