Make WordPress Core

Opened 4 years ago

Closed 21 months ago

#52428 closed enhancement (invalid)

Create a Filter for Blocking Outgoing HTTP Calls | Single URL

Reported by: jetxpert's profile jetxpert Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: HTTP API Keywords:
Focuses: Cc:

Description

Good Day!

Per subject, kindly create a new filter that will allow blocking Outgoing HTTP calls for single or defined URLs. Hopefully, prior to the release of WP 5.7.

Details here https://wordpress.org/support/topic/how-to-block-outgoing-http-call-single-url/

and

here https://make.wordpress.org/core/2020/11/23/wordpress-5-7-whats-on-your-wishlist/.

Sorry for the repeat entries. Many sources available :)

Cheers!

Change History (6)

#1 @TimothyBlynJacobs
4 years ago

  • Component changed from General to HTTP API
  • Keywords close reporter-feedback added; dev-feedback needs-unit-tests needs-design removed
  • Version changed from 5.6 to 2.7

Hi @jetxpert,

Welcome to trac! This should be doable with the existing pre_http_request filter. For example:

add_filter( 'pre_http_request', function ( $result, $args, $url ) {
	if ( wp_parse_url( $url, PHP_URL_HOST ) === 'github.com' ) {
		return new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
	}

	return $result;
}, 10, 3 );

#2 @jetxpert
4 years ago

  • Keywords needs-testing added; 2nd-opinion close removed

@TimothyBlynJacobs,

Thank you so much. We'll give it a spin and report back.

Questions:

(1) Can your proposed solution be converted to a "define" type filter we can enter into our wpconfig.php file?

(2) We do not want to report back a WP Error. How can we modify your snippet to reflect this?

(3) To add another (i.e, second or third) URL, how would we modify your snippet?

PS: We miss you over at iThemes Security (forum). Help appreciated. Let us know where we can donate :)

Again, thank you.

Cheers!

Last edited 4 years ago by jetxpert (previous) (diff)

#3 @jetxpert
4 years ago

  • Keywords needs-testing removed

@TimothyBlynJacobs,

Reporting back. Your snippet works like a charm. Thank you.

Can you kindly reply to our questions?

Thank you.

#4 @jetxpert
4 years ago

@TimothyBlynJacobs,

Update:

Questions (2) and (3) resolved.

Only need help with Question (1).

Thank you.

PS: This item added to WP 5.7's wish list https://make.wordpress.org/core/2020/11/23/wordpress-5-7-whats-on-your-wishlist/.

Last edited 4 years ago by jetxpert (previous) (diff)

#5 @TimothyBlynJacobs
4 years ago

  • Keywords close 2nd-opinion added; reporter-feedback removed

You could do something like this:

define( 'MY_BLOCKED_HOSTS', 'github.com,gitlab.com' );

add_filter( 'pre_http_request', function ( $result, $args, $url ) {
	$hosts = wp_parse_list( MY_BLOCKED_HOSTS );

	if ( in_array( wp_parse_url( $url, PHP_URL_HOST ), $hosts, true ) ) {
		return new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
	}

	return $result;
}, 10, 3 );

FYI: I'm adding the close keyword to indicate that this probably doesn't need changing in WordPress Core. The 2nd-opinion is for another Core contributor to take a look and see if they disagree.

#6 @desrosj
21 months ago

  • Keywords close 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Going to close this one out. This is more of a support request and I agree with @TimothyBlynJacobs that there's no action to take on the WordPress Core side.

Note: See TracTickets for help on using tickets.