Issue
- Adjusting the Host header in the request can impact page rendering, redirections, and other server-side behaviors. This manipulation can lead to attacks such as cross-site scripting (XSS).
- If
virtual.hosts.valid.hostsallows a host name that no site or virtual instance uses, a request for it returns the default site instead of an error response.
Environment
- Liferay DXP
Resolution
Liferay comes with a servlet filter for checking valid hosts:
# The valid host name filter will check the host name from request's # host header. It rejects a request with invalid server name to prevent XSS # and other host header manipulation attacks. com.liferay.portal.servlet.filters.validhostname.ValidHostNameFilter=true- You can verify the current value within the Server Administration Panel's Properties → Portal Properties tab by searching for "ValidHostNameFilter"
When the ValidHostNameFilter is enabled (default behavior), it compares the request's host name with domains listed in the
virtual.hosts.valid.hosts property:# Input a list of comma delimited valid domains and IPs that the portal is # allowed to use. #virtual.hosts.valid.hosts=* virtual.hosts.valid.hosts=localhost,127.0.0.1,[::1],[0:0:0:0:0:0:0:1]- The default value depends on the release. Before Liferay 2023.Q3, 7.4 Update 86, or DXP 7.3 Update 34, the default is
*.- A
*configuration accepts any host name, telling the filter to not reject any domains. Later releases accept only localhost and the loopback addresses unless modified.
- A
- To change the list, set
virtual.hosts.valid.hostsin your portal-ext.properties to the domains and IP addresses your portal uses.
- The default value depends on the release. Before Liferay 2023.Q3, 7.4 Update 86, or DXP 7.3 Update 34, the default is
- In addition to Liferay's OOTB security features, you can also implement webserver rules to apply custom configurations. To test configurations, run this curl command and check both your Liferay and webserver logs for more information:
curl -H "Host: http://invalid.host" “http://localhost:8080/”
- To return a 404 page for an invalid host name instead of the default site, set
virtual.hosts.strict.access=truein portal-ext.properties.- On older releases that lack this property, configure the 404 at the webserver tier in front of Liferay.
Additional Information
- The host validator also considers additional factors, such as the instance domain configured in the Liferay administration (Control Panel →System → Virtual Instances → Virtual Host).
- Updated Portal Property Default Values for Virtual Hosts
- Possible Host Header Attack Vulnerability (PaaS)
- portal.properties - Virtual Hosts
- Securing Liferay
- Enabling Strict Virtual Host Mode