Skip to content

Validate IP before resolving comment author domain#2342

Merged
pfefferle merged 6 commits intotrunkfrom
fix/ip-addr
Oct 20, 2025
Merged

Validate IP before resolving comment author domain#2342
pfefferle merged 6 commits intotrunkfrom
fix/ip-addr

Conversation

@pfefferle
Copy link
Copy Markdown
Member

@pfefferle pfefferle commented Oct 20, 2025

Added a check to ensure the comment author's IP address is present and valid before attempting to resolve the hostname with gethostbyaddr. This prevents potential errors when the IP is missing or invalid.

Fixes https://wordpress.org/support/topic/php-error-warning-17/

Proposed changes:

  • Added IP validation using filter_var() with FILTER_VALIDATE_IP before calling gethostbyaddr()
  • Initialized $comment_author_domain variable to an empty string as a fallback
  • Wrapped the hostname resolution in a conditional check to ensure it only runs with valid IPs

Other information:

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

Testing instructions:

  • Go to '..'

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

Added a safety check to prevent errors when resolving comment author hostnames without a valid IP address.

Added a check to ensure the comment author's IP address is present and valid before attempting to resolve the hostname with gethostbyaddr. This prevents potential errors when the IP is missing or invalid.
Copy link
Copy Markdown

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

This PR adds IP validation before attempting hostname resolution to prevent PHP warnings when the comment author's IP address is missing or invalid.

  • Added IP validation using filter_var() with FILTER_VALIDATE_IP before calling gethostbyaddr()
  • Initialized $comment_author_domain variable to an empty string as a fallback
  • Wrapped the hostname resolution in a conditional check to ensure it only runs with valid IPs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pfefferle pfefferle marked this pull request as ready for review October 20, 2025 12:53
@pfefferle pfefferle requested a review from obenland October 20, 2025 12:53
obenland
obenland previously approved these changes Oct 20, 2025
Copy link
Copy Markdown
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

I think this is good to go as-is.

There are two optional, OCD-satisfying suggestions if you feel inclined, but I consider them optional.

Co-authored-by: Konstantin Obenland <[email protected]>
pfefferle and others added 3 commits October 20, 2025 16:16
Co-authored-by: Konstantin Obenland <[email protected]>
Prefixed filter_var with a backslash to ensure the global PHP function is used when validating IP addresses in the Mailer class.
@pfefferle pfefferle requested a review from obenland October 20, 2025 14:17
Copy link
Copy Markdown
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

💖

@pfefferle pfefferle merged commit 832b505 into trunk Oct 20, 2025
13 checks passed
@pfefferle pfefferle deleted the fix/ip-addr branch October 20, 2025 14:49
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.

4 participants