Automattic / wordpress-activitypub

ActivityPub for WordPress
https://wordpress.org/plugins/activitypub/
MIT License
480 stars 70 forks source link

Object of class WP_Error could not be converted to string #192

Closed YiffyToys closed 1 year ago

YiffyToys commented 1 year ago

Version: 0.13.4 Wordpress 6.1.1 PHP 7.4-fpm Apache

Got error 'PHP message: PHP Fatal error:  Uncaught Error: Object of class WP_Error could not be converted to string in ***/wp-includes/http.php:687\n
Stack trace:\n
#0 ***/wp-content/plugins/activitypub/includes/class-signature.php(76): wp_parse_url()\n
#1 ***/wp-content/plugins/activitypub/includes/functions.php(38): Activitypub\\Signature::generate_signature()\n
#2 ***/wp-content/plugins/activitypub/includes/rest/class-inbox.php(341): Activitypub\\safe_remote_post()\n
#3 ***/wp-includes/class-wp-hook.php(308): Activitypub\\Rest\\Inbox::handle_follow()\n
#4 ***/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()\n
#5 ***/wp-includes/plugin.php(517): WP_Hook->do_action()\n
#6 ***/wp-content/plugins/activitypub/includes/rest/class-inbox.php(149)...'

I am experiencing the "waiting for approval" issue mentioned in https://wordpress.org/support/topic/approve-follow-request-redux/

pfefferle commented 1 year ago

Can you tell me your blog URL and the Username, so that I can have a look?

YiffyToys commented 1 year ago

@suran@blog.yiffytoys.de

YiffyToys commented 1 year ago

I have moved to a regular Mastodon server and another WP plugin.

thomas-pike commented 1 year ago

Also experiencing this issue, same symptoms and same stacktrace. I added a debug line in line 75 of includes/class-signature.php: error_log(print_r($url, true)); to find out what the WP_Error object being passed to wp_parse_url was.

Result:

WP_Error Object
(
    [errors] => Array
        (
            [activitypub_no_valid_actor_url] => Array
                (
                    [0] => The "actor" is no valid URL
                )

        )

    [error_data] => Array
        (
            [activitypub_no_valid_actor_url] => https://social.vivaldi.net/users/example
        )

    [additional_data:protected] => Array
        (
        )

)

It seems like \wp_http_validate_url( $actor ) called on line 122 of includes/functions.php considers the $actor URL to be invalid, though it's not immediately obvious why that would be. And of course the WP_Error generated on line 123 is then not being handled gracefully.

thomas-pike commented 1 year ago

Debugging further, it appears to fail the http_request_host_is_external check in \wp_http_validate_url.

thomas-pike commented 1 year ago

And the reason that http_request_host_is_external check was being run at all was because the author URL's hostname was resolving to a local network IP. Hopefully this information might be helpful to anyone else encountering this.

YiffyToys commented 1 year ago

FYI: Wich is perfectly fine if it's hosted on the same machine. Names don't have to resolve to the same collection of IPV6 addresses from everywhere.

craigconstantine commented 1 year ago

This seems to be the fix: In Activitypub\Rest\handle_follow

https://github.com/pfefferle/wordpress-activitypub/blob/010ccc7e228618f10f6473c7a1f35a3b4fbb9c92/includes/rest/class-inbox.php#L325

On line 330…

https://github.com/pfefferle/wordpress-activitypub/blob/010ccc7e228618f10f6473c7a1f35a3b4fbb9c92/includes/rest/class-inbox.php#L330

Here's the $object via print_r debugging…

Array
(
    [user_id] => 2
    [@context] => https://www.w3.org/ns/activitystreams
    [id] => https://c.im/41d40d8f-29dd-404f-913a-15ae38a33266
    [type] => Follow
    [actor] => https://c.im/users/craigconstantine
    [object] => https://constantine.name/author/craig/
)

So actor $object['actor'] is trying to act on inbox $object['object']… the argument should be $object['object']

Screenshot 2022-12-04 at 14 49 03

I've modified my local code. Issued a fresh follow request from a remote mastodon instance, and I did not get a 500-apache-error, … lots of debugging output, but I have a follower listed in WP.

Putting up a quick test post on WP… my debug log is full of deprecated errors (I'll start another issue for that). BUT it seems that the ActivityPub plugin realized it should notify the remote mastodon. So it looks like a successful follow.

craigconstantine commented 1 year ago

upon further consideration… I'm misunderstanding what was going on in Activitypub\Rest\handle_follow(). My suggested change is wrong. I'll undo my local change and dig into it again…

craigconstantine commented 1 year ago

The latest plugin release has resolved my issue. 🤟

Follow requests from another Mastodon server succeed instantly. New posts in my WP server appear as expected over on that Mastodon instance.

THANK YOU! 😃

pfefferle commented 1 year ago

I will close the issue for now, please re-open if still a problem!