Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CANTINA-913: Match protocol in CORS header #4964

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions 001-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,16 @@ function vip_prevent_invalid_core_query_args() {
}

add_action( 'wp_loaded', 'vip_prevent_invalid_core_query_args', 1 );

add_filter( 'allowed_http_origins', 'vip_only_https_origins' );

/**
* Only allow HTTPS origins on VIP
*
* @param array $origins
*/
function vip_only_https_origins( $origins ) {
return array_filter( $origins, function ( $origin ) {
return strpos( $origin, 'https://' ) === 0;
rebeccahum marked this conversation as resolved.
Show resolved Hide resolved
} );
}
17 changes: 17 additions & 0 deletions tests/test-core-filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Core_Filters_Test extends WP_UnitTestCase {
public function test_vip_only_https_origins(): void {
$input = [
0 => 'http://example.com',
1 => 'https://example.com',
];

$expected = [
1 => 'https://example.com',
];

$actual = vip_only_https_origins( $input );
self::assertSame( $expected, $actual );
}
}