Skip to content

Commit

Permalink
Boost: Fix cache bypass patterns not applied from start of URL (#40999)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity authored Jan 14, 2025
1 parent 8e91632 commit 06943fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
8 changes: 3 additions & 5 deletions projects/plugins/boost/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// PhanTypeArraySuspicious : 9 occurrences
// PhanTypeMismatchArgument : 8 occurrences
// PhanParamTooMany : 6 occurrences
// PhanPossiblyUndeclaredVariable : 6 occurrences
// PhanTypeMismatchReturnProbablyReal : 6 occurrences
// PhanPossiblyUndeclaredVariable : 5 occurrences
// PhanTypeMismatchReturnProbablyReal : 5 occurrences
// PhanUndeclaredConstant : 5 occurrences
// PhanTypeMismatchArgumentNullableInternal : 4 occurrences
// PhanUndeclaredFunction : 4 occurrences
Expand All @@ -30,7 +30,6 @@
// PhanTypeMismatchReturnNullable : 2 occurrences
// PhanCoalescingNeverNull : 1 occurrence
// PhanImpossibleTypeComparisonInGlobalScope : 1 occurrence
// PhanPluginNeverReturnFunction : 1 occurrence
// PhanRedefineFunction : 1 occurrence
// PhanRedundantCondition : 1 occurrence
// PhanTypeInvalidUnaryOperandIncOrDec : 1 occurrence
Expand All @@ -55,13 +54,12 @@
'app/lib/minify/Config.php' => ['PhanTypeMismatchReturnNullable'],
'app/lib/minify/Dependency_Path_Mapping.php' => ['PhanUndeclaredConstant'],
'app/lib/minify/functions-helpers.php' => ['PhanImpossibleTypeComparison', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchDefault', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredConstant'],
'app/lib/minify/functions-service.php' => ['PhanImpossibleTypeComparison', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginNeverReturnFunction', 'PhanPluginUseReturnValueInternalKnown', 'PhanPossiblyUndeclaredVariable', 'PhanTypeComparisonToArray', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullableInternal'],
'app/lib/minify/functions-service.php' => ['PhanImpossibleTypeComparison', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginUseReturnValueInternalKnown', 'PhanPossiblyUndeclaredVariable', 'PhanTypeComparisonToArray', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullableInternal'],
'app/modules/Modules_Setup.php' => ['PhanTypeMismatchPropertyDefault'],
'app/modules/image-guide/Image_Guide_Proxy.php' => ['PhanPluginDuplicateConditionalNullCoalescing'],
'app/modules/image-size-analysis/data-sync/Image_Size_Analysis_Action_Fix.php' => ['PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition'],
'app/modules/optimizations/critical-css/CSS_Proxy.php' => ['PhanPluginDuplicateConditionalNullCoalescing'],
'app/modules/optimizations/page-cache/Page_Cache_Setup.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeMissingReturn'],
'app/modules/optimizations/page-cache/data-sync/Page_Cache_Entry.php' => ['PhanTypeMismatchReturnProbablyReal'],
'app/modules/optimizations/page-cache/pre-wordpress/Boost_Cache.php' => ['PhanTypeMismatchReturnProbablyReal'],
'app/modules/optimizations/page-cache/pre-wordpress/Logger.php' => ['PhanCoalescingNeverNull', 'PhanPluginDuplicateConditionalNullCoalescing'],
'app/modules/optimizations/page-cache/pre-wordpress/Request.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchPropertyDefault'],
Expand Down
9 changes: 8 additions & 1 deletion projects/plugins/boost/app/lib/minify/functions-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,16 @@ function jetpack_boost_page_optimize_get_file_paths( $args ) {
return $args;
}

/**
* Exit with a given HTTP status code.
*
* @param int $status HTTP status code.
*
* @return never
*/
function jetpack_boost_page_optimize_status_exit( $status ) {
http_response_code( $status );
exit;
exit( 0 ); // This is a workaround, until a bug in phan is fixed - https://github.com/phan/phan/issues/4888
}

function jetpack_boost_page_optimize_get_mime_type( $file ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function set( $value ) {
*
* @param mixed $value The value to sanitize.
*
* @return string The sanitized value, as a list.
* @return array The sanitized value.
*/
private function sanitize_value( $value ) {
if ( is_array( $value ) ) {
Expand All @@ -56,12 +56,19 @@ private function sanitize_value( $value ) {
// Remove double shashes.
$path = str_replace( '//', '/', $path );

// Remove symbols, as they are included in the regex check.
$path = ltrim( $path, '^' );
$path = rtrim( $path, '$' );
$path = preg_replace( '/\/\?$/', '', $path );

// Make sure there's a leading slash.
$path = '/' . ltrim( $path, '/' );

// Fix up any wildcards.
$path = $this->sanitize_wildcards( $path );
}

$value = array_values( array_unique( array_filter( $value ) ) );
} else {
$value = array();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public function is_url_excluded( $request_uri = '' ) {

/**
* Filters the bypass patterns for the page cache.
* If you need to sanitize them, do it before passing them to this filter,
* as there's no sanitization done after this filter.
*
* @since 3.2.0
*
Expand All @@ -104,7 +106,7 @@ public function is_url_excluded( $request_uri = '' ) {

$bypass_patterns[] = 'wp-.*\.php';
foreach ( $bypass_patterns as $expr ) {
if ( ! empty( $expr ) && preg_match( "~$expr~", $request_uri ) ) {
if ( ! empty( $expr ) && preg_match( "~^$expr/?$~", $request_uri ) ) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Page Cache: Fixed bypass patterns getting applied to the whole URL instead of the start.

0 comments on commit 06943fd

Please sign in to comment.