I have an Apache/2.4.6 (CentOS) server with multiple subdomains as ServerAlias in Apache VirtualHost.
something like:
<VirtualHost *:443>
ServerName mydomain.com
ServerAlias a.mydomain.com
ServerAlias b.mydomain.com
Each client company should access through its subdomain and there are different databases for each client company for security, there is a separation of data.
I was alerted by a cyber security expert that there is a vulnerability where a user of one subdomain 'a.mydomain.com' can access another subdomain 'b.mydomain.com' by adding a Host header to the calls from the client to the web server.
At first I tried to get the information in PHP but failed, the PHP doesn't get the headers information. Then I switched to looking for a solution to this situation at the web server level - Apache.
I want to detect and reject when a malicious user tries to fool the server and send the request to another subdomain using a Host Header, in this example, the user should be served by a.mydomain.com and not b.mydomain.com:
curl 'https://a.mydomain.com/users/login' \
-H 'Host: b.mydomain.com' \
--data-raw $'{"email":"[email protected]","password":"*****"}'
A normal call from the client side application looks like this:
curl 'https://a.mydomain.com/users/login' \
--data-raw $'{"email":"[email protected]","password":"*****"}'
I tried RequestHeader unset host
but it doesn't work as I expected.
My expectation was that if the malicious user sent a "Host" header, the server should ignore it. This would cause both culr calls above to be effectively the same.
I think that what happens is that Apache is using the URL in the call, but if there is a "Host" header, it takes precedent and that is what is used and the original domain from the URL is discarded.
If that is the case, then RequestHeader unset host
doesn't send any host to my PHP code, which causes my code to break, as it needs to know which client company is calling it.