Skip to content

Add internal authorization check to system commands#463

Merged
Volte6 merged 2 commits intoGoMudEngine:masterfrom
sarahmaeve:upstream-fix/system-command-auth
Apr 6, 2026
Merged

Add internal authorization check to system commands#463
Volte6 merged 2 commits intoGoMudEngine:masterfrom
sarahmaeve:upstream-fix/system-command-auth

Conversation

@sarahmaeve
Copy link
Copy Markdown
Contributor

Summary

Adds defense-in-depth authorization check inside trySystemCommand for /shutdown and /reload. Previously authorization was only enforced at handler registration time in main.go — if registration was ever bypassed, any connection could trigger server shutdown or data reload.

Changes

  • systemcommands.go: After command lookup, verifies user has admin role via users.GetByConnectionId. Non-admin or unknown connections are rejected with a warning log. /quit remains available to all users.
  • Adds test helpers in users package for cross-package test setup.

Tests

8 test cases covering: shutdown/reload rejected for non-admin user, rejected for unknown connection, accepted for admin, unknown command and non-slash prefix handled correctly.

trySystemCommand() now verifies the user has admin role before
executing /shutdown or /reload. Previously authorization was only
enforced at handler registration time in main.go, with no check
inside the command handler itself.

/quit remains available to all users.

Adds 8 test cases covering admin/non-admin/unknown connection
scenarios. Adds SetTestConnection helper for cross-package tests.

Fixes #4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sarahmaeve sarahmaeve requested a review from Volte6 as a code owner April 5, 2026 03:40
@Volte6 Volte6 merged commit e014dc6 into GoMudEngine:master Apr 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants