[PR #5478] [CLOSED] [management] Validate account ID in URL matches authenticated account #23125

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5478
Author: @John-Dixon-IV
Created: 2/28/2026
Status: Closed

Base: mainHead: fix/accounts-handler-auth-validation


📝 Commits (1)

  • bd8e206 [management] Validate account ID in URL matches authenticated account

📊 Changes

2 files changed (+54 additions, -4 deletions)

View changed files

📝 management/server/http/handlers/accounts/accounts_handler.go (+16 -4)
📝 management/server/http/handlers/accounts/accounts_handler_test.go (+38 -0)

📄 Description

Summary

  • The updateAccount and deleteAccount handlers extracted accountId from the URL parameter without validating it against the authenticated user's account from the auth context. Every other handler in the codebase (users, groups, routes, peers, dns) uses userAuth.AccountId from the auth context — these two were the only ones trusting the URL parameter.
  • Added explicit validation that the URL accountId matches userAuth.AccountId, returning 403 if they differ.
  • The backend ValidateUserPermissions check mitigates single-account exploitation, but handlers should enforce this as defense-in-depth.

Test plan

  • PutAccount with mismatched accountId returns forbidden — URL has different accountId than auth context → 403
  • TestDeleteAccount_CrossAccountForbidden — DELETE with mismatched accountId → 403
  • All 9 existing account handler tests continue to pass

Summary by CodeRabbit

  • Bug Fixes

    • Strengthened account access control to ensure users can only update or delete their own accounts. Attempts to modify accounts belonging to other users now return permission denied responses.
  • Tests

    • Added comprehensive test coverage for cross-account access restriction scenarios during account updates and deletions.

🔄 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/5478 **Author:** [@John-Dixon-IV](https://github.com/John-Dixon-IV) **Created:** 2/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/accounts-handler-auth-validation` --- ### 📝 Commits (1) - [`bd8e206`](https://github.com/netbirdio/netbird/commit/bd8e206ec679e87918cc56912a556723e6c80b87) [management] Validate account ID in URL matches authenticated account ### 📊 Changes **2 files changed** (+54 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `management/server/http/handlers/accounts/accounts_handler.go` (+16 -4) 📝 `management/server/http/handlers/accounts/accounts_handler_test.go` (+38 -0) </details> ### 📄 Description ## Summary - The `updateAccount` and `deleteAccount` handlers extracted `accountId` from the URL parameter without validating it against the authenticated user's account from the auth context. Every other handler in the codebase (users, groups, routes, peers, dns) uses `userAuth.AccountId` from the auth context — these two were the only ones trusting the URL parameter. - Added explicit validation that the URL `accountId` matches `userAuth.AccountId`, returning 403 if they differ. - The backend `ValidateUserPermissions` check mitigates single-account exploitation, but handlers should enforce this as defense-in-depth. ## Test plan - [x] `PutAccount with mismatched accountId returns forbidden` — URL has different accountId than auth context → 403 - [x] `TestDeleteAccount_CrossAccountForbidden` — DELETE with mismatched accountId → 403 - [x] All 9 existing account handler tests continue to pass <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Strengthened account access control to ensure users can only update or delete their own accounts. Attempts to modify accounts belonging to other users now return permission denied responses. * **Tests** * Added comprehensive test coverage for cross-account access restriction scenarios during account updates and deletions. <!-- 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:06:49 -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#23125