Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Domain Name parser based on the Public Suffix List.

Fetching latest commit…

Cannot retrieve the latest commit at this time


Public Suffix Service

Public Suffix Service is a Ruby domain name parser based on the Public Suffix List available at

What is the Public Suffix List?

The Public Suffix List is a cross-vendor initiative to provide an accurate list of domain name suffixes.

The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.

A “public suffix” is one under which Internet users can directly register names. Some examples of public suffixes are “.com”, “” and “”. The Public Suffix List is a list of all known public suffixes.


Why the Public Suffix List is better than any available Regular Expression parser?

Previously, browsers used an algorithm which basically only denied setting wide-ranging cookies for top-level domains with no dots (e.g. com or org). However, this did not work for top-level domains where only third-level registrations are allowed (e.g. In these cases, websites could set a cookie for which will be passed onto every website registered under

Clearly, this was a security risk as it allowed websites other than the one setting the cookie to read it, and therefore potentially extract sensitive information.

Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list of all top-level domains and the level at which domains can be registered. This is the aim of the effective TLD list.

As well as being used to prevent cookies from being set where they shouldn't be, the list can also potentially be used for other applications where the registry controlled and privately controlled parts of a domain name need to be known, for example when grouping by top-level domains.


Not convinced yet? Check out a real world example:


  • Ruby >= 1.8.6 (not tested with previous versions)

Successfully tested against

  • Ruby 1.8.6 / 1.8.7 / 1.9.1

  • MacRuby 0.4

  • Ruby Enterprise Edition


Via RubyGems

$ gem install public_suffix_service

You might need administrator privileges on your system to install it.


Example domain without subdomains.

domain = PublicSuffixService.parse("")
# => "com"
# => "google"
# => nil

Example domain with subdomains.

domain = PublicSuffixService.parse("")
# => "com"
# => "google"
# => "www"

Simple validation example.

# => true

# => true

# => false



Simone Carletti <>


See the CHANGELOG.rdoc file for details.


Copyright © 2009-2010 Simone Carletti, DomainName is released under the MIT license.

Something went wrong with that request. Please try again.