honeybadger-io / honeybadger-php

PHP library for reporting errors to Honeybadger.io :elephant: :zap:
https://www.honeybadger.io/for/php/?utm_source=github&utm_medium=readme&utm_campaign=php&utm_content=website-url
MIT License
37 stars 21 forks source link

Inconsistent reporting of URL port #43

Closed hexpunk closed 6 years ago

hexpunk commented 7 years ago

I'm finding that the URL field of the exceptions that are being reported by this library is inconsistently showing the port. Sometimes it acts like one would expect, showing the port number only when it's not 80 or 443. Sometimes it shows the port even when it's 80. And sometimes, especially when the host is localhost and the port is something unusual like 8090, it reports the port in the url twice, like http://localhost:8090:8090/..., which is of course not a valid URL.

I've tried reproducing this in a controlled scenario with a system I have complete control over and xdebug install on, but I was unable to get the unusual behavior to happen. This seems to only occur in the wild.

sixlive commented 6 years ago

@JayAndCatchFire I would love to get any additional details about this issue. What version of the package are you using? Are you using a specific framework?

We're doing some pretty basic URL formatting and pulling it from the $_SERVER superglobal. (See Environment.php)

We also have some decent test coverage for this scenario (See EnvironmentTest.php).

Since you also state that is inconsistent on your end, I'm thinking that it might be an environmental issue.

Just trying to get some more context so I can do additional testing.

hexpunk commented 6 years ago

Here's my setup:

This is a legacy app. We're not really fully using Zend as designed. The "framework" is a very lightweight bespoke system that's poaching some of Zend's classes. For example, it uses Zend's request and response classes.

hexpunk commented 6 years ago

FWIW, this seems to happen very infrequently. I just went through my HB logs to try to find another example. I had to scour a little bit, but I did find one from 4 months ago.

Here's the environment info from that occurrence. I had to redact the values of several fields, unfortunately, since this comes from proprietary code. I hope this is still helpful. Let me know if there is anything else I can provide that might help.

{
  "PHP_SELF" => "REDACTED",
  "SERVER_NAME" => "0.0.0.0",
  "SERVER_SOFTWARE" => "PHP 5.5.38 Development Server",
  "SERVER_PROTOCOL" => "HTTP/1.1",
  "REQUEST_METHOD" => "POST",
  "REQUEST_TIME" => 1509652553,
  "REQUEST_TIME_FLOAT" => 1509652553.8835,
  "DOCUMENT_ROOT" => "REDACTED",
  "REMOTE_ADDR" => "127.0.0.1",
  "REMOTE_PORT" => "53096",
  "SCRIPT_FILENAME" => "REDACTED",
  "SERVER_PORT" => "8090",
  "SCRIPT_NAME" => "/index.php",
  "REQUEST_URI" => "REDACTED",
  "PATH_INFO" => "REDACTED",
  "HTTP_HOST" => "localhost:8090",
  "HTTP_COOKIE" => "XDEBUG_SESSION=myusername",
  "HTTP_ORIGIN" => "REDACTED",
  "HTTP_ACCEPT_ENCODING" => "gzip, deflate, br",
  "HTTP_SESSION_ID" => "bb8e7d3fe6dcc22c79660d5b27959bb855dc7417b520b966f7c09f82d5fcb1e8e1faba7c3b7ef1c6bab4c67e",
  "HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.9",
  "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36",
  "HTTP_CONTENT_TYPE" => "multipart/form-data; boundary=X-INSOMNIA-BOUNDARY",
  "HTTP_ACCEPT" => "*/*",
  "HTTP_REFERER" => "REDACTED",
  "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
  "HTTP_CONNECTION" => "keep-alive",
  "HTTP_ACCEPT_VERSION" => "v1",
  "HTTP_DNT" => "1",
  "HTTP_CONTENT_LENGTH" => "2903"
}
sixlive commented 6 years ago

Ah, I see why. Looking at the environment you sent the port is being included in both the SERVER_PORT and HTTP_HOST.

I've created a fix for this and will tag it in the release of #52.

sixlive commented 6 years ago

@JayAndCatchFire fix included in https://github.com/honeybadger-io/honeybadger-php/releases/tag/v0.4.1