Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing IPAddrs to allow_ip #444

Merged
merged 1 commit into from
Oct 29, 2019

Conversation

jdelStrother
Copy link
Contributor

Can we add support for passing IPAddrs directly to allow_ip?

@@ -33,7 +33,7 @@ class Middleware
# Adds an address to the set of IP addresses allowed to access Better
# Errors.
def self.allow_ip!(addr)
ALLOWED_IPS << IPAddr.new(addr)
ALLOWED_IPS << (addr.is_a?(IPAddr) ? addr : IPAddr.new(addr))
Copy link
Contributor

@simi simi Oct 18, 2019

Choose a reason for hiding this comment

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

What about to make it more safe? (code not tested)

case addr
  when String then IPAddr.new(addr)
  when IPAddr then addr
  else raise 'Unknown IP address type. Please specify it as a IPAddr compatible string like "1.1.1.1" or pass IPAddr object.'
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO it doesn't add much since IPAddr will already raise something like IPAddr::AddressFamilyError (address family must be specified) if you pass invalid input. I can add it if you prefer, though.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, it seems like the error raised by IPAddr would be sufficient. But also, this PR doesn't change the way that this error would be raised, currently it doesn't rescue from that error.

Choose a reason for hiding this comment

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

I wasn't able to work past the error in my case without using the wrapped object. Something not liked about my CIDR string, '172.16.0.0/12' is perfectly valid CIDR range though, which can be parsed from web_console.allow_whitelisted_ips for example

I was able to work past it with #444, thanks for merging this, my report is in #451

@RobinDaugherty RobinDaugherty merged commit 5e1d687 into BetterErrors:master Oct 29, 2019
@RobinDaugherty
Copy link
Member

@jdelStrother thanks for your contribution!

kingdonb pushed a commit to kingdonb/micro-swansons that referenced this pull request Feb 22, 2020
BetterErrors/better_errors#444 is not in a
release of the better_errors gem yet (no release since February 2019!)
@RobinDaugherty RobinDaugherty added this to the v2.6 milestone Feb 25, 2020
@jdelStrother jdelStrother deleted the allow-ipaddr branch March 2, 2020 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants