Skip to content

Commit 0a776cd

Browse files
committed
Handle case where HTTP_ORIGIN is not provided
1 parent 13e5ee1 commit 0a776cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/playground/php-cors-proxy/cors-proxy-functions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ function rewrite_relative_redirect(
359359
* Answers whether CORS is allowed for the specified origin.
360360
*/
361361
function should_respond_with_cors_headers($host, $origin) {
362+
if (empty($origin)) {
363+
return false;
364+
}
365+
362366
$is_request_from_playground_web_app = $origin === 'https://playground.wordpress.net';
363367
$not_hosted_with_playground_web_app = $host !== 'playground.wordpress.net';
364368
if (
@@ -368,7 +372,7 @@ function should_respond_with_cors_headers($host, $origin) {
368372
return true;
369373
}
370374

371-
$origin_host = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
375+
$origin_host = parse_url($origin, PHP_URL_HOST);
372376
$is_local_origin = in_array(
373377
$origin_host,
374378
array('localhost', '127.0.0.1'),

0 commit comments

Comments
 (0)