Validate IP before resolving comment author domain#2342
Merged
Conversation
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.
There was a problem hiding this comment.
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()withFILTER_VALIDATE_IPbefore callinggethostbyaddr() - Initialized
$comment_author_domainvariable 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.
obenland
previously approved these changes
Oct 20, 2025
Member
obenland
left a comment
There was a problem hiding this comment.
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]>
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
filter_var()withFILTER_VALIDATE_IPbefore callinggethostbyaddr()$comment_author_domainvariable to an empty string as a fallbackOther information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Added a safety check to prevent errors when resolving comment author hostnames without a valid IP address.