<?xml version="1.0" ?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:planet="http://planet.intertwingly.net/"><id>tag:ldpreload.com,2015-11-26:/blog/names-to-reserve</id><link href="https://ldpreload.com/blog/names-to-reserve" rel="alternate" type="text/html"/><title>Hostnames and usernames to reserve</title><summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>If you're setting up a service where people can register their own usernames to be used as a hostname (<code>username.example.com</code>), email address (<code>username@example.com</code>), or URL path (<code>example.com/username</code>) within your domain, there are some common names you should avoid letting the general public register.</p>
<p>Many …</p></div></summary><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>If you're setting up a service where people can register their own usernames to be used as a hostname (<code>username.example.com</code>), email address (<code>username@example.com</code>), or URL path (<code>example.com/username</code>) within your domain, there are some common names you should avoid letting the general public register.</p>
<p>Many Internet protocols make the assumption that a domain is manually managed by its owners, and in particular assume that a name like <code>admin</code> must have been registered or approved by the actual owners. Automatic registration breaks this assumption, and has been the source of some attacks. Microsoft Live has fallen victim to this multiple times: in 2008, <a href="http://www.theregister.co.uk/2011/04/11/state_of_ssl_analysis/">a researcher signed up for <code>sslcertificates@live.com</code> and used it to get a login.live.com certificate</a>, and as late as this March, the same problem happened to live.fi, the Finnish version of the service, when <a href="http://www.tivi.fi/Kaikki_uutiset/2015-03-18/A-Finnish-man-created-this-simple-email-account---and-received-Microsofts-security-certificate-3217662.html">an IT professional tried registering the email account <code>hostmaster@live.fi</code></a> as his personal Live account, and then found he could receive a certificate for that domain.</p>
<p>This is a list of all the names I know that should be restricted from registration in automated systems. If you know of others, please let me know and I'll update this page.</p>
<p><strong>tl;dr:</strong> Regardless of how you're currently using usernames, restrict them to lowercase letters, digits, and hyphens, starting with a letter and not ending with a hyphen (that is, <code>/^[a-z]([a-z0-9-]*[a-z0-9])?$/</code> as an extended regex). Ban <a href="https://ldpreload.com/files/names-to-reserve.txt">all the names in this file</a> (last updated 2015-11-21). Get yourself listed as a public suffix: see below for directions and implications.</p>
<h2>Hostnames</h2>
<p>Most of these problems involve a computer on the domain doing an unqualified lookup: when a computer named <code>a.example.com</code> looks for <code>b</code>, it will usually find <code>b.example.com</code>. If you're running a simple hosting service, or similar, you may not need to block all of these, but these names are extremely unlikely to be used by legitimate users anyway. So you may as well block all of them to allow expanding in the future.</p>
<ul>
<li><strong><code>localhost</code></strong>, <strong><code>localdomain</code></strong>, and <strong><code>broadcasthost</code></strong>: these are <em>usually</em> present in <code>/etc/hosts</code>, and applications or scripts might hard-code an assumption about them having their usual value (especially for <code>localhost</code>).</li>
<li><strong><code>www</code></strong>: Browsers will often prepend this if the domain itself does not resolve as a hostname.</li>
<li><strong><code>wpad</code></strong>: <a href="https://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol">Web Proxy Auto-Discovery</a> in several browsers; someone who owns this (unqualified) name can act as a proxy for all web traffic.</li>
<li><strong><code>isatap</code></strong>: <a href="https://en.wikipedia.org/wiki/ISATAP">IPv6 tunnel autodiscovery</a>, primarily on Windows. Similarly to WPAD, someone who owns this (unqualified) name can act as a proxy for all IPv6-capable traffic. Windows Server has a <a href="https://technet.microsoft.com/en-us/library/cc794902.aspx">built-in blacklist of domain names</a> that defaults to <code>WPAD</code> and <code>ISATAP</code>.</li>
<li><strong><code>autoconfig</code></strong>: <a href="https://wiki.mozilla.org/Thunderbird:Autoconfiguration">Thunderbird's spec for autoconfiguration</a>. Thunderbird will query the website at <code>autoconfig.example.com</code> for settings when attempting to set up <code>example.com</code> email. Good way to harvest passwords.</li>
<li>Along those lines, <strong><code>imap</code></strong>, <strong><code>pop</code></strong>, <strong><code>pop3</code></strong>, <strong><code>smtp</code></strong>, <strong><code>mail</code></strong>, for email clients that make guesses about what your email servers are. (This includes Thunderbird but also many others.)</li>
</ul>
<p>Note that valid hostnames are <a href="https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">restricted in syntax</a>: they must only contain letters, digits, or hyphens, and cannot start or end with a hyphen. DNS is case-insensitive, so make sure there are no case collisions. An older standard prevents hostnames from starting with a digit, which is a straightforward way to prevent all-numeric usernames (which can cause <a href="https://debathena.mit.edu/trac/ticket/367">problems with tools that accept either names or UIDs</a>). Dots separate portions of a domain name and cause various problems (wildcard certificates only apply to one level, <code>a.b.example.com</code> can read and write cookies for <code>b.example.com</code>, etc.), so they're usually more trouble than they're worth. <em>DNS records</em> are much more liberal, but names that don't follow these rules will generally not resolve as hostnames: you can look them up with <code>dig</code>/<code>host</code>/etc., but you can't use them in applications. Checking hostname syntax also prevents you from worrying about names like <strong><code>_tcp</code></strong> or <strong><code>_udp</code></strong>, which are used in <a href="https://en.wikipedia.org/wiki/SRV_record">SRV records</a>.</p>
<h3>Become a public suffix</h3>
<p>Most parts of the web platform consider two pages with different <em>origins</em>, that is, scheme (<code>http</code> / <code>https</code>), hostname, and port number, to be unrelated websites that cannot interact with each other by default. However, there are a few exceptions, most notably cookies. Web pages at <code>www.example.com</code> and <code>login.example.com</code> are allowed to set cookies with a scope of <code>example.com</code>, despite not sharing the same hostname / origin. The simple rule of allowing parent domains created the problem of <a href="https://en.wikipedia.org/wiki/HTTP_cookie#Supercookie">supercookies</a>: <code>example.com</code> could set a cookie scoped to <code>.com</code>, which would then be sent to all sites ending in <code>.com</code>. There are two big problems with this: the first is privacy (being tracked across websites), and the second is <a href="https://en.wikipedia.org/wiki/Session_fixation#Attacks_using_cross-subdomain_cookie">session-fixation attacks</a>, where an attacker can overwrite your session cookie with their own, and have your actions (including logging in or sending private data) happen within the attacker's session.</p>
<p>The immediate fix was to ban top-level domains, but this still allowed setting cookies for publicly-registrable suffixes like <code>.co.uk</code> that weren't at the top level. So browser vendors created the <a href="https://publicsuffix.org/">public suffix list</a> to track which suffixes are open for public registration. The public suffix list now includes not only &quot;ICANN&quot; entries, such as <code>.com</code> and <code>.co.uk</code>, but also &quot;private&quot; entries, such as <code>.herokuapp.com</code> and <code>.github.io</code>, since the same problems exist with allowing users to set cookies for all Heroku or GitHub Pages users.</p>
<p>So, if you are letting users register hostnames in your domain, you should <a href="https://publicsuffix.org/submit/">get it listed as a public suffix</a>, which requires just sending a pull request or an email. It takes some time for the update to reach browsers (the list is compiled into browsers, so it's only updated by a browser version update), so you should try to do this as far in advance as possible before launching.</p>
<p>Note that by making <code>example.com</code> a public suffix, nobody, <strong>not even code on <code>example.com</code> itself</strong>, can set a cookie for <code>example.com</code>. If you have a website of your own that needs cookies (analytics, registration, etc.), you'll need to run it at e.g. <code>www.example.com</code>, and make <code>example.com</code> just a redirect. Alternatively, you can use a completely separate domain for your own site vs. your users' sites, as with the Heroku and GitHub examples: their own websites are <code>heroku.com</code> and <code>github.com</code>.</p>
<h2>Email addresses</h2>
<p>The <a href="https://cabforum.org/baseline-requirements-documents/">CA/Browser Forum Baseline Requirements</a>, section 3.2.2.4 item 4, requires that if a CA is going to validate a domain by coming up with an administrative email address on its own, it may only use <strong><code>admin</code></strong>, <strong><code>administrator</code></strong>, <strong><code>webmaster</code></strong>, <strong><code>hostmaster</code></strong>, or <strong><code>postmaster</code></strong>. Reserve all of those names, regardless of whether they go somewhere useful.</p>
<p>All CAs are supposed to be compliant with that these days, but for safety's sake, also reserve <strong><code>root</code></strong>, <strong><code>info</code></strong>, <strong><code>ssladmin</code></strong>, <strong><code>ssladministrator</code></strong>, <strong><code>sslwebmaster</code></strong>, <strong><code>sysadmin</code></strong>, <strong><code>is</code></strong>, <strong><code>it</code></strong>, and <strong><code>mis</code></strong> (see this <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=477783#c19">2009 comment on Mozilla's bug tracker</a>).</p>
<p><a href="https://tools.ietf.org/html/rfc2142">RFC 2142</a> defines the names <code>info</code>, <strong><code>marketing</code></strong>, <strong><code>sales</code></strong>, <strong><code>support</code></strong>, <strong><code>abuse</code></strong>, <strong><code>noc</code></strong>, <strong><code>security</code></strong>, <code>postmaster</code>, <code>hostmaster</code>, <strong><code>usenet</code></strong>, <strong><code>news</code></strong>, <code>webmaster</code>, <code>www</code>, <strong><code>uucp</code></strong>, and <strong><code>ftp</code></strong>. You won't need most of these to actually reach a useful mailbox, though you should reserve all of them.</p>
<p>You may want to reserve <strong><code>mailer-daemon</code></strong>, <strong><code>nobody</code></strong> (a default UNIX user account), <strong><code>noreply</code></strong>, <strong><code>no-reply</code></strong>, etc. for automated processes that send email.</p>
<p>Again, as these names are unlikely to be used by legitimate users, it's usually worth blocking them now and keeping your options open, even if you're not currently offering email service. You may add an email service in the future (Amazon launched <a href="http://www.amazon.com/gp/sendtokindle/email">Send to Kindle by email</a> over a decade after introducing user accounts). As always, you can <em>manually</em> register these names to trusted or internal users.</p>
<h2>URLs</h2>
<p>For many websites with user-provided content, like Twitter, Facebook, or GitHub, user-chosen usernames become part of the URL at top level (<code>https://twitter.com/geofft</code>, <code>https://github.com/geofft</code>). If you're building a website like this, the easiest approach is to restrict these usernames as if they were hostnames. This has two advantages: the first is that it's easy to launch a hostname-based system later (e.g. GitHub Pages now supports <code>geofft.github.io</code>) if you know that all your usernames are valid hostnames.</p>
<p>The second is that there are several URL paths you need to reserve at top level, and all of them happen to contain dots and are therefore invalid hostnames. If you do permit dots, you need to block the following names:</p>
<ul>
<li><strong><code>robots.txt</code></strong>, for the <a href="http://www.robotstxt.org/">Robots Exclusion Protocol</a>, used to tell well-behaved crawlers how to well-behave.</li>
<li><strong><code>favicon.ico</code></strong>, for the <a href="https://en.wikipedia.org/wiki/Favicon">shortcut icon</a> displayed in the tab bar and other places.</li>
<li><strong><code>crossdomain.xml</code></strong>, which allows <a href="https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html">the Flash plugin to make cross-origin requests</a>. Java and Silverlight also look for and trust <code>crossdomain.xml</code>.</li>
<li><strong><code>clientaccesspolicy.xml</code></strong>, a <a href="https://msdn.microsoft.com/library/cc197955(v=vs.95).aspx">Silverlight-specific version</a> of <code>crossdomain.xml</code>.</li>
<li><strong><code>.well-known</code></strong>, specified in <a href="https://tools.ietf.org/html/rfc5785">RFC 5785</a> as a place for these sorts of things so they don't keep cluttering the root level. Thunderbird autoconfiguration looks in here, as do <a href="https://tools.ietf.org/html/draft-barnes-acme-04">ACME</a>, the automatic certificate enrollment spec from <a href="https://letsencrypt.org">Let's Encrypt</a>; <a href="https://github.com/mozilla/id-specs/blob/prod/browserid/index.md">BrowserID</a> / Mozilla Persona; and <a href="http://tools.ietf.org/html/rfc7711">RFC 7711</a>, a new standard for providing certificates for third-party non-HTTP services. So there are a number of security issues with an unauthorized user being able to create files under <code>/.well-known/</code>.</li>
</ul>
<p>(These are URLs, not filenames. You should of course also disallow users from creating files named e.g. <code>.htaccess</code> if your web server respects those.)</p>
<p>All of these are invalid hostnames, so simply requiring usernames to be valid hostnames avoids having to check for these specific cases. If you're only allowing users to choose some portion of the URL, and inserting other text (e.g., <code>example.com/user/geofft</code>, <code>example.edu/~geofft</code>), then you don't have to worry about this, but again it may still be useful to keep your options open for other URL, hostname, or email schemes in the future.</p>
<p>Do not allow users to publish custom HTML, <em>especially</em> not custom scripts, at these sorts of URLs. <code>https://example.com/user1</code>, <code>https://example.com/user2</code>, and <code>https://example.com/login</code> all share the same origin, so by the <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">same-origin policy</a>, these web pages can freely interact with each other and mess with each other's content. A few JavaScript interfaces, including <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API">service workers</a>, make it very easy to attack another site on the same origin. If you want users to be able to publish custom HTML and JS, use separate hostnames within a public suffix. <code>https://user1.example.com</code> and <code>https://user2.example.com</code> are separate origins, and if you have made <code>example.com</code> a public suffix as mentioned earlier, you can safely let them publish custom scripts, since the sites are no more able to interact with each other than two separate <code>.com</code> websites could.</p>
<p><em>This post was inspired by <a href="https://github.com/sandstorm-io/sandcats/issues/43">a GitHub issue</a> for <a href="https://docs.sandstorm.io/en/latest/administering/sandcats/">Sandstorm's sandcats.io dynamic DNS service</a>; thanks to <a href="http://asheesh.org">Asheesh Laroia</a> for pointing me at that thread and reviewing a draft of this article.</em></p></div></content><updated planet:format="November 26, 2015 12:00 AM">2015-11-26T00:00:00Z</updated><published planet:format="November 26, 2015 12:00 AM">2015-11-26T00:00:00Z</published><category term="misc"/><author><name>Geoffrey Thomas</name></author><source><id>https://ldpreload.com/</id><link href="https://ldpreload.com/" rel="alternate" type="text/html"/><link href="https://ldpreload.com/feeds/all.atom.xml" rel="self" type="application/atom+xml"/><title>Geoffrey Thomas (geofft)</title><updated planet:format="December 18, 2018 12:00 AM">2018-12-18T00:00:00Z</updated><planet:bozo>false</planet:bozo><planet:format>atom10</planet:format><planet:items_per_page>60</planet:items_per_page><planet:http_etag>W/&quot;17ae121ba4ef3cf4c16eb98b537048cc&quot;</planet:http_etag><planet:encoding>utf-8</planet:encoding><planet:name>Geoffrey Thomas</planet:name><planet:css-id>geoffrey-thomas</planet:css-id><planet:days_per_page>0</planet:days_per_page><planet:http_last_modified>Tue, 27 Aug 2024 18:24:01 GMT</planet:http_last_modified><planet:http_status>200</planet:http_status></source></entry>