Fix missing command in API key authorization
What changed, and why it matters
This commit fixes a crash in the API key authorization page. When a user submits the form without clicking either the 'Authorize' or 'Cancel' button, the server tries to read a missing command value, which could cause an error. The fix safely handles the missing value by using a question mark before converting it to lowercase. This is a defensive hardening change rather than a clear-cut security vulnerability, but an unhandled exception could potentially disrupt service or produce unexpected behavior.
Treat as a minor reliability/defensive fix. No urgent security response required. Review whether other controller actions similarly assume Command is non-null, and consider adding model-state validation or explicit command requirements to prevent ambiguous form submissions.
Security signals we found
Null dereference in request handling path
Unhandled exception could lead to error disclosure or availability impact
Defensive null-safety hardening in controller action
No authentication/authorization bypass introduced by patch
Evidence from the diff
In UIManageController.APIKeys.cs, the AuthorizeAPIKey action previously called viewModel.Command.ToLowerInvariant() unconditionally. If Command was null (e.g., form submitted without a recognized button/command), this would throw a NullReferenceException. The patch changes it to viewModel.Command?.ToLowerInvariant(), so command becomes null and falls through the switch to the default case. The default case currently returns the same View(viewModel), so behavior is now graceful. The change is minimal (+1/-1) and does not alter authorization logic or permissions.
Changed components
BTCPayServer/Controllers/UIManageController.APIKeys.csAuthorizeAPIKey actionAPI key management UI flowInspect captured patch +1 / −1
### BTCPayServer/Controllers/UIManageController.APIKeys.cs
@@ -215,7 +215,7 @@ public async Task<IActionResult> AuthorizeAPIKey([FromForm] AuthorizeApiKeysView
return View(viewModel);
}
- var command = viewModel.Command.ToLowerInvariant();
+ var command = viewModel.Command?.ToLowerInvariant();
switch (command)
{
case "cancel":Why this scored 49/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.