Skip to content

Commit 0613543

Browse files
CORS proxy: Make allowed origins configurable (#43)
## Motivation for the change, related issues We need to better support self-hosting the Playground web app (as we are now deploying a private instance), and the current CORS proxy only supports requests from playground.wordpress.net and localhost. Let's allow customizing the list of supported origins. ## Implementation details This PR specifies the current supported origins as the default list and allows it to be overridden by defining a PHP constant `PLAYGROUND_CORS_PROXY_SUPPORTED_ORIGINS`. This PR also stops the web app build and deployment from including its own CORS proxy. We don't want this in the main, public web app, so let's just keep the two completely separate. ## Testing Instructions (or ideally a Blueprint) Test after merge part of a private CORS proxy deployment.
1 parent c0815ce commit 0613543

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

packages/playground/php-cors-proxy-deployment/__wp__/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
if (
4-
empty( $_SERVER['PATH_INFO'] ) &&
4+
empty( $_SERVER['PATH_INFO'] ) &&
55
!str_starts_with($_SERVER['REQUEST_URI'], '/?')
66
) {
77
// Allow proxied URL to be provided via request URI,

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,21 @@ function should_respond_with_cors_headers($host, $origin) {
407407
return false;
408408
}
409409

410-
$is_request_from_playground_web_app = $origin === 'https://playground.wordpress.net';
411-
$not_hosted_with_playground_web_app = $host !== 'playground.wordpress.net';
410+
$supported_origins = array(
411+
'https://playground.wordpress.net',
412+
'http://localhost',
413+
'http://127.0.0.1',
414+
);
412415
if (
413-
$is_request_from_playground_web_app &&
414-
$not_hosted_with_playground_web_app
416+
defined('PLAYGROUND_CORS_PROXY_SUPPORTED_ORIGINS') &&
417+
is_array(PLAYGROUND_CORS_PROXY_SUPPORTED_ORIGINS)
415418
) {
416-
return true;
419+
$supported_origins = PLAYGROUND_CORS_PROXY_SUPPORTED_ORIGINS;
417420
}
418421

419-
$origin_host = parse_url($origin, PHP_URL_HOST);
420-
$is_local_origin = in_array(
421-
$origin_host,
422-
array('localhost', '127.0.0.1'),
422+
return in_array(
423+
$origin,
424+
$supported_origins,
423425
true
424426
);
425-
426-
return $is_local_origin;
427427
}

packages/playground/website-deployment/apply-update.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,4 @@ curl -sS -X POST -H "Auth: $ATOMIC_SITE_API_KEY" "$SITE_API_BASE/edge-cache/$ATO
102102
&& echo "Edge cache purged" \
103103
|| (>&2 echo "Failed to purge edge cache" && false)
104104

105-
echo Applying latest CORS proxy rate-limiting schema
106-
# NOTE: This will reset rate-limiting token buckets, but that should be tolerable
107-
# as long as we're generally discouraging abuse of the proxy.
108-
cat ~/website-deployment/cors-proxy-rate-limiting-table.sql | mysql --database="$DB_NAME"
109-
110105
echo Done!

packages/playground/website/project.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
"cp -r ./client ./wasm-wordpress-net/",
2020
"cp -r ./remote/* ./wasm-wordpress-net/",
2121
"cp -r ./website/* ./wasm-wordpress-net/",
22-
"cp ../../../packages/playground/php-cors-proxy/cors-proxy.php ./wasm-wordpress-net/",
23-
"cp ../../../packages/playground/php-cors-proxy/cors-proxy-functions.php ./wasm-wordpress-net/",
2422
"cat ./remote/.htaccess ./website/.htaccess > ./wasm-wordpress-net/.htaccess",
2523
"curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wasm-wordpress-net/wp-cli.phar",
2624
"cat wasm-wordpress-net/wp-cli.phar | gzip -c -9 > wasm-wordpress-net/wp-cli.phar.gz"

0 commit comments

Comments
 (0)