fix(gateway): restrict /_metrics to loopback callers (#2072)

This commit is contained in:
Hampus
2026-08-29 14:54:56 +02:00
committed by GitHub
parent 79064c3399
commit 38eed7cce6
+30 -8
View File
@@ -7,14 +7,36 @@
-spec init(cowboy_req:req(), term()) -> {ok, cowboy_req:req(), term()}.
init(Req0, State) ->
Body = render_metrics(),
Req = cowboy_req:reply(
200,
#{<<"content-type">> => <<"text/plain; version=0.0.4; charset=utf-8">>},
Body,
Req0
),
{ok, Req, State}.
case is_loopback_request(Req0) of
false ->
Req = cowboy_req:reply(
403,
#{<<"content-type">> => <<"text/plain">>},
<<"FORBIDDEN">>,
Req0
),
{ok, Req, State};
true ->
Body = render_metrics(),
Req = cowboy_req:reply(
200,
#{<<"content-type">> => <<"text/plain; version=0.0.4; charset=utf-8">>},
Body,
Req0
),
{ok, Req, State}
end.
-spec is_loopback_request(cowboy_req:req()) -> boolean().
is_loopback_request(Req) ->
case cowboy_req:peer(Req) of
{{127, 0, 0, 1}, _Port} ->
true;
{{0, 0, 0, 0, 0, 0, 0, 1}, _Port} ->
true;
_ ->
false
end.
-spec render_metrics() -> iolist().
render_metrics() ->