Add HTTP.blocklist for denying requests by IP/host - #844
Open
benubois wants to merge 1 commit into
Open
Conversation
Adds an opt-in blocklist that raises HTTP::BlockedHostError if the request resolves to a host or IP address which is on the list.
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.
Hello,
This adds a blocklist option, which raises
HTTP::BlockedHostErrorif the request resolves to an IP or host which is blocked.This supports:
IPAddrfor IP addresses. CIDR is fine too likeIPAddr.new("127.0.0.0/8")Stringfor matching hostnames host and its subdomains (for example if you blockinternal.example.com,db.internal.example.comwill also be blocked.deny:receives each resolved address as anIPAddrand blocks it by if it returnstrueAlso available as a constructor and per-request option:
Limitations
A blocklist cannot be enforced through a proxy. The proxy resolves the target and makes the connection, so the addresses checked locally are not necessarily the ones reached. The risk here is probably limited to DNS rebinding
No Happy Eyeballs for blocklisted requests. Since the address is validated up front the OS cannot try each one if multiple addresses are returned
Example Use Case
Currently Mastodon uses
http, but does its own DNS resolution and blocking. With this feature built in to http, all of this could become something likeThanks!