From 958227d5563d76f4f983b7cabb6948897d93bd4b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 15 Mar 2019 01:36:29 +0300 Subject: [PATCH] MediaProxy: parse filename from content-disposition for non-whitelisted types --- lib/pleroma/reverse_proxy.ex | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index 6298b92f4..39ede8619 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -311,7 +311,25 @@ defp build_resp_content_disposition_header(headers, opts) do end if attachment? do - disposition = "attachment; filename=" <> Keyword.get(opts, :attachment_name, "attachment") + name = + try do + {{"content-disposition", content_disposition_string}, _} = + List.keytake(headers, "content-disposition", 0) + + [name] = + Regex.run( + ~r/filename=\"(.*)\"/u, + content_disposition_string || "", + capture: :all_but_first + ) + + name + rescue + MatchError -> Keyword.get(opts, :attachment_name, "attachment") + end + + disposition = "attachment; filename=" <> name + List.keystore(headers, "content-disposition", 0, {"content-disposition", disposition}) else headers