I am using wildcard subdomains to give each of our users a page username.domain.com.
The usernames themselves are properly sanitized on signup.
To simplify things for the purposes of this question, assume I have a single PHP script that runs for all requests. It gets the domain components using...
$domain_components = explode( '.', $_SERVER['SERVER_NAME'] );
... and then pops off the tld, the primary domain and the subdomain.
The question is, do I need to treat the contents of the $_SERVER['SERVER_NAME']
variable, and in particular the domain components, as potentially hostile? Intuitively, I would think not since PHP and Apache must be doing as good a job as I could do before this ever reaches my code (and this answer seems to confirm it since the variable is under server control), but I would like to be sure that I'm not overlooking anything.
Do you know of any known attacks via $_SERVER['SERVER_NAME']
?
(I'm using PHP 5.3.9 and Apache 2.2.3.)