Skip to content

Commit cb35e4f

Browse files
authored
Actors: Don't convert non-numeric strings to Blog user id (#1554)
* Add failing test * Add changelog * Only convert to int when it's numeric * Use strict checks in user_can_activitypub * Revert "Use strict checks in user_can_activitypub" This reverts commit 8de3516. * Bail when user_id is not numeric
1 parent b704d95 commit cb35e4f

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Sites with comments from the Fediverse no longer create uncached extra fields posts that flood the Outbox.

includes/collection/class-actors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Actors {
4646
* @return User|Blog|Application|WP_Error The Actor or WP_Error if user not found.
4747
*/
4848
public static function get_by_id( $user_id ) {
49-
if ( is_string( $user_id ) || is_numeric( $user_id ) ) {
49+
if ( is_numeric( $user_id ) ) {
5050
$user_id = (int) $user_id;
5151
}
5252

includes/functions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,14 @@ function is_post_disabled( $post ) {
329329
/**
330330
* This function checks if a user is enabled for ActivityPub.
331331
*
332-
* @param int $user_id The user ID.
332+
* @param int|string $user_id The user ID.
333333
* @return boolean True if the user is enabled, false otherwise.
334334
*/
335335
function user_can_activitypub( $user_id ) {
336+
if ( ! is_numeric( $user_id ) ) {
337+
return false;
338+
}
339+
336340
switch ( $user_id ) {
337341
case Actors::APPLICATION_USER_ID:
338342
$enabled = true; // Application user is always enabled.

tests/includes/collection/class-test-actors.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public function set_up() {
2727
add_user_meta( 1, 'activitypub_user_identifier', 'admin' );
2828
}
2929

30+
/**
31+
* Test get_by_id.
32+
*
33+
* @covers ::get_by_id
34+
*/
35+
public function test_get_by_id() {
36+
// External user.
37+
$user_id = '[email protected]';
38+
39+
$actor = Actors::get_by_id( $user_id );
40+
$this->assertWPError( $actor );
41+
}
42+
3043
/**
3144
* Test get_by_various.
3245
*

0 commit comments

Comments
 (0)