Skip to content

Broken parsing of HTTP headers #39

Description

@abouvier

The parsing of HTTP headers is broken for certain value of Accept-Encoding when Hefur is behind a reverse proxy.

Apache config:

<VirtualHost *:443>
        ServerName tracker.domain.com
        (...)
        <Location />
                ProxyPass http://localhost:6969/
                ProxyPassReverse http://localhost:6969/
                ProxyPreserveHost On
        </Location>
</VirtualHost>

Hefur is launched like this:
$ hefurd -torrent-dir /srv/tracker -bind-addr 127.0.0.1 -reverse-proxy-from 127.0.0.1 -reverse-proxy-header X-Forwarded-For

The problem arise here:

auto headers = request.unparsedHeaders();
auto header = headers.find(REVERSE_PROXY_HEADER);

With qBittorrent, Apache sends the following request to Hefur:

Host: tracker.domain.com
User-Agent: qBittorrent/4.3.9
Accept-Encoding: gzip
X-Forwarded-For: 42.42.42.42
(...)

request.unparsedHeaders() returns all headers and X-Forwarded-For is found.

With Transmission, Apache sends the following request to Hefur:

Host: tracker.domain.com
User-Agent: Transmission/3.00
Accept: */*
Accept-Encoding: deflate, gzip, br, zstd
X-Forwarded-For: 42.42.42.42
(...)

request.unparsedHeaders() returns only Accept: */*

If I remove Accept-Encoding from the request sent by Apache (with RequestHeader unset Accept-Encoding in <Location />), then the request is parsed correctly and the real IP is found, but Hefur crash soon after with:

hefurd[28911]: hefurd: hefur/address.cc:133: hefur::Address& hefur::Address::operator=(const sockaddr*): Assertion 'false' failed.

So an announce request from Transmission seems totally broken: the real IP is not found, the response is bad (wrong values of seeders/leechers) and Transmission try to announce again every 8 seconds in a loop.
Everything is working fine with qBittorrent.

OS: Arch Linux
Hefur: 1.0
Apache: 2.4.51
qBittorrent: 4.3.9
Transmission: 3.00

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions