Skip to content

getHostname() ensure the returned hostname does only contain characters, digits, hypen and dots (security) #8

@mattab

Description

@mattab

This was reported by email by a security researcher:

  • The getHostname() function in piwik/vendor/piwik/network/src/IP.php does not sanitize the hostname before returning the value.

As described by another security researcher here, http://zoczus.blogspot.sg/2014/05/how-reverse-dns-can-help-us-with-xss.html, an attacker will need to be in control of an IP address where he can set the RDNS hostname to return JS script tags. After that, the attacker tunnels his traffic through that IP address and visits the target site. The getHostname() function will then resolve the IP address and obtain the JS code. Since it is not sanitized, any function which directly stores or displays the hostname will be susceptible to XSS.

The idea is to prevent the function from returning a special string which would trigger an XSS attack, for example <script>alert("1");</script>

Solution

According to RFC1123, valid hostnames can consist of only letters, digits and hyphens. Hence, valid RDNS names should only consist of letter, digits, hyphens and dots. It should thus be possible to sanitize the input to remove all other invalid characters without breaking RDNS resolution for legitimate hosts.

Our solution should also accept international / unicode domains in case the hostname would contain non english characters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions