[PR #5608] fix(ui): open browser in user context on macOS/Linux when daemon runs as root #23422

Open
opened 2026-08-05 06:07:12 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/5608

State: closed
Merged: No


Describe your changes

When the NetBird daemon runs as root and triggers re-authentication after peer login expiry, the bare open/xdg-open command launches the browser in the root process context, ignoring the logged-in user's default browser preference. On macOS this consistently opens Safari in the background even when the user has Chrome/Firefox set as their default browser, causing the session expired re-auth flow to go unnoticed.

Fix by detecting when running as root (os.Getuid() == 0) and invoking open/xdg-open as the current logged-in user via sudo -u, ensuring macOS/Linux resolves the correct default browser in the user's session context. Falls back to bare open/xdg-open if user.Current() fails or if not running as root.

The existing open-golang dependency was considered but has the same root cause on darwin — it calls open directly without user context.

Tested on macOS (Intel + ARM64) by invalidating a peer session and confirming Chrome opens instead of Safari.

Related: #4471
Related: #2109

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

  • Documentation is not needed for this change — internal bug fix for browser launch behavior.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed URL-opening when the app runs with elevated privileges on macOS and Linux/FreeBSD so links open in the desktop user's browser instead of failing or opening as root.
  • Behavior

    • Respects user-configured browser (BROWSER env) and falls back to the platform default, preserving normal behavior when not running as root.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5608 **State:** closed **Merged:** No --- ## Describe your changes When the NetBird daemon runs as root and triggers re-authentication after peer login expiry, the bare `open`/`xdg-open` command launches the browser in the root process context, ignoring the logged-in user's default browser preference. On macOS this consistently opens Safari in the background even when the user has Chrome/Firefox set as their default browser, causing the session expired re-auth flow to go unnoticed. Fix by detecting when running as root (`os.Getuid() == 0`) and invoking `open`/`xdg-open` as the current logged-in user via `sudo -u`, ensuring macOS/Linux resolves the correct default browser in the user's session context. Falls back to bare `open`/`xdg-open` if `user.Current()` fails or if not running as root. The existing `open-golang` dependency was considered but has the same root cause on darwin — it calls `open` directly without user context. Tested on macOS (Intel + ARM64) by invalidating a peer session and confirming Chrome opens instead of Safari. ## Issue ticket number and link Related: #4471 Related: #2109 ## Stack <!-- branch-stack --> ### Checklist - [x] 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](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation - [x] Documentation is **not needed** for this change — internal bug fix for browser launch behavior. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed URL-opening when the app runs with elevated privileges on macOS and Linux/FreeBSD so links open in the desktop user's browser instead of failing or opening as root. * **Behavior** * Respects user-configured browser (BROWSER env) and falls back to the platform default, preserving normal behavior when not running as root. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 06:07:12 -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#23422