Legacy Knowledge Base
Publicado Jul. 25, 0002

Preventing host header attacks and stopping invalid host headers returning the default site

Written By

Jordi Rodó

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

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.hosts allows 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.
    • To change the list, set virtual.hosts.valid.hosts in your portal-ext.properties to the domains and IP addresses your portal uses.
  • 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=true in portal-ext.properties.
    • On older releases that lack this property, configure the 404 at the webserver tier in front of Liferay.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base