-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Hostname route ignore HTTP_HOST and give SERVER_NAME precedence #4581
Conversation
In nginx for example the SERVER_NAME is the first value which is configured after server_name for example: server_name server1.com server2.com serverN.com SERVER_NAME in php env will be server1.com While HTTP_HOST will be the requested URL
To clear the "problem" about spoofing: The general problem is, that HTTP_HOST can contain any value the user supplies (it's simply not trust-able). This is not a real problem here though, since we have two things we know:
The only problem we have is if the developer uses the request object to output the HTTP_HOST in a view or so, and it is spoofed with JavaScript code or such. But that is usual output escaping. I would only suggest one thing, to make sure we don't let any invalid HTTP_HOST through: Within the @weierophinney: Any thoughts about it? |
@mbn18 I talked with @weierophinney about this at DPC. The way I suggested would be fine to him (including the validation). Would you be able to to this until Monday or Tuesday? |
@DASPRiD Yes, will spare some time tomorrow. But first will try to catch you on the IRC |
Added test for spoofed HTTP_HOST
Ok, I added a hostname validator and splited the elseif from its chain. Also added a malformed test |
array( | ||
'allow'=>\Zend\Validator\Hostname::ALLOW_ALL, | ||
'useIdnCheck'=>false, | ||
'useTldCheck'=>false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add spaces around the =>
operator.
Hostname route ignore HTTP_HOST and give SERVER_NAME precedence
- Import hostname validator - CS around arguments for hostname validator constructor - Added zend-validator to required components, as it's used for hostname validation
All feedback I provided was incorporated during merge. |
Hostname route ignore HTTP_HOST and give SERVER_NAME precedence
- Import hostname validator - CS around arguments for hostname validator constructor - Added zend-validator to required components, as it's used for hostname validation
Web servers that are configured to accept more then one name for a virtual host, pass the following variables:
SERVER_NAME - the virtual host primary name
HTTP_HOST - the requested domain in the URL
As discussed with @DASPRiD, HTTP_HOST need to be checked first to verify what domain was asked by the client.
@weierophinney raised concern about the host header being spoofed. The Q is, even if so, do we have an alternative?
Extra info about the subject:
http://shiflett.org/blog/2006/mar/server-name-versus-http-host