Skip to content

Commit

Permalink
Only append the home_url port number if the allowed origin lacks a po…
Browse files Browse the repository at this point in the history
…rt number
  • Loading branch information
westonruter committed Nov 10, 2024
1 parent 04f2618 commit 167c935
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/optimization-detective/storage/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,20 @@ function od_register_endpoint(): void {
function od_is_allowed_http_origin( string $origin ): bool {
$allowed_origins = get_allowed_http_origins();
$home_url_port = wp_parse_url( home_url(), PHP_URL_PORT );

// Append the home URL's port to the allowed origins if they lack a port number.
if ( is_int( $home_url_port ) ) {
$allowed_origins = array_map(
static function ( string $allowed_origin ) use ( $home_url_port ): string {
return $allowed_origin . ':' . (string) $home_url_port;
if ( null === wp_parse_url( $allowed_origin, PHP_URL_PORT ) ) {
$allowed_origin .= ':' . (string) $home_url_port;
}
return $allowed_origin;
},
$allowed_origins
);
}

return in_array( $origin, $allowed_origins, true );
}

Expand Down

0 comments on commit 167c935

Please sign in to comment.