Skip to content

HTTP API: Don't trust the insecure origin of an HTTPS site - #15002

Open
johnbillion wants to merge 11 commits into
WordPress:trunkfrom
johnbillion:fix/66391-insecure-http-origin
Open

johnbillion wants to merge 11 commits into
WordPress:trunkfrom
johnbillion:fix/66391-insecure-http-origin

Conversation

@johnbillion

@johnbillion johnbillion commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

get_allowed_http_origins() added both the http:// and https:// variants of the admin and home host unconditionally, so an HTTPS-only site incorrectly trusted an http:// origin. This adds the http:// origin only when the corresponding admin_url()/home_url() is not HTTPS.

Trac ticket: https://core.trac.wordpress.org/ticket/66391

`get_allowed_http_origins()` added both the `http://` and `https://` variants of the admin and home host unconditionally. On an HTTPS-only site the `http://` origin was trusted even though the site never uses it, allowing a network attacker on plaintext traffic to read credentialed cross-origin responses.

Add the `http://` origin only when the corresponding `admin_url()`/`home_url()` is not served over HTTPS. The admin and home schemes are evaluated independently.

Fixes #66391.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props johnbillion, westonruter, sadmansakibnadvi.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment thread src/wp-includes/http.php Outdated
$allowed_origins[] = 'http://' . $home_origin['host'];
}

$allowed_origins = array_unique( $allowed_origins );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are PHPStan errors here which I think we can take an opportunity to fix:

  454    Cannot access offset 'host' on array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}|false.
         🪪  offsetAccess.nonOffsetAccessible
  455    Cannot access offset 'host' on array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}|false.
         🪪  offsetAccess.nonOffsetAccessible
  459    Cannot access offset 'scheme' on array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}|false.
         🪪  offsetAccess.nonOffsetAccessible
  460    Offset 'host' might not exist on array{scheme: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}.
         🪪  offsetAccess.notFound
  462    Cannot access offset 'scheme' on array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}|false.
         🪪  offsetAccess.nonOffsetAccessible
  463    Offset 'host' might not exist on array{scheme: string, host?: string, port?: int<0, 65535>, user?: string, pass?:
         string, path?: string, query?: string, fragment?: string}.
         🪪  offsetAccess.notFound

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4bcae67 and then further refined.

@westonruter westonruter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Comment by Claude Opus 5.5 (medium effort)

Correction: the main concern in this review was retracted (see the reply on r4419422381). Rows 2 and 3 below show the fix working as intended: during an HTTPS request, the http:// origin is not trusted, which is what protects FORCE_SSL_ADMIN sites with an http:// home.

Details

These are the results from a temporary PHPUnit probe for host example.org:

Scenario get_allowed_http_origins()
home/siteurl http://, HTTP request https://, http://
home/siteurl http:// + force_ssl_admin( true ), HTTPS request https:// only
home/siteurl http://, HTTPS request (no FORCE_SSL_ADMIN) https:// only
home/siteurl https://, request not detected as HTTPS (e.g. proxy without is_ssl() detection) https://, http:// (admin_url() is http://…/wp-admin/)
home_url/admin_url filtered to HTTPS://example.org https://, http://
filtered to //example.org https:// only

Rows 4 to 6 only arise with an undetected-HTTPS misconfiguration or unusual URL filters. The other inline comments (the (array) cast, the changelog entry, and the port) are unaffected by this correction.

Edited: this originally called rows 2 and 3 a regression.

