From 57273754b77cfc0f2cea5e8982ad908227d3480c Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Mon, 17 Jun 2024 22:30:14 +0100 Subject: [PATCH] we may as well handle (expires) as well --- lib/pleroma/web/plugs/http_signature_plug.ex | 11 +++++++++++ .../pleroma/web/plugs/http_signature_plug_test.exs | 14 +++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/plugs/http_signature_plug.ex b/lib/pleroma/web/plugs/http_signature_plug.ex index 254b5171a..e3ae99636 100644 --- a/lib/pleroma/web/plugs/http_signature_plug.ex +++ b/lib/pleroma/web/plugs/http_signature_plug.ex @@ -54,6 +54,16 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do end end + def maybe_put_expires_psudoheader(conn) do + case HTTPSignatures.signature_for_conn(conn) do + %{"expires" => expires} -> + put_req_header(conn, "(expires)", expires) + + _ -> + conn + end + end + defp assign_valid_signature_on_route_aliases(conn, []), do: conn defp assign_valid_signature_on_route_aliases(%{assigns: %{valid_signature: true}} = conn, _), @@ -66,6 +76,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do conn |> put_req_header("(request-target)", request_target) |> maybe_put_created_psudoheader() + |> maybe_put_expires_psudoheader() |> case do %{assigns: %{digest: digest}} = conn -> put_req_header(conn, "digest", digest) conn -> conn diff --git a/test/pleroma/web/plugs/http_signature_plug_test.exs b/test/pleroma/web/plugs/http_signature_plug_test.exs index 750ffa323..0a602424d 100644 --- a/test/pleroma/web/plugs/http_signature_plug_test.exs +++ b/test/pleroma/web/plugs/http_signature_plug_test.exs @@ -19,9 +19,10 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do [ signature_for_conn: fn _ -> %{ - "keyId" => "http://mastodon.example.org/users/admin#main-key", - "created" => "1234567890", - } + "keyId" => "http://mastodon.example.org/users/admin#main-key", + "created" => "1234567890", + "expires" => "1234567890" + } end, validate_conn: fn conn -> Map.get(conn.assigns, :valid_signature, true) @@ -151,4 +152,11 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do created_header = List.keyfind(conn.req_headers, "(created)", 0) assert {_, "1234567890"} = created_header end + + test "(expires) psudoheader", _ do + conn = build_conn(:get, "/doesntmattter") + conn = HTTPSignaturePlug.maybe_put_expires_psudoheader(conn) + expires_header = List.keyfind(conn.req_headers, "(expires)", 0) + assert {_, "1234567890"} = expires_header + end end