Hledger: [hledger-web] Lacking IPv6 support

Created on 5 Dec 2019  路  2Comments  路  Source: simonmichael/hledger

Hello, I'm trying out hledger (considering migrating from GnuCash) and found lack of IPv6 support in hledger-web's server to be an issue.

It's possible that the changes are minima, but I understand that everything is work :-). Just opening to document it.

Cheers and thank you.

Further information:

> uname -oprb
FreeBSD 13.0-CURRENT amd64 5b8f656016fa216bb99a3853141b8d4d9eb9b6de
> hledger-web --version
hledger-web 1.16.1
> hledger-web --serve --host '::1' --port 8080
hledger-web: --host requires an IP address, not "::1" (use -h to see usage)
A BUG web

Most helpful comment

Thanks for the report.

All 2 comments

Thanks for the report.

I'll try to solve this issue.

The error itself comes from the function checkWebOpts, where the value of the host option is checked against ".0123456789".
This is basically a whitelist for allowed characters, but it does not prevent hosts like 999.999.999.999, which will crash when Network.Socket.getAddrInfo uses it.

Adding : to the whitelist allows ::1 as host, but browser access won't work, as IPv6 addresses need to be surrounded by brackets like http://[::1]/.

Calling hledger-web with the modified whitelist like this:

hledger-web --host ::1 --base-url=http://[::1]:5000

gives a simple workaround, but still launches the wrong URL in the browser.

Basically, to solve this issue, I'd try the following steps:

  1. Generally allow IPv6 addresses (e.g. by adding : or checking the address with other means)
  2. Depending on the IP version, switch to a default base-url that uses brackets

As a first step, I'll just add : to the whitelist and check for that to change the base-url, but it might be sane to use something that completely validates the IP address.

I'll open a PR as soon as I've made progress.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lucianf picture lucianf  路  8Comments

cwarden picture cwarden  路  4Comments

varac picture varac  路  9Comments

cdepillabout picture cdepillabout  路  7Comments

adityag81 picture adityag81  路  5Comments