Skip to content

Bug: nextcloud-domain.sh stores unvalidated HTTP responses in trusted_domains #2167

Open

Description

@nodeam

System information

Relevant, privacy-filtered output from ncp-report:

NextcloudPi version  v1.59.0
NextcloudPi image    NextcloudPi_lxc_04-08-25
OS                   Debian GNU/Linux 13 (trixie), 7.0.14-30-pve (x86_64)
Nextcloud check      ok
Nextcloud version    34.0.6.2
HTTPD service        up
PHP service          up
MariaDB service      up
Redis service        up
Internet check       ok

Environment:

  • Unprivileged Proxmox LXC container
  • PHP 8.5.12
  • Caddy reverse proxy
  • AdGuard Home for DNS filtering

The complete diagnostic report is omitted because it contains private network addresses, domains, hostnames, certificate information and unrelated application logs.

Description

The NextcloudPi script nextcloud-domain.sh retrieves public IPv4 and IPv6 addresses from icanhazip.com and writes the responses directly into Nextcloud's trusted_domains configuration.

The script only checks whether each response is non-empty. It does not verify that the returned value is a valid IP address.

In my installation, an HTML redirect response was written into trusted_domains instead of an IPv4 address.

Relevant code

File: /usr/local/bin/nextcloud-domain.sh

pub_ipv4="$(curl -4 -m4 icanhazip.com 2>/dev/null)"
pub_ipv6="$(curl -6 -m4 icanhazip.com 2>/dev/null)"

[[ -z "$pub_ipv4" ]] || ncc config:system:set trusted_domains 11 --value="$pub_ipv4"
[[ -z "$pub_ipv6" ]] || ncc config:system:set trusted_domains 12 --value="[$pub_ipv6]"

Actual behavior

An HTML document containing an HTTP 302 redirect to https://icanhazip.com/ was stored in trusted_domains[11].

Example of the observed response, abbreviated:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>302 Found</title></head>
<body>
<h1>Found</h1>
<p>The document has moved
<a href="https://icanhazip.com/">here</a>.</p>
</body>
</html>

The exact circumstances that caused the redirect were not fully established.

However, the script allows arbitrary non-empty responses to be written into the Nextcloud configuration.

Expected behavior

The script should:

  • Use HTTPS and follow redirects.
  • Detect HTTP errors.
  • Validate IPv4 and IPv6 addresses before storing them.
  • Reject HTML documents and other unexpected responses.
  • Log an appropriate warning when IP detection fails.
  • Leave the existing configuration unchanged if validation fails.

Suggested improvement

Use a more robust request, for example:

pub_ipv4="$(curl -4 -fsSL --max-time 10 https://icanhazip.com/ 2>/dev/null)"

The returned value must additionally be validated as a valid IPv4 address before updating trusted_domains.

The same validation should be implemented for IPv6.

Using HTTPS and --fail alone does not guarantee that the response contains a valid IP address.

Recovery

After correcting the underlying DNS filtering issue, public IP detection worked again.

The invalid entry was removed manually, and the script was executed again:

/bin/bash /usr/local/bin/nextcloud-domain.sh

The script then successfully populated trusted_domains[11] with a valid IPv4 address.

The local issue is resolved, but the missing input validation remains.

Impact

Unexpected responses from an external service can introduce invalid values into Nextcloud's trusted domain configuration.

These entries may persist until the script runs successfully again or an administrator removes them manually.

Validating external input before modifying Nextcloud configuration would prevent this problem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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