X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fweb%2Fplugs%2Fhttp_signature_plug.ex;h=c906a4eecaee47ffbc4d4fa38f47afb129ea8cbe;hb=dbe678cb06352df49de4aa36f033b392ce6e6745;hp=036e2a7739e0ca16fb05412d15249fa6594c2ab3;hpb=755f58168bb2b6b979c6f5d36f7eff56d2305911;p=akkoma
diff --git a/lib/pleroma/web/plugs/http_signature_plug.ex b/lib/pleroma/web/plugs/http_signature_plug.ex
index 036e2a773..c906a4eec 100644
--- a/lib/pleroma/web/plugs/http_signature_plug.ex
+++ b/lib/pleroma/web/plugs/http_signature_plug.ex
@@ -1,10 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
import Plug.Conn
import Phoenix.Controller, only: [get_format: 1, text: 2]
+ alias Pleroma.Activity
+ alias Pleroma.Web.Router
require Logger
def init(options) do
@@ -25,21 +27,47 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
end
end
+ def route_aliases(%{path_info: ["objects", id], query_string: query_string}) do
+ ap_id = Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :object, id)
+
+ with %Activity{} = activity <- Activity.get_by_object_ap_id_with_object(ap_id) do
+ ["/notice/#{activity.id}", "/notice/#{activity.id}?#{query_string}"]
+ else
+ _ -> []
+ end
+ end
+
+ def route_aliases(_), do: []
+
+ defp assign_valid_signature_on_route_aliases(conn, []), do: conn
+
+ defp assign_valid_signature_on_route_aliases(%{assigns: %{valid_signature: true}} = conn, _),
+ do: conn
+
+ defp assign_valid_signature_on_route_aliases(conn, [path | rest]) do
+ request_target = String.downcase("#{conn.method}") <> " #{path}"
+
+ conn =
+ conn
+ |> put_req_header("(request-target)", request_target)
+ |> case do
+ %{assigns: %{digest: digest}} = conn -> put_req_header(conn, "digest", digest)
+ conn -> conn
+ end
+
+ conn
+ |> assign(:valid_signature, HTTPSignatures.validate_conn(conn))
+ |> assign_valid_signature_on_route_aliases(rest)
+ end
+
defp maybe_assign_valid_signature(conn) do
if has_signature_header?(conn) do
# set (request-target) header to the appropriate value
# we also replace the digest header with the one we computed
- request_target = String.downcase("#{conn.method}") <> " #{conn.request_path}"
-
- conn =
- conn
- |> put_req_header("(request-target)", request_target)
- |> case do
- %{assigns: %{digest: digest}} = conn -> put_req_header(conn, "digest", digest)
- conn -> conn
- end
+ possible_paths =
+ route_aliases(conn) ++ [conn.request_path, conn.request_path <> "?#{conn.query_string}"]
- assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
+ assign_valid_signature_on_route_aliases(conn, possible_paths)
else
Logger.debug("No signature header!")
conn