matomo-org / matomo-org/component-network

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

Open
#8 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
21
Forks
10
PR merge metrics
No merged PRs in 30d

Description

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 `alert("1");`

## 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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading getHostname() in piwik/vendor/piwik/network/src/IP.php and trace how the resolved hostname is returned. Define the accepted hostname characters, including the requested international-domain behavior, and consider how to verify that script-like or other invalid characters cannot be returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
networking, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.