Comment thread src/wp-includes/http.php Resolved
* @param non-falsy-string $admin_url Value to return from admin_url().
* @param non-falsy-string $home_url Value to return from home_url().
*/
private function force_urls( string $admin_url, string $home_url ): void {

@westonruter westonruter Oct 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Comment by Claude Opus 5.5 (medium effort)

The admin_url/home_url filters run after the scheme is chosen, so these tests never reach the request-dependent is_ssl()/force_ssl_admin() logic. Tests that set $_SERVER['HTTPS'] and call force_ssl_admin() are suggested, to lock in that the http:// origin is rejected during HTTPS requests.

Details

The suggested tests set the home/siteurl options directly and then:

  • set $_SERVER['HTTPS'] = 'on' with an http:// configuration, asserting http://example.org is not allowed;
  • also call force_ssl_admin( true ) with an http:// home, asserting the same, since this is the case the protection matters most for (admin-ajax is authenticated only by the secure auth cookie there);
  • leave is_ssl() false with an http:// configuration, asserting http://example.org is allowed.

$_SERVER['HTTPS'] and force_ssl_admin( false ) would need to be reset in tear_down().

Edited: the first two bullets originally asserted the http:// origin was still allowed, based on the retracted concern in r4419422381.

Comment thread src/wp-includes/http.php Outdated
* @param string[] $allowed_origins Array of allowed HTTP origins.
*/
return apply_filters( 'allowed_http_origins', $allowed_origins );
return (array) apply_filters( 'allowed_http_origins', $allowed_origins );

@westonruter westonruter Oct 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Comment by Claude Opus 5.5 (medium effort)

The (array) cast silently turns an invalid filter return, such as a string, into an allow-list. On trunk the same mistake raised a TypeError that made it visible.

Details

A callback that returns the string 'https://a.example' becomes array( 'https://a.example' ) (verified), and an object becomes an array of its public properties. On trunk the TypeError came from in_array() in is_allowed_http_origin(). The options are to drop the cast, or to check is_array() and fall back to $allowed_origins, perhaps with _doing_it_wrong().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to prevent a fatal error with the addition of the native array return type hint. Maybe this would be better:

Suggested change
return (array) apply_filters( 'allowed_http_origins', $allowed_origins );
$origins = (array) apply_filters( 'allowed_http_origins', $allowed_origins );
return array_filter( $origins, 'is_string' );

Or we can just drop the change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a pattern that should be encouraged, although it is used in a few places already. Type casting just serves to mask an underlying mistake.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this could be more holistically addressed with Core-51525.

The main benefit of the cast here is that it prevents a fatal error.

I've reverted this in 6ace9e6

Comment thread src/wp-includes/http.php
@@ -445,19 +445,28 @@ function get_http_origin() {
*
* @return string[] Array of origin URLs.

@westonruter westonruter Oct 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Comment by Claude Opus 5.5 (medium effort)

A @since changelog entry is suggested, because sites that rely on the http:// origin will see their CORS requests start failing after upgrading.

Details

For example (with the actual version):

 * @since X.Y.0 The insecure `http://` origin is no longer included for a URL served over HTTPS.

The allowed_http_origins hook docs could also mention that the http:// variant can be added back through that filter.

The order of the returned origins also changes. Trunk returned http:// admin, https:// admin, http:// home, https:// home; now https:// comes first. This only matters to code that reads the list by position.

Comment thread src/wp-includes/http.php
parse_url( home_url() ),
);

// @todo Preserve port?

@westonruter westonruter Oct 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Comment by Claude Opus 5.5 (medium effort)

Nit (pre-existing): this rewrite could resolve the @todo, because a site on a non-default port, such as http://localhost:8000, never matches its own Origin header. It's fine to leave for a separate ticket.

Details

Append ':' . $port to the origin when parse_url( $url, PHP_URL_PORT ) is set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to finally do this todo 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related, in Performance Lab we have this workaround:

	/**
	 * Determines if the HTTP origin is authorized.
	 *
	 * Note that `is_allowed_http_origin()` is not used directly because the underlying `get_allowed_http_origins()` does
	 * not account for the URL port (although there is a to-do comment committed in core to address this). Additionally,
	 * the `is_allowed_http_origin()` function in core for some reason returns a string rather than a boolean.
	 *
	 * @since 1.0.0
	 * @see is_allowed_http_origin()
	 * @access private
	 *
	 * @param string $origin Origin to check.
	 * @return bool Whether the origin is allowed.
	 */
	protected static function is_allowed_http_origin( string $origin ): bool {
		// Strip out the port number since core does not account for it yet as noted in get_allowed_http_origins().
		$origin = preg_replace( '/:\d+$/', '', $origin );
		return '' !== is_allowed_http_origin( $origin );
	}

@sadmansakibnadvi

Copy link
Copy Markdown

Tested 5695cb8 on 7.2-beta3-64990. Home and admin share a host here. I forced HTTPS per request with home_url / admin_url filters, and sent Origin headers without a port, since origins are compared by host only.

get_allowed_http_origins():

Site Before After
HTTP home and admin http, https https, http
HTTPS home and admin http, https https only
HTTPS admin, HTTP home http, https https, http

End to end, Access-Control-Allow-Origin from admin-ajax.php:

Site Origin Before After
HTTP http:// sent sent
HTTP https:// sent sent
HTTPS http:// sent not sent
HTTPS https:// sent sent

So an HTTPS site no longer echoes an http:// origin, and mixed setups keep both. No notices from the new code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants