Jonathan Roes home

Rack::RBL

October 16, 2009

photo credit sbest2048 @ flickr

Here’s my (first) entry into the coderack.org Rack middleware contest. It’s a Rack middleware that will respond with a 403 (Forbidden) when a connecting client is listed in an RBL.

An RBL or DNSBL is a list of malicious internet hosts. Usually, mail server administrators configure their servers to reject connections from hosts that are on an RBL to prevent spam. The lists are published using DNS. To look up an IP address in an RBL, you just reverse the IP address octets and prepend them to a RBL server hostname, then perform a DNS query. For example, if you want to find out if Google (74.125.67.100) is listed in the RBL at dnsbl.ahbl.org, you can look it up with:

[~] host 100.67.125.74.dnsbl.ahbl.org
Host 100.67.125.74.dnsbl.ahbl.org not found: 3(NXDOMAIN)

I wrapped this functionality up into a sweet little Rack middleware you can play with. It needs to do some caching and maybe even spawn some procs to avoid slowing down a real production server though.