Harden webhook API input
This commit is contained in:
parent
27090ad7e6
commit
ab634a4aa3
3 changed files with 64 additions and 8 deletions
|
|
@ -40,14 +40,14 @@ defmodule Pleroma.Web.AdminAPI.WebhookController do
|
|||
end
|
||||
|
||||
def create(%{body_params: params} = conn, _) do
|
||||
with {:ok, webhook} <- Webhook.create(params) do
|
||||
with {:ok, webhook} <- Webhook.create(webhook_params(params)) do
|
||||
render(conn, "show.json", webhook: webhook)
|
||||
end
|
||||
end
|
||||
|
||||
def update(%{body_params: params} = conn, %{id: id}) do
|
||||
with %Webhook{internal: false} = webhook <- Webhook.get(id),
|
||||
{:ok, webhook} <- Webhook.update(webhook, params) do
|
||||
{:ok, webhook} <- Webhook.update(webhook, webhook_params(params)) do
|
||||
render(conn, "show.json", webhook: webhook)
|
||||
else
|
||||
%Webhook{internal: true} -> {:error, :forbidden}
|
||||
|
|
@ -94,4 +94,8 @@ defmodule Pleroma.Web.AdminAPI.WebhookController do
|
|||
nil -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
defp webhook_params(params) do
|
||||
Map.drop(params, [:internal, "internal"])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue