Skip to content

Fixes #193: use strict IPv4 regex in nginx resolver to prevent crash#194

Open
d4c00 wants to merge 1 commit intolinuxserver:3.23from
d4c00:patch-1
Open

Fixes #193: use strict IPv4 regex in nginx resolver to prevent crash#194
d4c00 wants to merge 1 commit intolinuxserver:3.23from
d4c00:patch-1

Conversation

@d4c00
Copy link

@d4c00 d4c00 commented Feb 15, 2026

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

Fixes #193. This PR addresses a critical Nginx startup failure in the /etc/s6-overlay/s6-rc.d/init-nginx/run script.

The previous logic used awk -F ':' '{print NF-1}' to filter IPv6 addresses from /etc/resolv.conf. However, this method fails to account for compressed IPv6 addresses (e.g., fd00::1), which only contain two colons and thus bypass the filter. This results in an unformatted IPv6 address being written to /config/nginx/resolver.conf without brackets [], causing the Nginx error: [emerg] invalid port in resolver "fd00::1".

The fix implements a declarative regex to strictly validate IPv4 addresses, ensuring only valid IPv4 entries are passed to the resolver configuration.

Benefits of this PR and context:

In dual-stack environments (common in RHEL/Podman setups), both IPv4 and IPv6 nameservers are automatically passed into the container's /etc/resolv.conf.

This PR prevents the container from entering a crash loop by ensuring that compressed IPv6 addresses are correctly ignored rather than being misinterpreted as IPv4. By switching to a declarative regex validation ^[0-9]{1,3}(\.[0-9]{1,3}){3}$, we eliminate the edge cases inherent in the previous colon-counting approach, providing a more robust and predictable initialization process.

How Has This Been Tested?

  • Environment: RHEL 10.1 with dual-stack networking and Podman.

  • Test Case: Added nameserver 10.0.0.1 and fd00::1 to the host's /etc/resolv.conf.

# librespeed.container
[Container]
ContainerName=librespeed
Environment=PUID=3013 PGID=3013
DNS=10.0.0.1
Image=lscr.io/linuxserver/librespeed:latest
PublishPort=3013:80

[Service]
Restart=always

Source / References:

    ### Problem
    The current logic filters IPv6 addresses by counting colons (NF-1 <= 2). However, compressed IPv6 addresses like `fd00::1` contain only two colons, causing them to be incorrectly identified as IPv4. This leads to an invalid `resolver.conf` and Nginx fails to start with:
    `[emerg] invalid port in resolver "fd00::1"`

    Solution

    Replaced the unreliable colon-counting logic with a strict IPv4 regex: ^[0-9]{1,3}(\.[0-9]{1,3}){3}$. This ensures only valid IPv4 addresses are added, maintaining the script's intent to "ignore ipv6 addresses" without crashing Nginx.

    Impact

    Fixes container startup failure on hosts with IPv6 ULA or compressed addresses in /etc/resolv.conf.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this pull request! Be sure to follow the pull request template!

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/baseimage-nginx/3.23-1.28.2-r0_8.4.17-r0-pkg-8a39f2e1-dev-605fe2118d9e2cc4aae281701497af613694349b-pr-194/index.html
https://ci-tests.linuxserver.io/lspipepr/baseimage-nginx/3.23-1.28.2-r0_8.4.17-r0-pkg-8a39f2e1-dev-605fe2118d9e2cc4aae281701497af613694349b-pr-194/shellcheck-result.xml

Tag Passed
amd64-3.23-1.28.2-r0_8.4.17-r0-pkg-8a39f2e1-dev-605fe2118d9e2cc4aae281701497af613694349b-pr-194
arm64v8-3.23-1.28.2-r0_8.4.17-r0-pkg-8a39f2e1-dev-605fe2118d9e2cc4aae281701497af613694349b-pr-194

@d4c00 d4c00 changed the title fix: use strict IPv4 regex in nginx resolver to prevent crash Fixes #193: use strict IPv4 regex in nginx resolver to prevent crash Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] <Flawed IPv6 filtering logic in init-nginx allows compressed IPv6 addresses to crash Nginx>

2 participants