[PR #6061] [MERGED] [relay] Preserve non-standard port in WS dialer URL prep #24681

Closed
opened 2026-08-05 06:09:00 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6061
Author: @lixmal
Created: 5/4/2026
Status: Merged
Merged: 5/11/2026
Merged by: @lixmal

Base: mainHead: fix/relay-healthcheck-non-standard-port


📝 Commits (4)

  • a409678 Rewrite relay WS dialer URL prep using net/url to preserve non-standard ports
  • abccbde Add IPv6 cases to relay WS prepareURL tests
  • a61a04a Merge branch 'main' into fix/relay-healthcheck-non-standard-port
  • 67dc18e Reject relay address with missing host

📊 Changes

2 files changed (+96 additions, -12 deletions)

View changed files

📝 shared/relay/client/dialer/ws/ws.go (+20 -12)
shared/relay/client/dialer/ws/ws_test.go (+76 -0)

📄 Description

Describe your changes

Rewrite prepareURL in the relay WS dialer to use net/url parsing instead of a strings.Replace based scheme rewrite, and add tests covering non-standard ports and other edge cases.

  • Parse the relay address with url.Parse, switch on the scheme, and set the path explicitly
  • Add table-driven tests for ports, IPs, hostnames starting with rel, and rejected schemes

https://github.com/netbirdio/netbird/issues/6057

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Internal refactor with no user-visible API change.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes

    • Improved WebSocket endpoint handling with stricter scheme validation, more reliable host/port/path construction, and clearer error reporting for invalid or unsupported inputs.
  • Tests

    • Added comprehensive tests for URL conversion and validation, covering hostnames, ports, IPv4/IPv6 formats, and malformed or unsupported URLs.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6061 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 5/4/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix/relay-healthcheck-non-standard-port` --- ### 📝 Commits (4) - [`a409678`](https://github.com/netbirdio/netbird/commit/a409678fe5ccd2265f77de78bb3d357701e298c8) Rewrite relay WS dialer URL prep using net/url to preserve non-standard ports - [`abccbde`](https://github.com/netbirdio/netbird/commit/abccbdee9e965c9525362b5fd2968f0a05fc4ad1) Add IPv6 cases to relay WS prepareURL tests - [`a61a04a`](https://github.com/netbirdio/netbird/commit/a61a04a9f5126b7c9069936a32fb2c9bb87d3add) Merge branch 'main' into fix/relay-healthcheck-non-standard-port - [`67dc18e`](https://github.com/netbirdio/netbird/commit/67dc18e14c5b865abca883c9344a5e27d1740968) Reject relay address with missing host ### 📊 Changes **2 files changed** (+96 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `shared/relay/client/dialer/ws/ws.go` (+20 -12) ➕ `shared/relay/client/dialer/ws/ws_test.go` (+76 -0) </details> ### 📄 Description ## Describe your changes Rewrite `prepareURL` in the relay WS dialer to use `net/url` parsing instead of a `strings.Replace` based scheme rewrite, and add tests covering non-standard ports and other edge cases. - Parse the relay address with `url.Parse`, switch on the scheme, and set the path explicitly - Add table-driven tests for ports, IPs, hostnames starting with `rel`, and rejected schemes ## Issue ticket number and link https://github.com/netbirdio/netbird/issues/6057 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [x] It is a refactor - [x] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Internal refactor with no user-visible API change. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved WebSocket endpoint handling with stricter scheme validation, more reliable host/port/path construction, and clearer error reporting for invalid or unsupported inputs. * **Tests** * Added comprehensive tests for URL conversion and validation, covering hostnames, ports, IPv4/IPv6 formats, and malformed or unsupported URLs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 06:09:00 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#24681