Code Duplication    Length = 5-8 lines in 2 locations

includes/upload/UploadBase.php 2 locations

@@ 1427-1434 (lines=8) @@
1424
				&& strpos( $value, 'data:' ) !== 0
1425
				&& strpos( $value, '#' ) !== 0
1426
			) {
1427
				if ( !( $strippedElement === 'a'
1428
					&& preg_match( '!^https?://!im', $value ) )
1429
				) {
1430
					wfDebug( __METHOD__ . ": Found href attribute <$strippedElement "
1431
						. "'$attrib'='$value' in uploaded file.\n" );
1432
1433
					return [ 'uploaded-href-attribute-svg', $strippedElement, $attrib, $value ];
1434
				}
1435
			}
1436
1437
			# only allow data: targets that should be safe. This prevents vectors like,
@@ 1445-1449 (lines=5) @@
1442
				$parameters = '(?>;[a-zA-Z0-9\!#$&\'*+.^_`{|}~-]+=(?>[a-zA-Z0-9\!#$&\'*+.^_`{|}~-]+|"(?>[\0-\x0c\x0e-\x21\x23-\x5b\x5d-\x7f]+|\\\\[\0-\x7f])*"))*(?:;base64)?';
1443
				// @codingStandardsIgnoreEnd
1444
1445
				if ( !preg_match( "!^data:\s*image/(gif|jpeg|jpg|png)$parameters,!i", $value ) ) {
1446
					wfDebug( __METHOD__ . ": Found href to unwhitelisted data: uri "
1447
						. "\"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" );
1448
					return [ 'uploaded-href-unsafe-target-svg', $strippedElement, $attrib, $value ];
1449
				}
1450
			}
1451
1452
			# Change href with animate from (http://html5sec.org/#137).