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

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

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

State: closed
Merged: No


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.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5478 **State:** closed **Merged:** No --- ## 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 -->
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#23129