Skip to content

Commit 6c90990

Browse files
authored
Some fixes to be compatible with discourse (#736)
* some fixes to be compatible with discourse * always handle actors objects
1 parent 6e374b7 commit 6c90990

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

includes/class-signature.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ public static function parse_signature_header( $signature ) {
379379
if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) {
380380
$parsed_header['keyId'] = trim( $matches[1] );
381381
}
382-
if ( \preg_match( '/created=([0-9]*)/ism', $signature, $matches ) ) {
382+
if ( \preg_match( '/created=["|\']*([0-9]*)["|\']*/ism', $signature, $matches ) ) {
383383
$parsed_header['(created)'] = trim( $matches[1] );
384384
}
385-
if ( \preg_match( '/expires=([0-9]*)/ism', $signature, $matches ) ) {
385+
if ( \preg_match( '/expires=["|\']*([0-9]*)["|\']*/ism', $signature, $matches ) ) {
386386
$parsed_header['(expires)'] = trim( $matches[1] );
387387
}
388388
if ( \preg_match( '/algorithm="(.*?)"/ism', $signature, $matches ) ) {
@@ -434,12 +434,22 @@ public static function get_signed_data( $signed_headers, $signature_block, $head
434434
// created in future
435435
return false;
436436
}
437+
438+
if ( ! array_key_exists( '(created)', $headers ) ) {
439+
$signed_data .= $header . ': ' . $signature_block['(created)'] . "\n";
440+
continue;
441+
}
437442
}
438443
if ( '(expires)' === $header ) {
439444
if ( ! empty( $signature_block['(expires)'] ) && \intval( $signature_block['(expires)'] ) < \time() ) {
440445
// expired in past
441446
return false;
442447
}
448+
449+
if ( ! array_key_exists( '(expires)', $headers ) ) {
450+
$signed_data .= $header . ': ' . $signature_block['(expires)'] . "\n";
451+
continue;
452+
}
443453
}
444454
if ( 'date' === $header ) {
445455
// allow a bit of leeway for misconfigured clocks.

includes/collection/class-interactions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use WP_Error;
55
use WP_Comment_Query;
66

7+
use function Activitypub\object_to_uri;
78
use function Activitypub\url_to_commentid;
89
use function Activitypub\object_id_to_comment;
910
use function Activitypub\get_remote_metadata_by_actor;
@@ -46,7 +47,8 @@ public static function add_comment( $activity ) {
4647
return false;
4748
}
4849

49-
$meta = get_remote_metadata_by_actor( $activity['actor'] );
50+
$actor = object_to_uri( $activity['actor'] );
51+
$meta = get_remote_metadata_by_actor( $actor );
5052

5153
if ( ! $meta || \is_wp_error( $meta ) ) {
5254
return false;

includes/collection/class-users.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Activitypub\Model\Blog_User;
88
use Activitypub\Model\Application_User;
99

10+
use function Activitypub\object_to_uri;
1011
use function Activitypub\url_to_authorid;
1112
use function Activitypub\is_user_disabled;
1213

@@ -136,6 +137,8 @@ public static function get_by_username( $username ) {
136137
* @return \Acitvitypub\Model\User The User.
137138
*/
138139
public static function get_by_resource( $resource ) {
140+
$resource = object_to_uri( $resource );
141+
139142
$scheme = 'acct';
140143
$match = array();
141144
// try to extract the scheme and the host

includes/handler/class-undo.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use Activitypub\Collection\Users;
55
use Activitypub\Collection\Followers;
66

7+
use function Activitypub\object_to_uri;
8+
79
/**
810
* Handle Undo requests
911
*/
@@ -28,10 +30,10 @@ public static function handle_undo( $activity ) {
2830
if (
2931
isset( $activity['object']['type'] ) &&
3032
'Follow' === $activity['object']['type'] &&
31-
isset( $activity['object']['object'] ) &&
32-
filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
33+
isset( $activity['object']['object'] )
3334
) {
34-
$user = Users::get_by_resource( $activity['object']['object'] );
35+
$user_id = object_to_uri( $activity['object']['object'] );
36+
$user = Users::get_by_resource( $user_id );
3537

3638
if ( ! $user || is_wp_error( $user ) ) {
3739
// If we can not find a user,
@@ -40,8 +42,9 @@ public static function handle_undo( $activity ) {
4042
}
4143

4244
$user_id = $user->get__id();
45+
$actor = object_to_uri( $activity['actor'] );
4346

44-
Followers::remove_follower( $user_id, $activity['actor'] );
47+
Followers::remove_follower( $user_id, $actor );
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)