Allow external host on http.php
-
I have WordPress installed on a Synology server, is not working any link to install, update, rss, etc. that goes to ww.wp.xz.cn. Is blocked by the wp_safe_remote_request function. Specifically for not accomplishing the same_host restriction.
I would like to keep this part in the code for safety, and I seen that there is a code for apply_filters , how can I make an exception for https://downloads.wp.xz.cn/ ?
Tanks for help, everything I have tried has not worked.
-
This topic was modified 5 years, 5 months ago by
intrapixel.
-
This topic was modified 5 years, 5 months ago by
-
Hi @intrapixel,
wp_safe_remote_request()should allow requests to ww.wp.xz.cn downloads & API, and RSS feeds normally. The only limitations is that it blocks requests to certain “local” addresses and ports, to avoid issues around WordPress accessing things it shouldn’t (For example, being able to access the Synology management interface).What’s the exact error message you’re seeing from WordPress? The RSS feed display is the simplest place to see it, but you can also try the Site Health screens which may also show it.
@intrapixel Also, make sure you do NOT have
WP_ACCESSIBLE_HOSTorWP_HTTP_BLOCK_EXTERNALdefined in your wp-config.php file, or in a synology-helper plugin (although these should both be flagged in Site Health I believe)Thanks for answering me. The errors are…
In any update:
“An error occurred while updating anything Download failed. A valid URL was not provided.”
In theme install:
“Downloading installation package from http://downloads.wp.xz.cn/theme/anyfile.zip…
Download failed. A valid URL was not provided.”
In admin Dashboard, WordPress news:
“Error RSS: WP HTTP Error: A valid URL was not provided.”If I change “wp_safe_remote_request ()” to “$ args [‘reject_unsafe_urls’] =
truefalse” that allow to get news on Dashboard. For updates and installs I need to change that on “wp_safe_remote_get ()”.My problem is whit “reject_unsafe_urls” is marking unsafe if it is not on localhost. I want to now how write the right code to add arguments to set ww.wp.xz.cn as safe.
-
This reply was modified 5 years, 5 months ago by
intrapixel.
-
This reply was modified 5 years, 5 months ago by
intrapixel.
@intrapixel Sorry for the delayed follow up (If you mention me by @dd32 in your reply I’ll be able to get back to you faster)
My problem is whit “reject_unsafe_urls” is marking unsafe if it is not on localhost. I want to now how write the right code to add arguments to set ww.wp.xz.cn as safe
By default, that IS a safe URL, so I think the problem here is that something (not WordPress itself) is triggering a failure case where it thinks that’s NOT safe.
A valid URL was not provided
That makes me think that wp_http_validate_url() is returning false, looking through that function, I suspect that the likely cause is a DNS resolution issue – if
gethostbyname( 'ww.wp.xz.cn' )doesn’t return an IP it can fail.I think your best bet is to add some debugging and call
wp_http_validate_url( 'https://ww.wp.xz.cn/' )and see where it’s failing and returning false – that function call should return the URL there if it’s working correctly.-
This reply was modified 5 years, 5 months ago by
Dion Hulse.
@dd32 Thanks. Yes, debug mode is active, and when I go to for example install new theme to see the “invalid url” error, nothing happen in the log file:
called site single site, get site license or else default settingsI must do something different in debug?
My apologies @intrapixel by debugging I meant adding something into the function so that where it looked like:
if ( condition1 ) { var_dump( "Condition 1 caused it to fail" ); return false; }I’ve copied the code from WordPress 5.6 into a gist to add some debugging: https://gist.github.com/dd32/a9e9e89101f7e4a18200376649aa3b55
If you update the function with that and then run a few requests, you should see it output the reasoning for it being an invalid url.
@dd32 I add the code to http.php and now the error I got is this:
Installation failed: string(146) "wp_http_validate_url 'https://downloads.wp.xz.cn/theme/twentytwenty.1.6.zip' is invalid, gethostbyname() failed to find correct DNS for site." {"success":false,"data":{"install":"theme","slug":"twentytwenty","debug":["Downloading installation package from https:\/\/downloads.wp.xz.cn\/theme\/twentytwenty.1.6.zip…","Download failed. A valid URL was not provided."],"errorMessage":"Download failed. A valid URL was not provided."}}-
This reply was modified 5 years, 5 months ago by
intrapixel.
I add the code to http.php and now the error I got is this… gethostbyname() failed to find correct DNS for site.
Right, so your problem is that DNS resolution is broken, as I alluded to above.
I’m not familiar enough with how synology works, but I think it’s docker based? you might need to force it to restart the instances/apps if they started before there was internet access or something.. or maybe even restarting the entire device..
Unfortunately this isn’t really a WordPress problem, but rather a PHP/Synology problem, so you might be able to get more help through a Synology support forum. Mentioning that
gethostbyname( 'ww.wp.xz.cn' )isn’t working.@dd32 It’s not on docker, and I restart several times the server. Thank you very much for your help, now that I know what the error is, I will continue looking why gethostbyname does not work solving the DNS.
-
This reply was modified 5 years, 5 months ago by
The topic ‘Allow external host on http.php’ is closed to new replies.