Skip to content

Captive portal: fix bracketed IPv6 literal in redirurl regex#9981

Merged
swhite2 merged 1 commit intoopnsense:masterfrom
agoodkind:fix/captiveportal-ipv6-host-regex-redirurl
Mar 17, 2026
Merged

Captive portal: fix bracketed IPv6 literal in redirurl regex#9981
swhite2 merged 1 commit intoopnsense:masterfrom
agoodkind:fix/captiveportal-ipv6-host-regex-redirurl

Conversation

@agoodkind
Copy link
Copy Markdown
Contributor

@agoodkind agoodkind commented Mar 17, 2026

Summary

Follow-up to #9745 (Captive portal: IPv6 support). The host-match regex fix from #9973 was not included when #9745 merged.

When a client reaches the captive portal via a raw IPv6 address, the Host header contains a bracketed literal (e.g. [2606:4700:4700::1111]). The regex ([^:/]+) stops at the first colon, so the redirect URL becomes [2601/ instead of [2606:4700:4700::1111]/.

This PR updates the regex to (\[[^\]]+\]|[^:/]+) so full bracketed IPv6 literals are matched first, with the original pattern still used for IPv4 and hostnames.

Testing

Lab overview

Host Interfaces Role
opnsense-dev WAN: 3d06:bad:b01:200::11/128
LAN: 3d06:bad:b01:210::1/64
Firewall under test. Captive portal enabled.
ubuntu-test-client LAN: 3d06:bad:b01:210::902/64 IPv6-only client behind opnsense-dev.
Case Upstream result This PR
Bracketed IPv6 literal preserved in redirurl Fails. redirurl=[2606/ redirurl=[2606:4700:4700::1111]/

Missed in: 369630d (Captive portal: IPv6 support, #9745)
See also: #9973

The host-match regex ([^:/]+) in the IPv6 lighttpd socket blocks
truncates bracketed IPv6 literals at the first colon, producing a
broken redirurl (e.g. [2601/ instead of [2606:4700:4700::1111]/).

Change the capture group to (\[[^\]]+\]|[^:/]+) so a full bracketed
literal is matched first, falling back to the original pattern for
IPv4 addresses and hostnames.

Missed in: 369630d (Captive portal: IPv6 support, opnsense#9745)
See also: opnsense#9973
@agoodkind agoodkind marked this pull request as ready for review March 17, 2026 02:29
@agoodkind
Copy link
Copy Markdown
Contributor Author

agoodkind commented Mar 17, 2026

I found this was missed in the previous captive portal changes, @AdSchellevis @swhite2 do you mind taking a look?

@swhite2 swhite2 merged commit 2ac18ce into opnsense:master Mar 17, 2026
@swhite2
Copy link
Copy Markdown
Member

swhite2 commented Mar 17, 2026

Merged, thanks :)

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants