Skip to content

Conversation

stayallive
Copy link
Collaborator

We could throw an exception if a IP address is invalid or an empty string. Capture and ignore the exception since we can just continue without it.

As reported: getsentry/sentry-php#1750 (comment)

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

This PR adds exception handling for invalid IP addresses when setting user IP data from HTTP requests. The change prevents crashes when getClientIp() returns invalid IP addresses or empty strings by catching InvalidArgumentException and continuing execution without setting the IP address.

  • Added try-catch block around setIpAddress() call to handle invalid IP address exceptions
  • Added test case for empty remote address scenario
  • Updated PHPStan baseline to account for new test case

Reviewed Changes

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

File Description
src/EventListener/RequestListener.php Added exception handling around IP address setting to prevent crashes from invalid IPs
tests/EventListener/RequestListenerTest.php Added test case to verify behavior with empty remote address
phpstan-baseline.neon Updated count for undefined constant usage in tests

@stayallive stayallive merged commit 1d1686c into master Jul 30, 2025
39 checks passed
@stayallive stayallive deleted the empty-ip-fix branch July 30, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants