Skip to content

Commit

Permalink
Don't enqueue in CritCSS job queue if the path indicates it's garbage…
Browse files Browse the repository at this point in the history
… (e.g. .php or /null).
  • Loading branch information
futtta committed Dec 29, 2023
1 parent 41e3204 commit c93c339
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions classes/autoptimizeCriticalCSSEnqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function ao_ccss_enqueue( $hash = '', $path = '', $type = 'is_page' ) {
// ... which are not the ones below.
if ( true === autoptimizeUtils::is_local_server() ) {
$enqueue = false;
$this->criticalcss->log('cant enqueue as local/ private', 3 );
$this->criticalcss->log( 'cant enqueue as local/ private', 3 );
} elseif ( 'nokey' == $key['status'] || 'invalid' == $key['status'] ) {
$enqueue = false;
$this->criticalcss->log( 'Job queuing is not available: no valid API key found.', 3 );
Expand Down Expand Up @@ -66,9 +66,15 @@ public function ao_ccss_enqueue( $hash = '', $path = '', $type = 'is_page' ) {
}
$req_path = strtok( $req_orig, '?' );

// now that we really have the path, check if there's no garbage in there (due to some themes serving a non 404 page even if the resource does not exist resulting in all sorts of nonsense rules).
if ( true === apply_filters( 'autoptimize_filter_ccss_enqueue_block_garbage' , true ) && str_replace( apply_filters( 'autoptimize_filter_ccss_enqueue_blocklist', array( '.php', 'data:javascript/text;base64', '/.', '/null' ) ), '', $req_path ) !== $req_path ) {
$this->criticalcss->log( 'Job not enqueued looks like the path is just garbage; ' . $req_path, 3 );
return;
}

// Check if we have a lang param. we need to keep as WPML can switch languages based on that
// and that includes RTL -> LTR so diff. structure, so rules would be RTL vs LTR
// but this needs changes in the structur of the rule object so off by default for now
// but this needs changes in the structure of the rule object so off by default for now
// as now this will simply result in conditional rules being overwritten.
if ( apply_filters( 'autoptimize_filter_ccss_coreenqueue_honor_lang', false ) && strpos( $req_orig, 'lang=' ) !== false ) {
$req_params = strtok( '?' );
Expand Down

0 comments on commit c93c339

Please sign in to comment.