BetterErrors / better_errors

Better error page for Rack apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A CIDR range cannot be automatically parsed from string in the config

kingdonb opened this issue · comments

I am attempting to use better_errors with the latest released versions of ruby and rails, at this time 2.7.0 and 6.0.2.1, and I thought I needed a little help from #444 which is only in the master branch (but not released)

This PR was made to permit calling allow_ip! with an IPAddr as CIDR, as it seems you can't just pass in a valid IPv4 CIDR as a string anymore like the first examples in the Wiki documentation,

IPAddr::AddressFamilyError: address family must be specified

I tried that, specifying address family, it didn't work either, even with #444 - this setting is alongside of web_console.whitelisted_ips setting which does seem to accept the CIDR string without issues. I then made my IP Address spec for BetterErrors as fully-qualified as possible, and the assignment succeeds against the master branch at 5e1d687, as below (however):

  config.web_console.whitelisted_ips = '172.16.0.0/12'
  BetterErrors::Middleware.allow_ip! IPAddr.new('172.16.0.0/12', Socket::AF_INET)

The setting works as above, but passing the unwrapped string results in the IPAddr::AddressFamilyError for some reason. It doesn't seem like there should be a problem parsing this string.

In spite of this, I am still seeing the web console from my 172.16.x.x private address on the other side of Docker bridge. I'd guess whatever issue is responsible for failure to parse the address string is the same issue preventing me from accessing this way, but that'd be a wild guess.

(Actually, I tested setting my IP address with a specific IPv4 string '172.19.0.1' and it was accepted as valid input for the allow_ip! method, but I still see web_console instead. If I remove the address from web_console whitelisted_ips, I still get the classic red Rails development error trace page, no better_errors. If I trigger an error from 127.0.0.1, it works - I see better_errors.)

Without this, I can't find a way to use docker and better_errors together.

I just learned that RoutingError always displays the classic red Rails error page, no matter what, with the route list (so you can figure out what route you meant to reach, duh.)

The issue here (I've edited above, to cross out the problems I am not having anymore) is that an IPv4 CIDR string is not accepted without wrapping it in a IPAddr object, which #444 was submitted to ensure is possible.

Could you share a stacktrace of the error you're seeing? And what ruby version are you using?

With BetterErrors 5e1d687 and ruby 2.6.3, all of these seem to work for me:

  BetterErrors::Middleware.allow_ip! IPAddr.new('192.168.0.0/16')
  BetterErrors::Middleware.allow_ip! '192.168.1.2'
  BetterErrors::Middleware.allow_ip! '192.168.0.0/16'

It seems likely I was conflating two issues and somehow confused about whether I'd solved the first, or the second, or both...

I'm not able to repro AddressFamilyError anymore, this works fine:

BetterErrors::Middleware.allow_ip! '172.16.0.0/12'

Closing, thanks for responding. I guess that #444 fixed it!