Skip to content

Commit

Permalink
Improved: don't use relative URLs when storing the cache_url to the DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Aug 28, 2023
1 parent d1566f8 commit 19e872b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Includes/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static function get_domain() {
* Get Analytics URL.
*
* @since 1.0.0
* @access public
*
* @param bool $local Return the Local JS file IF proxy is enabled.
*
* @return string
*/
Expand Down Expand Up @@ -235,6 +236,13 @@ public static function get_proxy_resources() {
$resources = get_option( 'plausible_analytics_proxy_resources', [] );
}

/**
* Force a refresh of our resources if the user recently switched to SSL and we still have non-SSL resources stored.
*/
if ( ! empty( $resources ) && is_ssl() && isset( $resources['cache_url'] ) && ( strpos( $resources['cache_url'], 'http:' ) !== false ) ) {
$resources = [];
}

if ( empty( $resources ) ) {
$cache_dir = bin2hex( random_bytes( 5 ) );
$upload_dir = wp_get_upload_dir();
Expand All @@ -243,7 +251,7 @@ public static function get_proxy_resources() {
'base' => bin2hex( random_bytes( 2 ) ),
'endpoint' => bin2hex( random_bytes( 4 ) ),
'cache_dir' => trailingslashit( $upload_dir['basedir'] ) . trailingslashit( $cache_dir ),
'cache_url' => str_replace( [ 'https:', 'http:' ], '', trailingslashit( $upload_dir['baseurl'] ) . trailingslashit( $cache_dir ) ),
'cache_url' => trailingslashit( $upload_dir['baseurl'] ) . trailingslashit( $cache_dir ),
'file_alias' => bin2hex( random_bytes( 4 ) ),
];

Expand Down

0 comments on commit 19e872b

Please sign in to comment.