Skip to content

Commit

Permalink
fix: Return 404 when parsing nonexistent vhost
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisSotoLopez committed Apr 2, 2024
1 parent dd5686a commit cf497a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% TODO sort all this out; maybe there's scope for rabbit_mgmt_request?

-export([is_authorized/2, is_authorized_admin/2, is_authorized_admin/4,
is_authorized_admin/3, vhost/1, vhost_from_headers/1]).
is_authorized_admin/3, vhost/1, vhost_or_not_found/2, vhost_from_headers/1]).
-export([is_authorized_vhost/2, is_authorized_user/3,
is_authorized_user/4, is_authorized_user/5,
is_authorized_monitor/2, is_authorized_policies/2,
Expand Down Expand Up @@ -210,6 +210,12 @@ vhost_from_headers(ReqData) ->
vhost(ReqData) ->
rabbit_web_dispatch_access_control:vhost(ReqData).

vhost_or_not_found(ReqData, Context) ->
case rabbit_web_dispatch_access_control:vhost(ReqData) of
not_found -> not_found(<<"virtual host not found">>, ReqData, Context);
VHost -> VHost
end.

user(ReqData) ->
case id(user, ReqData) of
none -> not_found;
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_get.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ accept_content(ReqData, Context) ->
rabbit_mgmt_util:post_respond(do_it(ReqData, Context)).

do_it(ReqData0, Context) ->
VHost = rabbit_mgmt_util:vhost(ReqData0),
VHost = rabbit_mgmt_util:vhost_or_not_found(ReqData0, Context),
Q = rabbit_mgmt_util:id(queue, ReqData0),
rabbit_mgmt_util:with_decode(
[ackmode, count, encoding], ReqData0, Context,
Expand Down

0 comments on commit cf497a9

Please sign in to comment.