jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Jetpack Signature: Support X-Forwarded-Port HTTP header

Open kraftbj opened this issue 12 years ago • 9 comments

In some circumstances, when php is executing on a server behind a caching layer or another intermediate server, if the server is on a different port than the public version, the Jetpack signature will be created using the php server's port instead of the public port.

Suggest supporting the X-Forwarded-Port header as one way to handle this.

Further details in 1835697-t

kraftbj avatar Jun 30 '14 15:06 kraftbj

cc: @lezama who has been the rockstar handling signature failings lately.

georgestephanis avatar Jul 01 '14 13:07 georgestephanis

Context: I am the original source of this request. Our platform puts the runtimes for WP sites in containers on a number of different ports for security reasons, then load-balances in front of them. Other tools use the X-Forwarded-Port and X-Forwarded-Proto headers for this sort of thing.

In the mean-time I'm getting a work-around in place, but it'd be a nice piece of future-proofing to have these headers work natively in Jetpack.

joshkoenig avatar Jul 10 '14 16:07 joshkoenig

Some general Core discussion context: (unsure if relevant, I'm not terribly familiar with this case)

https://core.trac.wordpress.org/ticket/19337#comment:4 https://core.trac.wordpress.org/ticket/28443

georgestephanis avatar Jul 10 '14 16:07 georgestephanis

Hey Guys,

For Pantheon is_https() should work as expected. We are carrying the legacy $_SERVER['HTTPS'] superglobal forward. The issue is that we currently expose the actual $_SERVER['HTTP_PORT'] to PHP, which is typically a high/crazy number since it's an ephemeral container.

I think the issue is that Jetpack's code uses that $_SERVER['HTTP_PORT'] variable in signing the request, rather than is_https(). We may be able to work around this by adding a snippit to wp-config.php:

if ( isset( $_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
  $_SERVER['HTTP_PORT'] = 443;
}
else {
  $_SERVER['HTTP_PORT'] = 80;
}

joshkoenig avatar Sep 10 '14 20:09 joshkoenig

Checking the X-Forwarded-* headers seems like the right solution, but I think we need to think it through a bit.

In the meantime, you should be able to do the following (for example, in your wp-config.php or some early loading plugin).

define( 'JETPACK_SIGNATURE__HTTP_PORT', $_SERVER['SERVER_PORT'] );
define( 'JETPACK_SIGNATURE__HTTPS_PORT', $_SERVER['SERVER_PORT'] );

I think that will trick Jetpack into checking incoming signed requests correctly in your setup. That's what we do on WordPress.com, so it should be future proof.

mdawaffe avatar Sep 13 '14 08:09 mdawaffe

Oooh, that's even more perfect. Didn't realize there was a constant we could use. Thanks!

joshkoenig avatar Sep 14 '14 17:09 joshkoenig

@joshkoenig Long ago, but do you have any sites setup not using the constants and using X-Forwarded that you could help test #3402 using?

kraftbj avatar May 16 '16 14:05 kraftbj

I worked around this internally, but can probably re-break it in a test environment so see if it works.

Thanks for getting to this @kraftbj! I'll be able to take a look later this week and will report back.

joshkoenig avatar May 16 '16 20:05 joshkoenig

Fixed in #3402

jeherve avatar Jun 17 '16 15:06 jeherve