Skip to content

Interactions: Don't (always) accept empty names #1811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025
Merged

Conversation

obenland
Copy link
Member

image

Proposed changes:

  • Looks for an actual name or preferredUsername, rather than just the key being present.
  • Checks require_name_email option before rejecting a likes, comments, or reposts.
  • Falls back to "Anonymous" of no-name comments are allowed.
  • Adds tests.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Likes, comments, and reposts from the Fediverse now require either a name or preferredUsername to be set when the Discussion option require_name_email is set to true. It falls back to "Anonymous", if not.

@obenland obenland requested review from pfefferle and Copilot June 12, 2025 20:28
@obenland obenland self-assigned this Jun 12, 2025
@obenland obenland changed the title Interactions: Don't accept empty ~~promises~~ names Interactions: Don't accept empty names Jun 12, 2025
@obenland obenland changed the title Interactions: Don't accept empty names Interactions: Don't (always) accept empty names Jun 12, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Enhance comment author handling by requiring a non-empty name or preferredUsername (when configured), falling back to "Anonymous" otherwise, and adding tests for these behaviors.

  • Enforce non-empty name or preferredUsername, and reject anonymous comments if require_name_email is enabled
  • Use "Anonymous" fallback for comments when names are allowed but missing
  • Add unit tests covering all author name scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/includes/collection/class-test-interactions.php New tests for activity_to_comment author logic, including rejection and fallback
includes/collection/class-interactions.php Updated activity_to_comment to validate non-empty actor names and handle anonymous fallback
Comments suppressed due to low confidence (1)

tests/includes/collection/class-test-interactions.php:592

  • The docblock declares $response as bool, but the callback actually returns an array of metadata. Update the @param type to array|string[].
@param bool   $response The value to return instead of the remote metadata.

@@ -261,7 +264,7 @@ public static function activity_to_comment( $activity ) {
}

$comment_data = array(
'comment_author' => \esc_attr( $comment_author ),
'comment_author' => $comment_author ?? __( 'Anonymous', 'activitypub' ),
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore sanitization on comment_author (e.g., wrap in esc_attr()) to prevent unsanitized user input from being stored or output.

Suggested change
'comment_author' => $comment_author ?? __( 'Anonymous', 'activitypub' ),
'comment_author' => \esc_attr( $comment_author ?? __( 'Anonymous', 'activitypub' ) ),

Copilot uses AI. Check for mistakes.

@obenland obenland merged commit 500ddf7 into trunk Jun 16, 2025
14 of 15 checks passed
@obenland obenland deleted the update/comment-name branch June 16, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants